Jump to content

[solved][1.8] Change size of player inventory


Recommended Posts

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

Link to comment
Share on other sites

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.



Link to comment
Share on other sites

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) {
	mainInventory = new ItemStack[18];





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


Link to comment
Share on other sites

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

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Exception in thread "main" java.lang.IllegalStateException: Current Java is 1.8.0_271 but we require at least 17         at net.minecraftforge.bootstrap.shim.Main.main(Main.java:32) Never have successfully gotten a minecraft server up and running so I thought i'd try again. Instant unfixable issue.  
    • What MC version? What's the IP? Are any mods needed to be able to join?
    • Thank you for your answer ! Unfortunatly i have the same problem when i use setPos() public static int movingfunction(CommandContext<CommandSourceStack> context){ CommandSourceStack source = context.getSource(); if (!(source.getEntity() instanceof ServerPlayer)) { return 0; } ServerPlayer player = (ServerPlayer ) source.getEntity(); double moveSpeed = 0.5; for (int i =0; i<10000;i++) { LOGGER.info("running for the {} time", i); double x = player.getX() + player.getViewVector(1.0f).x * moveSpeed; double y = player.getY(); double z = player.getZ() + player.getViewVector(1.0f).z * moveSpeed ; Vec3 movementVec = new Vec3(x, y, z); LOGGER.info("x ={} y ={} z ={}", x, y, z); player.setPos( movementVec); } return 1; } With the logs i can see that x and z are increasing but once again my player is not moving. is there a function to use to sync the server and the client ? I also tried to use LocalPlayer instead of ServerPlayer but my code would stop when i got the object. Also i will change a bit the main topic but is there a way to similate key press ? i found KeyBinding.setKeyBindState on others post but it look like there is no more KeyBinding in 1.20   I found this code : KeyMapping.click(Minecraft.getInstance().options.keyUp.getKey()); But it doesn't seems to work   And i found this one : Minecraft.getInstance().options.keyUp.setDown(true); wich works but doesn't exactly do what i want , it doesn't release the key so for exemple i can't make him run. Minecraft.getInstance().options.keyUp.setDown(true); Minecraft.getInstance().options.keyUp.setDown(false); Minecraft.getInstance().options.keyUp.setDown(true); doesn't make him run
    • Add crash-reports with sites like https://paste.ee/ Maybe an issue with blur, essentials or cumulus_menus
  • Topics

  • Create New...

Important Information

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