Jump to content

[1.7.10] Changing Player Inventory on Server Side


joecanmakeit

Recommended Posts

So I'm trying to make a very small mod to ban the use of specific items.  The mod just constantly checks each player's inventory and sets any slot with a "restricted" item to null.

 

This works fine when it's loaded on both the client and the server; the moment I move an item from the Creative Inventory to my hotbar, it disappears.  But I really want this mod to be server-side only.  Here's my code:

 

@SubscribeEvent
    public void onPlayerTick(PlayerTickEvent e) {
        EntityPlayer player = e.player;
        if (!e.player.worldObj.isRemote) {
            for (int i = 0; i < player.inventory.mainInventory.length; i++) {
                ItemStack is = player.inventory.mainInventory[i];
                if (is != null) {
                    Item it = is.getItem();
                    // MFYLog.bannedItems is an ArrayList<Item>
                    for (Item compare : MFYLog.bannedItems) {
                        if (it == compare) {
                            player.inventory.setInventorySlotContents(i, null);
} } } } }

 

The Bug: The item isn't usable, which is good, but it is visible.  It sticks around on the hotbar, and can be moved around my inventory.  The item will disappear if I interact with any other block in the game.

 

Reading other posts, my best guess is I need to send a packet of some type, but I don't have much experience with packets, and the tutorials I could find only talked about custom packets.  In this case I just want to send whatever vanilla packet is normally sent with an inventory update.  Any hints?

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.

Guest
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.

Announcements



×
×
  • Create New...

Important Information

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