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?