Skip to content

Commit

Permalink
Bug fixes and clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Aug 17, 2018
1 parent 0e84e8e commit 2b6ea1b
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +43,7 @@ public class PlayerEventHandler {
public PlayerEventHandler(IMod mod) {
setMod(mod);
}

/**
*
* @param event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
*
*/
Expand Down Expand Up @@ -210,9 +252,8 @@ public ActionResult<ItemStack> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"));
}
}
Expand Down
4 changes: 2 additions & 2 deletions Treasure2-1.12.2/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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."
}
}

0 comments on commit 2b6ea1b

Please sign in to comment.