From 420faddca46e70e3a70def168fb4e452ef193b0d Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Sat, 21 Feb 2015 21:31:16 +0000 Subject: Added just a butt ton of stuff, also thanks to pau101 for helping me with the Hand Pedestal animation :) --- .../jewelrycraft/container/JewelryInventory.java | 111 +++++++++++++++------ 1 file changed, 79 insertions(+), 32 deletions(-) (limited to 'java/darkknight/jewelrycraft/container/JewelryInventory.java') diff --git a/java/darkknight/jewelrycraft/container/JewelryInventory.java b/java/darkknight/jewelrycraft/container/JewelryInventory.java index 05accfa..ce6f0b5 100644 --- a/java/darkknight/jewelrycraft/container/JewelryInventory.java +++ b/java/darkknight/jewelrycraft/container/JewelryInventory.java @@ -4,47 +4,67 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import darkknight.jewelrycraft.item.ItemBracelet; +import darkknight.jewelrycraft.item.ItemEarrings; +import darkknight.jewelrycraft.item.ItemNecklace; +import darkknight.jewelrycraft.item.ItemRing; +import darkknight.jewelrycraft.util.PlayerUtils; public class JewelryInventory implements IInventory { - public ItemStack[] inventory = new ItemStack[18]; - public JewelryInventory() + public EntityPlayer player; + public ItemStack[] inventory = new ItemStack[18]; + + /** + * @param player + */ + public JewelryInventory(EntityPlayer player) { + this.player = player; + NBTTagCompound nbt = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + for(int i = 0; i < 18; i++) + inventory[i] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("ext" + i)); } + /** + * @return + */ @Override public int getSizeInventory() { return inventory.length; } + /** + * @param slot + * @return + */ @Override public ItemStack getStackInSlot(int slot) { return inventory[slot]; } + /** + * @param slot + * @param amount + * @return + */ @Override public ItemStack decrStackSize(int slot, int amount) { ItemStack stack = getStackInSlot(slot); - if (stack != null) - { - if (stack.stackSize > amount) - { - stack = stack.splitStack(amount); - markDirty(); - } - else - { - setInventorySlotContents(slot, null); - } - } - + if (stack != null) if (stack.stackSize > amount){ + stack = stack.splitStack(amount); + markDirty(); + }else setInventorySlotContents(slot, null); return stack; } + /** + * @param slot + * @return + */ @Override public ItemStack getStackInSlotOnClosing(int slot) { @@ -53,66 +73,93 @@ public class JewelryInventory implements IInventory return stack; } + /** + * @param slot + * @param stack + */ @Override public void setInventorySlotContents(int slot, ItemStack stack) { inventory[slot] = stack; - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } + if (stack != null && stack.stackSize > getInventoryStackLimit()) stack.stackSize = getInventoryStackLimit(); markDirty(); } + /** + * @return + */ @Override public String getInventoryName() { return "Jewelry"; } + /** + * @return + */ @Override public boolean hasCustomInventoryName() { return false; } + /** + * @return + */ @Override public int getInventoryStackLimit() { return 1; } + /** + * + */ @Override public void markDirty() { - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) - { - inventory[i] = null; - } - } + NBTTagCompound nbt = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + for(int i = 0; i < 18; i++) + if (inventory[i] != null) nbt.setTag("ext" + i, inventory[i].writeToNBT(nbt.getCompoundTag("ext" + i))); + else nbt.removeTag("ext" + i); } + /** + * @param player + * @return + */ @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } + /** + * + */ @Override public void openInventory() - { - } + {} + /** + * + */ @Override public void closeInventory() - { - } + {} + /** + * @param slot + * @param stack + * @return + */ @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { - return true; + if (slot >= 0 && slot <= 9 && stack.getItem() instanceof ItemRing) return true; + else if (slot >= 10 && slot <= 13 && stack.getItem() instanceof ItemBracelet) return true; + else if (slot >= 14 && slot <= 16 && stack.getItem() instanceof ItemNecklace) return true; + else if (slot == 17 && stack.getItem() instanceof ItemEarrings) return true; + return false; } } \ No newline at end of file -- cgit v1.2.3