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,

I've been on a steep learning curve in creating my own mod which includes custom entities.  I've been searching and trying different ways to equip them with armour, weapons and/or tools, but so far, nothing I've tried has worked.  I've also been hesitant to ask for help, because I've seen so many replies of, 'You need to learn java'.  I've bought and read three books on java, have watched numerous tutorials (which is why my mod is mostly working), but I've found there is very little documentation or tutorials to learn how to do different things that I want to do.  I'm using Eclipse to build my mod for 1.12.2.

 

Here's a custom entity class that works, but that I can't equip.  Can anyone tell me how to do it?  I want this entity to look like a player, wander around the structure he'll be found in and have some equipment on.  I'm going to paste my mess of an entity class directly on here:

 

public class Stish extends EntityAgeable

{

 

private Object canPickUpLoot;

private boolean canEquipItem;

private EntityAIBase aiAttackOnCollide;

private Object inventory;

 

public Stish(World worldIn)

{

super(worldIn);

this.setSize(width, height);

}

 

private NonNullList<ItemStack> list = NonNullList.withSize(2, ItemStack.EMPTY);

private Object difficultyManager;

 

@Override

protected void initEntityAI()

{

this.tasks.addTask(2, new EntityAIWander(this, 1.25D, 5));

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

this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 1.0F));

this.tasks.addTask(1, new EntityAILeapAtTarget(this, 0.6F));

this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.75D, true));

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

this.canEquipItem = true;

this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false, new Class[0]));

 

//I don't want him to be hostile to players

//this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));

 

}

 

 

@Override

protected void applyEntityAttributes()

{

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0D);

this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2001D);

this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(6.0D);

 

}

 

/**

@Override

@Nullable

public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {

 

livingdata = super.onInitialSpawn(difficulty, livingdata);

 

this.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.STONE_PICKAXE));

return livingdata;

 

 

}

*/

 

    @Override

    public ItemStack getHeldItemMainhand() {

    return getHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.STONE_PICKAXE));

    }

 

 

 

 

 

 

private ItemStack getHeldItem(EnumHand mainHand, ItemStack itemStack) {

// TODO Auto-generated method stub

return null;

}

 

 

protected ResourceLocation getLootTable()

    {

    return LootTableList.ENTITIES_VILLAGER;

    }

 

 

public boolean isSpectator() {

// TODO Auto-generated method stub

return false;

}

 

 

public boolean isCreative() {

// TODO Auto-generated method stub

return false;

}

 

 

@Override

public EntityAgeable createChild(EntityAgeable ageable) {

// TODO Auto-generated method stub

return null;

}

 

 

    

 

}

  • Author

Thanks for your reply.  You're absolutely right, I don't really understand how to equip the entity, and haven't found any guidance on it.  The bits of code are from what others have shared in their mods.  I've re-activated the onInitialSpawn code and removed the other bit above but it's still not working.  I'm extending EntityAgeable, and when I tried to extend EntityLiving it seems to be very limited (as TurtyWurty discusses briefly in his entity tutorial (https://www.youtube.com/watch?v=N4uTqY_FU_8).  Am I extending the right base class for the IEntityLivingData bit to work?  Thanks again.

 

Edited by darkgreenminer

  • Author

IEntityLivingData was part of the onInitialSpawn code that I copied to try.  Here's the code now:

 

public class Stish extends EntityLiving

{

 

private Object canPickUpLoot;

private boolean canEquipItem;

private EntityAIBase aiAttackOnCollide;

private Object inventory;

 

public Stish(World worldIn)

{

super(worldIn);

this.setSize(width, height);

}

 

private NonNullList<ItemStack> list = NonNullList.withSize(2, ItemStack.EMPTY);

private Object difficultyManager;

 

@Override

protected void initEntityAI()

{

//this.tasks.addTask(2, new EntityAIWander(this, 1.25D, 5));

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

this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 1.0F));

this.tasks.addTask(1, new EntityAILeapAtTarget(this, 0.6F));

//this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.75D, true));

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

this.canEquipItem = true;

//this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));

        //this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false, new Class[0]));

//

//note some tasks commented out due to extended class or not wanting entity to be hostile

}

 

 

@Override

protected void applyEntityAttributes()

{

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(10.0D);

this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.2001D);

this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(6.0D);

 

}

 

 

protected SoundEvent getAmbientSound()

    {

        return SoundsHandler.ENTITY_STISH_AMBIENT;

    }

 

    protected SoundEvent getHurtSound(DamageSource damageSourceIn)

    {

        return SoundsHandler.ENTITY_STISH_HURT;

    }

 

    protected SoundEvent getDeathSound()

    {

        return SoundsHandler.ENTITY_STISH_DEATH;

    }

 

 

@Override

@Nullable

public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) {

 

livingdata = super.onInitialSpawn(difficulty, livingdata);

 

this.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.STONE_PICKAXE));

return livingdata;

 

 

}

 

 

 

/**

    @Override

    public ItemStack getHeldItemMainhand() {

    return getHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.STONE_PICKAXE));

    }

*/

 

 

 

 

/**

private ItemStack getHeldItem(EnumHand mainHand, ItemStack itemStack) {

// TODO Auto-generated method stub

return null;

}

*/

 

protected ResourceLocation getLootTable()

    {

    return LootTableList.ENTITIES_VILLAGER;

    }

 

 

public boolean isSpectator() {

// TODO Auto-generated method stub

return false;

}

 

 

public boolean isCreative() {

// TODO Auto-generated method stub

return false;

}

 

 

    

 

}

Edited by darkgreenminer

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.