Posted August 18, 201510 yr Hello! So a friend and I are working on a mod. I've created an entity that when right clicked on opens a gui. The gui already contains a container and all player slots work. The entity slots are assigned to a dummy inventory at the moment. My question is how would I go about add an inventory to the entity and saving it. The inventory looks like this:
August 18, 201510 yr Author You can either make the entity implement IInventory directly like you would on a TileEntity or make a separate class that does so and then store an instance of that class in the Entity. Then in the NBT read and write methods of your entity you save the inventory. It is pretty much exactly like when making a TileEntity. You see I tried that, Copying most of the tile entity code into the entity code, But it doesn't seem to work. Also how would I go about getting an instance of the entity I've just opened? I use a GuiManager to handle the guis I'm able to pass in the player but now the entity I'm interacting with.
August 18, 201510 yr Author With a TileEntity you pass x, y, z to player.openGui, they end up in your IGuiHandler. With entities you use the entityID (getEntityId()) and pass that as e.g. the x variable. Then in your IGuiHandler you can use that to get the entity back using world.getEntityByID(). Thank you so much, I was originally sending the entity ID through x but I was decoding it a different way (I was essentially making a new Entity with that id) now the crash is gone and the inventory works! I'll be sure to credit you when we release the mod. You have a tutorial page right? Do you have an official link that I can send people to?
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.