Posted September 2, 201510 yr Hello guys, I am triing to change the size of the player inventory. He can upgrade it later so it gets bigger again. I would render the inventory gui on myself later. My problem is the setting of the inventory size. I thought using the entity construct event would allow me to do so, but im wrong. First problem is, that at the time the event is fired the player.inventory is null (which makes no sense to me, since it is initialized via public InventoryPlayer inventory = new InventoryPlayer(this) If I set the inventory myself via player.inventory = new InventoryPlayer(player); it gets overriden by vanilla. So my question is: How can I change the size of the inventory of the player? Do I need to create a custom class, overriding the inventory? Where do I need to apply my changes? Mfg Failender
September 2, 201510 yr You need to override the vanilla inventory. Subsribe to the GuiOpenEvent, and change event.gui[code] to your custom inventory gui. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
September 2, 201510 yr Author Alright. Managed to do a lot. (Apparently strg v code messes up the formatting a bit) Created my own class, which does nothing but reduce the inventory size. Applied the inventory every time the player joiins the world. Two problems I got right now. 1. The player picks up items, even though his inventory is already full. I am confused, this shouldnt happen since the important methods of InventoryPlayer seem to always iterate over mainInventory.length 2. The hotbar only updates after opening the custom gui public class InventoryPlayerCustom extends InventoryPlayer{ public InventoryPlayerCustom(EntityPlayer playerIn) { super(playerIn); mainInventory = new ItemStack[18]; } } @SubscribeEvent public void joining(EntityJoinWorldEvent event) { if(event.entity instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.entity; player.inventory = new InventoryPlayerCustom(player); } } EDIT: I guess I could be fixxing the 2nd problem by rendering it on my own, but I dont understand it. Normally the hotbar renderer should access the first 9 slots in the InventoryPlayer, where InveotryPlayer is my class and the first 9 slots shouldnt be out of sync
September 3, 201510 yr Author found out that the problem with the hotbar is that the inventory is not synced. opening and closing the gui syncs it, thats why its fixxed after that. I could sync it using packets in combination with PlayerEvent.ItemPickupEvent. First problem.. how can I prevent an item from beeing picked up? If I can prevent it I can simply do checks in the ItemPickupEvent event and if my inventory is full prevent pickup
September 3, 201510 yr There are 2 pickup events! Many people don't know that EntityItemPickupEvent can be cancelled and is called before you pickup EntityItem, so that is what you are looking for. 1.7.10 is no longer supported by forge, you are on your own.
September 3, 201510 yr Author Perfect sir! That was exactly what I needed! Now I just need to find a solution for problem number two, rest of the things should take some time to figure out but be managable
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.