mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 12:15:11 +00:00
Added drowning types:
In Air, In Water, or Never to CNPCs.
This commit is contained in:
1 parent
44225194ac
commit
55b21de050
9 files changed
+102
-44
No files matched your search
@@ -8,9 +8,6 @@ import noppes.npcs.constants.EnumPotionType;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class DataStats {
|
||||
|
||||
private float attackStrength = 5;
|
||||
@@ -33,7 +30,7 @@ public class DataStats {
|
||||
|
||||
public boolean immuneToFire = false;
|
||||
public boolean potionImmune = false;
|
||||
public boolean canDrown = true;
|
||||
public int drowningType = 1; //0 - Never, 1 - Water, 2 - Air
|
||||
public boolean burnInSun = false;
|
||||
public boolean noFallDamage = false;
|
||||
public float healthRegen = 1;
|
||||
@@ -108,7 +105,7 @@ public class DataStats {
|
||||
|
||||
compound.setBoolean("ImmuneToFire", immuneToFire);
|
||||
compound.setBoolean("PotionImmune", potionImmune);
|
||||
compound.setBoolean("CanDrown", canDrown);
|
||||
compound.setInteger("DrowningType", drowningType);
|
||||
compound.setBoolean("BurnInSun", burnInSun);
|
||||
compound.setBoolean("NoFallDamage", noFallDamage);
|
||||
compound.setBoolean("AttackInvisible", attackInvisible);
|
||||
@@ -118,8 +115,7 @@ public class DataStats {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readToNBT(NBTTagCompound compound)
|
||||
{
|
||||
public void readToNBT(NBTTagCompound compound) {
|
||||
resistances.readToNBT(compound.getCompoundTag("Resistances"));
|
||||
setMaxHealth(compound.getDouble("MaxHealth"));
|
||||
hideKilledBody = compound.getBoolean("HideBodyWhenKilled");
|
||||
@@ -129,7 +125,7 @@ public class DataStats {
|
||||
creatureType = EnumCreatureAttribute.values()[compound.getInteger("CreatureType") % EnumPotionType.values().length];
|
||||
healthRegen = compound.getFloat("HealthRegen");
|
||||
combatRegen = compound.getFloat("CombatRegen");
|
||||
|
||||
|
||||
setAttackStrength(compound.getFloat("AttackStrenght"));
|
||||
attackSpeed = compound.getInteger("AttackSpeed");
|
||||
attackRange = compound.getInteger("AttackRange");
|
||||
@@ -137,15 +133,15 @@ public class DataStats {
|
||||
potionType = EnumPotionType.values()[compound.getInteger("PotionEffect") % EnumPotionType.values().length];
|
||||
potionDuration = compound.getInteger("PotionDuration");
|
||||
potionAmp = compound.getInteger("PotionAmp");
|
||||
|
||||
|
||||
rangedRange = compound.getInteger("MaxFiringRange");
|
||||
fireRate = compound.getInteger("FireRate");
|
||||
minDelay = ValueUtil.CorrectInt(compound.getInteger("minDelay"), 1, 9999);
|
||||
maxDelay = ValueUtil.CorrectInt(compound.getInteger("maxDelay"), 1, 9999);
|
||||
burstCount = compound.getInteger("BurstCount");
|
||||
shotCount = ValueUtil.CorrectInt(compound.getInteger("ShotCount"), 1, 10);
|
||||
accuracy = compound.getInteger("Accuracy");
|
||||
|
||||
accuracy = compound.getInteger("Accuracy");
|
||||
|
||||
pDamage = compound.getFloat("pDamage");
|
||||
pImpact = compound.getInteger("pImpact");
|
||||
pSize = compound.getInteger("pSize");
|
||||
@@ -166,9 +162,15 @@ public class DataStats {
|
||||
aimWhileShooting = compound.getBoolean("AimWhileShooting");
|
||||
projectilesKeepTerrain = compound.getBoolean("ProjectilesKeepTerrain");
|
||||
|
||||
immuneToFire = compound.getBoolean("ImmuneToFire");
|
||||
potionImmune = compound.getBoolean("PotionImmune");
|
||||
canDrown = compound.getBoolean("CanDrown");
|
||||
immuneToFire = compound.getBoolean("ImmuneToFire");
|
||||
potionImmune = compound.getBoolean("PotionImmune");
|
||||
//canDrown = compound.getBoolean("CanDrown");
|
||||
if (!compound.hasKey("DrowningType") && compound.hasKey("CanDrown")) {
|
||||
drowningType = compound.getBoolean("CanDrown") ? 1 : 0;
|
||||
} else {
|
||||
drowningType = compound.getInteger("DrowningType");
|
||||
}
|
||||
|
||||
burnInSun = compound.getBoolean("BurnInSun");
|
||||
noFallDamage = compound.getBoolean("NoFallDamage");
|
||||
attackInvisible = compound.getBoolean("AttackInvisible");
|
||||
|
||||
@@ -12,10 +12,7 @@ import com.google.common.collect.Sets;
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.MathHelper;
|
||||
@@ -68,17 +65,15 @@ public class NPCSpawning {
|
||||
|
||||
ChunkPosition chunkposition = getChunk(world, chunkcoordintpair1.chunkXPos, chunkcoordintpair1.chunkZPos);
|
||||
int j1 = chunkposition.chunkPosX;
|
||||
int k1 = chunkposition.chunkPosY;
|
||||
int y = chunkposition.chunkPosY;
|
||||
int l1 = chunkposition.chunkPosZ;
|
||||
|
||||
for(int i = 0; i < 3; i++){
|
||||
int x = j1;
|
||||
int y = k1;
|
||||
int z = l1;
|
||||
byte b1 = 6;
|
||||
|
||||
x += world.rand.nextInt(b1) - world.rand.nextInt(b1);
|
||||
y += world.rand.nextInt(1) - world.rand.nextInt(1);
|
||||
z += world.rand.nextInt(b1) - world.rand.nextInt(b1);
|
||||
|
||||
|
||||
@@ -177,7 +172,7 @@ public class NPCSpawning {
|
||||
}
|
||||
|
||||
Result canSpawn = ForgeEventFactory.canEntitySpawn(entityliving, world, x + 0.5f, y, z + 0.5f);
|
||||
if (canSpawn == Result.DENY || (canSpawn == Result.DEFAULT && !entityliving.getCanSpawnHere()))
|
||||
if (canSpawn == Result.DENY || (canSpawn == Result.DEFAULT && !canEntitySpawn(data,entityliving)))
|
||||
return false;
|
||||
|
||||
if (!EventHooks.onCNPCNaturalSpawn(data, new BlockPos(x,y,z), NPCSpawning.animalSpawn, NPCSpawning.monsterSpawn, NPCSpawning.liquidSpawn, NPCSpawning.airSpawn)) {
|
||||
@@ -188,6 +183,14 @@ public class NPCSpawning {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canEntitySpawn(SpawnData data, EntityLiving entityLiving) {
|
||||
if (!data.liquidSpawning) {
|
||||
return entityLiving.getCanSpawnHere();
|
||||
} else {
|
||||
return entityLiving.worldObj.checkNoEntityCollision(entityLiving.boundingBox) && entityLiving.worldObj.getCollidingBoundingBoxes(entityLiving, entityLiving.boundingBox).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canCreatureTypeSpawnAtLocation(SpawnData data, World world, int x, int y, int z){
|
||||
Block block = world.getBlock(x, y - 1, z);
|
||||
@@ -198,7 +201,7 @@ public class NPCSpawning {
|
||||
|
||||
boolean animalSpawn = data.animalSpawning && hasSolidSurface && spawnBlockCreature && !world.getBlock(x, y, z).isNormalCube() && !world.getBlock(x, y, z).getMaterial().isLiquid() && !world.getBlock(x, y + 1, z).isNormalCube();
|
||||
boolean monsterSpawn = data.monsterSpawning && hasSolidSurface && spawnBlockMonster && !world.getBlock(x, y, z).isNormalCube() && !world.getBlock(x, y, z).getMaterial().isLiquid() && !world.getBlock(x, y + 1, z).isNormalCube();
|
||||
boolean liquidSpawn = data.liquidSpawning && world.getBlock(x, y, z).getMaterial().isLiquid() && world.getBlock(x, y - 1, z).getMaterial().isLiquid() && !world.getBlock(x, y + 1, z).isNormalCube();
|
||||
boolean liquidSpawn = data.liquidSpawning && world.getBlock(x, y - 1, z).getMaterial().isLiquid() && world.getBlock(x, y, z).getMaterial().isLiquid();
|
||||
boolean caveSpawn = data.airSpawning && world.getBlock(x, y - 1, z) == Blocks.air && world.getBlock(x, y, z) == Blocks.air && world.getBlock(x, y + 1, z) == Blocks.air;
|
||||
|
||||
NPCSpawning.animalSpawn = animalSpawn;
|
||||
|
||||
@@ -61,11 +61,11 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener,
|
||||
|
||||
addButton(new GuiNpcButton(4,guiLeft + 82, y+=34, 56, 20, new String[]{"gui.no","gui.yes"} ,npc.isImmuneToFire()? 1:0));
|
||||
addLabel(new GuiNpcLabel(10,"stats.fireimmune", guiLeft + 5, y + 5));
|
||||
addButton(new GuiNpcButton(5,guiLeft + 217, y, 56, 20, new String[]{"gui.no","gui.yes"} ,stats.canDrown? 1:0));
|
||||
addButton(new GuiNpcButton(5,guiLeft + 217, y, 56, 20, new String[]{"stats.never","stats.inWater","stats.inAir"} , stats.drowningType));
|
||||
addLabel(new GuiNpcLabel(11,"stats.candrown", guiLeft + 140, y + 5));
|
||||
addTextField(new GuiNpcTextField(14, this, guiLeft + 355, y, 56, 20, String.format("%.0f", stats.healthRegen) + "").setFloatsOnly());
|
||||
addLabel(new GuiNpcLabel(14,"stats.regenhealth", guiLeft + 275, y + 5));
|
||||
|
||||
|
||||
addTextField(new GuiNpcTextField(16, this, guiLeft + 355, y+=22, 56, 20, String.format("%.0f", stats.combatRegen) + "").setFloatsOnly());
|
||||
addLabel(new GuiNpcLabel(16,"stats.combatregen", guiLeft + 275, y + 5));
|
||||
addButton(new GuiNpcButton(6,guiLeft + 82, y, 56, 20, new String[]{"gui.no","gui.yes"} ,stats.burnInSun? 1:0));
|
||||
@@ -77,8 +77,8 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener,
|
||||
addLabel(new GuiNpcLabel(17,"stats.potionImmune", guiLeft + 5, y + 5));
|
||||
addButton(new GuiNpcButtonYesNo(18, guiLeft + 217, y, 56, 20, stats.attackInvisible));
|
||||
addLabel(new GuiNpcLabel(18,"stats.attackInvisible", guiLeft + 140, y + 5));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield){
|
||||
if(textfield.id == 0){
|
||||
@@ -95,7 +95,7 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener,
|
||||
stats.combatRegen = (float)(Math.floor(Float.parseFloat(textfield.getText())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton){
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
@@ -112,7 +112,7 @@ public class GuiNpcStats extends GuiNPCInterface2 implements ITextfieldListener,
|
||||
npc.setImmuneToFire(button.getValue() == 1);
|
||||
}
|
||||
else if(button.id == 5){
|
||||
stats.canDrown = button.getValue() == 1;
|
||||
npc.stats.drowningType = button.getValue();
|
||||
}
|
||||
else if(button.id == 6){
|
||||
stats.burnInSun = button.getValue() == 1;
|
||||
|
||||
@@ -204,6 +204,28 @@ public class ServerCloneController implements ICloneHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity[] getTab(int tab, IWorld world) {
|
||||
File dir = new File(getDir(), tab + "");
|
||||
if (!dir.exists() || !dir.isDirectory() || dir.listFiles() == null) {
|
||||
return new IEntity[]{};
|
||||
}
|
||||
|
||||
ArrayList<IEntity> arrayList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.getName().endsWith(".json")) {
|
||||
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||
Instance.cleanTags(compound);
|
||||
Entity entity = EntityList.createEntityFromNBT(compound, world.getMCWorld());
|
||||
arrayList.add(entity == null ? null : NpcAPI.Instance().getIEntity(entity));
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
return arrayList.toArray(new IEntity[]{});
|
||||
}
|
||||
|
||||
public IEntity get(int tab, String name, IWorld world) {
|
||||
NBTTagCompound compound = this.getCloneData((ICommandSender)null, name, tab);
|
||||
if (compound == null) {
|
||||
|
||||
@@ -62,7 +62,6 @@ import noppes.npcs.constants.EnumPacketClient;
|
||||
import noppes.npcs.constants.EnumPotionType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.constants.EnumStandingType;
|
||||
import noppes.npcs.controllers.GlobalDataController;
|
||||
import noppes.npcs.controllers.data.*;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.LinkedNpcController;
|
||||
@@ -416,12 +415,19 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
protected void updateAITasks()
|
||||
{
|
||||
this.getNavigator().onUpdateNavigation();
|
||||
this.getMoveHelper().onUpdateMoveHelper();
|
||||
if (this.worldObj.isAnyLiquid(this.boundingBox) || this.stats.drowningType != 2) {
|
||||
this.getNavigator().onUpdateNavigation();
|
||||
this.getMoveHelper().onUpdateMoveHelper();
|
||||
try {
|
||||
super.updateAITasks();
|
||||
} catch (ConcurrentModificationException ignored){}
|
||||
} else {
|
||||
this.setAir(this.decreaseAirSupply(this.getAir()));
|
||||
|
||||
try {
|
||||
super.updateAITasks();
|
||||
} catch (ConcurrentModificationException ignored){
|
||||
if (this.getAir() <= -20) {
|
||||
this.setAir(0);
|
||||
this.attackEntityFrom(DamageSource.drown, 2.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,10 +816,17 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAir(int air) {
|
||||
if (this.worldObj.isAnyLiquid(this.boundingBox) || air < this.getAir() || this.stats.drowningType != 2) {
|
||||
super.setAir(air);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int decreaseAirSupply(int par1)
|
||||
{
|
||||
if (!this.stats.canDrown)
|
||||
if (this.stats.drowningType == 0)
|
||||
return par1;
|
||||
return super.decreaseAirSupply(par1);
|
||||
}
|
||||
|
||||
@@ -1038,10 +1038,19 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
}
|
||||
|
||||
public boolean getCanDrown() {
|
||||
return npc.stats.canDrown;
|
||||
return npc.stats.drowningType > 0;
|
||||
}
|
||||
public void setCanDrown(boolean d) {
|
||||
npc.stats.canDrown = d;
|
||||
npc.stats.drowningType = d ? 1 : 0;
|
||||
}
|
||||
|
||||
public void setDrowningType(int type) {
|
||||
if (type < 0)
|
||||
type = 0;
|
||||
if (type > 2)
|
||||
type = 2;
|
||||
|
||||
npc.stats.drowningType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -359,7 +359,11 @@ public interface ICustomNpc<T extends EntityCreature> extends IEntityLiving<T> {
|
||||
|
||||
boolean getCanDrown();
|
||||
|
||||
void setCanDrown(boolean b);
|
||||
/**
|
||||
*
|
||||
* @param type 0 - Never drowns, 1 - Drowns in water, 2 - Drowns in air (without water)
|
||||
*/
|
||||
void setDrowningType(int type);
|
||||
|
||||
/**
|
||||
* @param type The AnimationType
|
||||
|
||||
@@ -9,11 +9,13 @@ import noppes.npcs.scripted.interfaces.IWorld;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
|
||||
public interface ICloneHandler {
|
||||
IEntity spawn(double var1, double var3, double var5, int var7, String var8, IWorld var9);
|
||||
IEntity spawn(double x, double y, double z, int tab, String name, IWorld world);
|
||||
|
||||
IEntity get(int var1, String var2, IWorld var3);
|
||||
IEntity[] getTab(int tab, IWorld world);
|
||||
|
||||
void set(int var1, String var2, IEntity var3);
|
||||
IEntity get(int tab, String name, IWorld world);
|
||||
|
||||
void remove(int var1, String var2);
|
||||
void set(int tab, String name, IEntity entity);
|
||||
|
||||
void remove(int tab, String name);
|
||||
}
|
||||
Reference in new issue
Block a user