Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 :( ).

  • 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);

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.