Posted January 8, 20169 yr hello guys, i have been trying this for couple of hours and i am really stuck. I tried to find some examples from the internet that would be helpfull but nothing helped. So i have my "customEntity" which extends simply EntityZombie . public class EntityTest extends EntityZombie { private double maxHealth = 100.0D; public EntityTest(World par1World) { super(par1World); ((PathNavigateGround)this.getNavigator()).func_179688_b(true); this.tasks.addTask(0, new EntityAISwimming(this)); } @Override protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.maxHealth); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D); } } this should be really easy and there is nothing i can screw but propably i did.. When i spawn this entity by using my own command which is like: EntityTest entit = new EntityTest(world); entit.setPosition(player.posX+1, player.posY, player.posZ+1); world.spawnEntityInWorld(entit); player.addChatComponentMessage(new ChatComponentText("SUMMON!")); Entity is spawned but it instantly die. But when i change this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(this.maxHealth); to this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10.0D); it works perfectly.. So i am asking where is the problem and why is this happening and sorry for my English (not everyone is borned at the right place ).
January 8, 20169 yr Author and what if i want to dynamically set the health? i can not simply use a variable with a type double like i did? what is the difference between test(10.0D) and private double doub = 10.0D; test(doub);
January 9, 20169 yr applyEntityAttributes() is called by super-constructor of this entity (in EntityLivingBase i think) at which time any global member of your object variable is not yet set (which happens after call to super(); ). Therefore at the time of calling applyEntityAttributes() your global this.maxHealth is 0.0D. Proper way to go about this is declare static baseMaxHealth for all entities or put value direclty in method (like test(10.0D); ). 1.7.10 is no longer supported by forge, you are on your own.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.