Jump to content

[1.16.1] Custom Entity holding an Item


Recommended Posts

Managed to make a hostile entity, however the item's, well let's just say, no dice. Found pretty much code that led me nowhere, searched through ZombieEntity, PillagerEntity and AbstractSkeletonEntity Classes.
*Entity Class:* https://pastebin.com/Kc03YVt7
*Entity Renderer:* https://pastebin.com/FTP9G3kn

Tried using this in my entity class:
    protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty) {
        this.setItemStackToSlot(EquipmentSlotType.MAINHAND, new ItemStack(Items.DIAMOND_SWORD));
`    }

And this in my entity render class:
 ` this.addLayer(new HeldItemLayer(this));`

Hope i can get pointed at what im supposed to be looking at, otherwise i will waste probably hours looking like i have already blindly, thank you in advance. (1.16.1)

Link to comment
Share on other sites

2 hours ago, diesieben07 said:
  1. You don't own bunny.com.
  2. Please update to 1.16.4.
  3. This is not visible in the code you posted.

I have updated to 1.16.4 like you said and the latest mappings, for your 1. I have no idea what you mean, since this is my very own mod package under my username. Also for 3. I have taken the code out because it was doing nothing and not giving me any errors anyways but thought id specify the closest thing I probably got to with my issue.  ` this.addLayer(new HeldItemLayer(this));`  <-- This was under in my builder super().

Link to comment
Share on other sites


1 hour ago, diesieben07 said:

Java package names are reverse domain names. If you use "com.bunny" that implies you own bunny.com. This is used to prevent name collisions, since obviously a domain cannot be own by multiple entities. If you don't own a domain name, use something that cannot be a domain name, e.g. "mod.<mod id here>". "mod" is not a valid TLD, so it is safe to use.


Please post the actual code you were trying to use to achieve this effect.


Alright i hope this fixed the issue, i will upload the classes once more with the code that i tried to use in order to get my original question to work.

Entity Renderer : https://pastebin.com/pVqqugcn

Entity Class : https://pastebin.com/sZyu0xex

If anything else is needed please let me know, although for holding an item I'm pretty sure that these two classes are all that you need in order to do so. Sorry for any inconveniences as I am ned to modding and thank you for your time.

Edited by BunnYx
Link to comment
Share on other sites

3 hours ago, diesieben07 said:

setEquipmentBasedOnDifficulty is not called by default. Look at where vanilla entities call it.

Yeah but without actually doing the difficulty setting I have no idea how to do any of the item setting if I'm being completely honest. setEquipmentBasedOnDifficulty is called from MobEntity , and by looking through that I do not see anything that I should be using. I can't paste any of the original code here but I'm very sure you know exactly what it looks like. I tried many discord forge modding servers and nobody was able to help. This is pretty much my last resort 🤷‍♂️ Wasted my whole day today playing around with Minecraft's original code to no avail.

Edited by BunnYx
Link to comment
Share on other sites

1 hour ago, diesieben07 said:

No, it is not. It is defined in MobEntity, but it is not called from there.

Once again: Look at where vanilla entities call this method.

From looking more onInitialSpawn seems to be the case, although whenever I try to override it alongside the renders of the item the game simply crashes upon loading in the world with this log. (Doing by summoning the entity only)

Updated Entity Class : https://pastebin.com/D1kZCm6H
lastest.log : https://pastebin.com/CfhZ39yS
Render Class : No changes

Edited by BunnYx
Link to comment
Share on other sites

Update, well i managed to actually add the item to the entities hand, as poopoodice mentioned the model i did more digging and it turns out i needed a few lines of code there, i am now able to add items to the mainhand as well as the offhand, however for the others aka Armor i assume i would need something else in the model class. Implemented


for the hands though. Not sure how i'd go about the armor, but regardless with the armor i will most likely just model all my entities in blockbench with the armor already on there since some models will be different sizes so i think that would be a good practice for me. Thank you to the both of you for the individual help. Big or small. Will focus on making animations and what-not in the far future since im only wanting to test all the features i need, which this was one of those :) 


Edited by BunnYx
Link to comment
Share on other sites

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

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