joecanmakeit Posted March 12, 2015 Share Posted March 12, 2015 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? Quote Link to comment Share on other sites More sharing options...
joecanmakeit Posted March 12, 2015 Author Share Posted March 12, 2015 Awesome, that did the trick. The Immutable Set and event.phase tips are also great to know. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.