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

I created this entity warrior that follows you and attacks whatever you attack. The only problem is when he attacks he goes super sonic, and runs circles around the target hes attacking. The code for the class is here. How do i fix this?

 

 

public class IamAWarrior extends EntityTameable{

 

 

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

 

 

 

public IamAWarrior(World par1World)

{

super(par1World);

this.setSize(0.6F, 0.8F);

        this.getNavigator().setAvoidsWater(true);

        this.tasks.addTask(1, new EntityAISwimming(this));

        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 4.0D, true));

        this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F));

        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));

        this.tasks.addTask(9, new EntityAILookIdle(this));

        this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));

        this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));

        this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));

        this.setTamed(true);

     

}

 

protected void applyEntityAttributes(){

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23D);

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);

//this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);

}

 

@Override

protected boolean isAIEnabled()

{

return true;

 

}

@Override

protected boolean canDespawn()

{

return false;

}

 

@Override

public boolean attackEntityAsMob(Entity p_70652_1_)

  {

        int i = 10;

        return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i);

  }

 

 

@Override

    public void writeEntityToNBT(NBTTagCompound cmp)

    {

        super.writeEntityToNBT(cmp);

        cmp.setString("Owners Name", player.getUniqueID().toString());

       

    }

 

    @Override

    public void readEntityFromNBT(NBTTagCompound cmp)

    {

        super.readEntityFromNBT(cmp);

        this.func_152115_b(cmp.getString("Owners Name"));

       

    }

 

    @Override

public EntityAgeable createChild(EntityAgeable entityageable)

{

return null;

 

}

 

 

}

 

 

The second parameter in EntityAIAttackOnCollide is the speed at which your entity will move towards the target. Most of the time, it should be the same as or just slightly more than your entity's movement speed, yet you set it to 4.0D, which is roughly 4 blocks per tick.

 

Take it down a notch ;)

OHH lol ok thanks for the quick reply. One more thing how do i make him hold a iron sword?

There's a whole topic about it that may help, but basically:

 

1. Set your entity's held item to what you want (use addRandomArmor or whatever else you need upon spawning)

 

2. To make your life easy, extend both RenderBiped and ModelBiped where appropriate

 

3. Make sure whatever attack AI you are using calls #swingItem when attacking - EntityAIAttackOnCollide does this.

 

4. Make sure you call updateArmSwingProgress() from your entity's onLivingUpdate method, otherwise the swing animation won't work despite your entity holding the sword

  • Author

Alright thanks ill take a look, last thing xD. The entity doesnt seem to remember that i am the owner when i log out completely and come back, how do i fix this?

Alright thanks ill take a look, last thing xD. The entity doesnt seem to remember that i am the owner when i log out completely and come back, how do i fix this?

Are you logging in with the same name each time? The default development environment settings log you in with a new user name each time - you need to set it in the run-time configuration: --username Me. You can even add your password (if the username is your real one) to log in using your actual account, if you want.

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.