From 2b6ea1bb2e8ffcb40e32d418fc1da5fa694d9839 Mon Sep 17 00:00:00 2001 From: gottsch <17928819+gottsch@users.noreply.github.com> Date: Fri, 17 Aug 2018 12:42:18 -0400 Subject: [PATCH] Bug fixes and clean up. --- .../gui/inventory/CompressorChestGui.java | 10 +++++ .../client/gui/inventory/KeyRingGui.java | 10 +++++ .../gui/inventory/StandardChestGui.java | 10 +++++ .../gui/inventory/StrongboxChestGui.java | 10 +++++ .../eventhandler/PlayerEventHandler.java | 13 +++++- .../treasure2/generator/GenUtil.java | 2 + .../inventory/AbstractChestContainer.java | 14 ++++++ .../treasure2/inventory/KeyRingInventory.java | 13 ++++++ .../treasure2/item/KeyRingItem.java | 45 ++++++++++++++++++- .../AbstractTreasureChestTileEntity.java | 4 +- Treasure2-1.12.2/update.json | 4 +- 11 files changed, 128 insertions(+), 7 deletions(-) diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/CompressorChestGui.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/CompressorChestGui.java index 7839ea529..a5a678a3e 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/CompressorChestGui.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/CompressorChestGui.java @@ -63,4 +63,14 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final int LABEL_YPOS = 5; fontRenderer.drawString(tileEntity.getDisplayName().getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB()); } + + /** + * + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + this.renderHoveredToolTip(mouseX, mouseY); + } } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/KeyRingGui.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/KeyRingGui.java index a7455cde8..a9eb2962f 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/KeyRingGui.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/KeyRingGui.java @@ -60,4 +60,14 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final int LABEL_YPOS = 5; fontRenderer.drawString(KEY_RING_LABEL, LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB()); } + + /** + * + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + this.renderHoveredToolTip(mouseX, mouseY); + } } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StandardChestGui.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StandardChestGui.java index 566cd0c0c..e896c8bdd 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StandardChestGui.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StandardChestGui.java @@ -61,4 +61,14 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final int LABEL_YPOS = 5; fontRenderer.drawString(tileEntity.getDisplayName().getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB()); } + + /** + * + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + this.renderHoveredToolTip(mouseX, mouseY); + } } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StrongboxChestGui.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StrongboxChestGui.java index 93d6255c8..e90d3f5e5 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StrongboxChestGui.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/client/gui/inventory/StrongboxChestGui.java @@ -61,4 +61,14 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final int LABEL_YPOS = 5; fontRenderer.drawString(tileEntity.getDisplayName().getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB()); } + + /** + * + */ + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + super.drawScreen(mouseX, mouseY, partialTicks); + this.renderHoveredToolTip(mouseX, mouseY); + } } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java index 81b215efe..8db04bd2a 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/eventhandler/PlayerEventHandler.java @@ -7,14 +7,25 @@ import com.someguyssoftware.treasure2.Treasure; import com.someguyssoftware.treasure2.block.FogBlock; import com.someguyssoftware.treasure2.block.WitherFogBlock; +import com.someguyssoftware.treasure2.client.gui.inventory.KeyRingGui; import com.someguyssoftware.treasure2.enums.FogType; +import com.someguyssoftware.treasure2.inventory.KeyRingContainer; +import com.someguyssoftware.treasure2.inventory.KeyRingInventory; +import com.someguyssoftware.treasure2.item.KeyRingItem; +import com.someguyssoftware.treasure2.item.TreasureItems; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; +import net.minecraft.inventory.ItemStackHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -32,7 +43,7 @@ public class PlayerEventHandler { public PlayerEventHandler(IMod mod) { setMod(mod); } - + /** * * @param event diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/generator/GenUtil.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/generator/GenUtil.java index db15b9882..a3abbe402 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/generator/GenUtil.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/generator/GenUtil.java @@ -166,6 +166,8 @@ public static boolean placeChest(World world, Block chest, ICoords coords, EnumF Treasure.logger.warn("Unable to create Chest's TileEntity, removing Chest."); return false; } + // update the TCTE facing + ((AbstractTreasureChestTileEntity)te).setFacing(facing.getIndex()); } catch(Exception e) { Treasure.logger.error("An error occurred placing chest: ", e); diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/AbstractChestContainer.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/AbstractChestContainer.java index 6c0638037..fdb61f01e 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/AbstractChestContainer.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/AbstractChestContainer.java @@ -327,4 +327,18 @@ public int getContainerInventoryYPos() { public void setContainerInventoryYPos(int containerInventoryYPos) { this.containerInventoryYPos = containerInventoryYPos; } + + /** + * @return the inventory + */ + public IInventory getChestInventory() { + return inventory; + } + + /** + * @param inventory the inventory to set + */ + public void setChestInventory(IInventory inventory) { + this.inventory = inventory; + } } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/KeyRingInventory.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/KeyRingInventory.java index bfafa3e25..1c2c6d4b5 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/KeyRingInventory.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/inventory/KeyRingInventory.java @@ -13,6 +13,7 @@ import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.NonNullList; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -191,6 +192,18 @@ public boolean isUsableByPlayer(EntityPlayer player) { */ @Override public void openInventory(EntityPlayer player) { + /* + * clear the items. prevents duplicating keys. + * this is to prevent the player from taking the keys from the key ring inventory gui, then dropping the key ring + * while the inventory is open, then picking up the key ring again with all its items intact. + * so now, if the player does dropping the key ring, it will not have any items in it's inventory and the player will lose any + * keys that are left in the gui when closed. + */ + if (getItemStack().getTagCompound() == null) return; + + getItemStack().getTagCompound().setTag("Items", new NBTTagList()); + + // set the IS_OPEN tag getItemStack().getTagCompound().setBoolean(KeyRingItem.IS_OPEN, true); } diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/item/KeyRingItem.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/item/KeyRingItem.java index 1f652fa24..4ca153327 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/item/KeyRingItem.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/item/KeyRingItem.java @@ -61,6 +61,48 @@ public KeyRingItem(String modID, String name) { setCreativeTab(Treasure.TREASURE_TAB); } + /** + * Called when the item is crafted (not added via Creative). + * Initializes the item with a tag compound inital values. + */ + @Override + public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) { + if (!worldIn.isRemote) { + if (!stack.hasTagCompound()) { + stack.setTagCompound(new NBTTagCompound()); + } + stack.getTagCompound().setBoolean(USED_ON_CHEST, false); + stack.getTagCompound().setBoolean(IS_OPEN, false); + } + super.onCreated(stack, worldIn, playerIn); + } + + /** + * Call before the block is activated. (Isn't called for right click on non-item ie AIR) + * Initializes the item with a tag compound inital values. + * This *helps* initialize the itemStack's tag compound when it is added to the players inventory via the creative gui. + * You still have to use on a block before you can open the inventory. + * + * This is called when the item is used, before the block is activated. + * @param stack The Item Stack + * @param player The Player that used the item + * @param world The Current World + * @param pos Target position + * @param side The side of the target hit + * @param hand Which hand the item is being held in. + * @return Return PASS to allow vanilla handling, any other to skip normal code. + */ + public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { + if (!world.isRemote) { + ItemStack heldItem = player.getHeldItem(hand); + if (!heldItem.hasTagCompound()) { + heldItem.setTagCompound(new NBTTagCompound()); + } + heldItem.getTagCompound().setBoolean(USED_ON_CHEST, false); + } + return EnumActionResult.PASS; + } + /** * */ @@ -210,9 +252,8 @@ public ActionResult onItemRightClick(World worldIn, EntityPlayer play */ @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 + // NOTE only works on 'Q' press, not mouse drag and drop if (item.getTagCompound().getBoolean(IS_OPEN)) { - Treasure.logger.debug("The KeyRing inventory was open"); return false; } else { diff --git a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/tileentity/AbstractTreasureChestTileEntity.java b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/tileentity/AbstractTreasureChestTileEntity.java index f4e18d710..e818c2c76 100644 --- a/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/tileentity/AbstractTreasureChestTileEntity.java +++ b/Treasure2-1.12.2/src/com/someguyssoftware/treasure2/tileentity/AbstractTreasureChestTileEntity.java @@ -215,7 +215,7 @@ public NBTTagCompound writePropertiesToNBT(NBTTagCompound parentNBT) { parentNBT.setString("CustomName", this.customName); } // write facing - Treasure.logger.debug("Writing FACING to NBT ->{}", getFacing()); +// Treasure.logger.debug("Writing FACING to NBT ->{}", getFacing()); parentNBT.setInteger("facing", getFacing()); } catch(Exception e) { @@ -300,7 +300,7 @@ public void readPropertiesFromNBT(NBTTagCompound parentNBT) { } // read the facing if (parentNBT.hasKey("facing")) { - Treasure.logger.debug("Has 'facing' key -> {}", parentNBT.getInteger("facing")); +// Treasure.logger.debug("Has 'facing' key -> {}", parentNBT.getInteger("facing")); this.setFacing(parentNBT.getInteger("facing")); } } diff --git a/Treasure2-1.12.2/update.json b/Treasure2-1.12.2/update.json index a8d4efc3e..e40501d68 100644 --- a/Treasure2-1.12.2/update.json +++ b/Treasure2-1.12.2/update.json @@ -2,7 +2,7 @@ "homepage": "https://minecraft.curseforge.com/projects/treasure2", "promos": { "1.12.2-latest": "0.9.0", - "1.12.2-recommended": "0.8.0" + "1.12.2-recommended": "0.9.0" }, "1.12.2": { "0.5.0": "alpha release", @@ -13,6 +13,6 @@ "0.6.0": "alpha: updated to use Forge 14.23.4.2705\nUsing Loot Tables instead of custom loot generation.\nFixed chest registry check for Wither Chest.\nFixed chunk count reset in world generators.\nAdded 6 epic (extra powerful) potions.\nFixed Skeleton Key so that it doesnt open Wither Chests.\nAdded Spanish Moss.\nTweaking the Pit gen settings.\nAdded probability config for fog.\nRandomize fog generation and size.\nAdded Mob Trapped Pit.", "0.7.0": "beta: add Treasure Tool.\nUpdated recipes.\nUpdated tooltips to reflect what is craftable.\nGeneral Clean up.", "0.8.0": "beta: add config option to enable/disable Lock drops when unlocked.\nFix Wither Tree Gen data not being saved to NBT.\nAdded Savanna to the Wither Tree biome white list.\n-Fixed HUGE bug where the chest wasn't saving its inventory and state if it was locked when broken.\nAdded dump() method to TreasureChestBlock.", - "0.9.0": "" + "0.9.0": "beta: fixed when breaking Wither Chest top, that it does not spawn a Wither Chest Top item.\nFixed when scrolling over Wither Chest Top item crashes game.\nFix Wither Log rotations when placed.\nAdded Wither Planks.\nFixed lock rotations when re-placing locked chest.\nFixed bug where you could drop Key Ring will inventory is open and make duplicate keys.\nFixed Tooltips not rendering in custom GUIs." } }