Jump to content

Add ItemStack to chest from client side without SimpleNetworkWrapper.


Recommended Posts

I have a mod that change chests inventories near the player when player press button.

All works fine, however, since I send custom packets to the server to manipulate chests inventory, mod, sure, should be installed both on client and dedicated server to work.
Because my mod do not add any block or whatever to the game, I start to think about making it client-side only.


Why I think it is possible?
Well, because one solution is already exist: manipulate player, simulate keypresses, simulate mouse movement etc.
But it's terrible, hacky, and hard solution. So I trying to avoid it and do job more directly.


For example, when I connect from client with my mod to the dedicated server without it, I can do something like:

if (keyBinding.isPressed()) {
    Minecraft minecraft = Minecraft.getMinecraft();
    EntityPlayerSP player = minecraft.thePlayer;
    ItemStack itemStack = new ItemStack(Item.getItemById(20), 25); // 25 Glass

    player.inventoryContainer.putStackInSlot(10, itemStack);

And voila! Player got items, client side, no use network wrapper.

But when I look at "player.inventoryContainer", I can not understand what kind of dark magic goes inside.


Sure, I can not do something like because world object is client side:

World world = player.getEntityWorld();
BlockPos blockPos = new BlockPos(player.posX + 1, player.posY, player.posZ);
TileEntityChest tileEntityChest = (TileEntityChest) world.getTileEntity(blockPos);
tileEntityChest.setInventorySlotContents(10, itemStack);

So, question is:
How to add ItemStack to chest from client side without "NETWORK.registerMessage(MainMessage.Handler.class, MainMessage.class, 0, Side.SERVER)"..?

P.S: Sorry for my English.

Link to comment
Share on other sites

For modders who read this and think to do same thing as I tried to do:


Most probably you will encounter many (including barely solvable, logical) issues. Type of "What if ..?".


For example, player has no free slots and press the button. We need take 1 item from inventory away, to free player's hand, to send interraction packet.

Where to store it? Maybe drop on the ground and pickup after? Ok.


But What If, player currently, for example, near the lake of lava? He will press the button, drop currently equipped diamond sword of whatever, it fall into the lava and...:|


Or what if this item is from another mod, and this mod override ItemTossEvent and cause dropped item to explode?


Or what if you want it to work with containers from another mods, but then you can encounter additional problems with, let's say, catching proper GUI from GuiOpenEvent after interaction.


Or what if ...


So, be ready for this. For now I make decision to stay with server-side solution. ¬¬

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.