summaryrefslogtreecommitdiff
path: root/java/darkknight/jewelrycraft/container/JewelryInventory.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-02-21 21:31:16 +0000
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2015-02-21 21:31:16 +0000
commit420faddca46e70e3a70def168fb4e452ef193b0d (patch)
tree247e334012e4bf9e4fa6d42718bf601ce6bd42d9 /java/darkknight/jewelrycraft/container/JewelryInventory.java
parent3f4c717de5ebc9b942d65ae45ac87c43bdf8a31b (diff)
Added just a butt ton of stuff, also thanks to pau101 for helping me with the Hand Pedestal animation :)
Diffstat (limited to 'java/darkknight/jewelrycraft/container/JewelryInventory.java')
-rw-r--r--java/darkknight/jewelrycraft/container/JewelryInventory.java111
1 files changed, 79 insertions, 32 deletions
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