Skip to content

Commit

Permalink
Prevent KeyRing being dropped when inventory is open.
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Aug 16, 2018
1 parent e709ba0 commit 0e84e8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.item.KeyItem;
import com.someguyssoftware.treasure2.item.KeyRingItem;
import com.someguyssoftware.treasure2.tileentity.AbstractTreasureChestTileEntity;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -190,6 +191,7 @@ public boolean isUsableByPlayer(EntityPlayer player) {
*/
@Override
public void openInventory(EntityPlayer player) {
getItemStack().getTagCompound().setBoolean(KeyRingItem.IS_OPEN, true);
}

/* (non-Javadoc)
Expand All @@ -204,6 +206,9 @@ public void closeInventory(EntityPlayer player) {
getItemStack().setTagCompound(new NBTTagCompound());
}
writeInventoryToNBT(getItemStack().getTagCompound());

// update the IS_OPEN flag
getItemStack().getTagCompound().setBoolean(KeyRingItem.IS_OPEN, false);
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.someguyssoftware.treasure2.tileentity.AbstractTreasureChestTileEntity;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
Expand Down Expand Up @@ -42,6 +44,7 @@
*/
public class KeyRingItem extends ModItem {
private static final String USED_ON_CHEST = "usedOnChest";
public static final String IS_OPEN = "isOpen";

/*
* The GUIID;
Expand Down Expand Up @@ -201,7 +204,22 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer play
return super.onItemRightClick(worldIn, playerIn, handIn);
}
}


/**
*
*/
@Override
public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player) {
// TODO check if the inventory is open. if so, prevent from dropping OR close inventory performing any updates to inventory
if (item.getTagCompound().getBoolean(IS_OPEN)) {
Treasure.logger.debug("The KeyRing inventory was open");
return false;
}
else {
return super.onDroppedByPlayer(item, player);
}
}

/**
* @return the keyRingGuiID
*/
Expand Down

0 comments on commit 0e84e8e

Please sign in to comment.