Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONTAINER
- package RpgInventory;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.CompressedStreamTools;
- import net.minecraft.nbt.NBTTagCompound;
- public class RpgContainer extends Container {
- File rpgfile = new File("rpg.dat");
- NBTTagCompound nbt1;
- NBTTagCompound nbt2;
- public RpgInventory rpgInv;
- public RpgContainer (EntityPlayer p1, RpgInventory rpg)
- {
- super();
- rpgInv = rpg;
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 0, 6, 16, 0));// necklace
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 1, 6, 37, 1));//shield
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 2, 82, 16, 2));//cloak
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 3, 82, 38, 3));//gloves
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 4, 82, 59, 4));//ring
- this.addSlotToContainer(new SlotRpgArmor( this, rpgInv, 5, 6, 58, 4));//ring
- for (int var4 = 0; var4 < 3; ++var4)
- {
- for (int var5 = 0; var5 < 9; ++var5)
- {
- this.addSlotToContainer(new Slot(p1.inventory, (var5 + (var4 + 1) * 9), 8 + var5 * 18, 84 + var4 * 18));
- }
- }
- for (int var4 = 0; var4 < 9; ++var4)
- {
- this.addSlotToContainer(new Slot(p1.inventory, var4, 8 + var4 * 18, 142));
- }
- this.onGuiOpen(rpgInv);
- }
- public void onGuiOpen(RpgInventory inv)
- {
- inv = rpgInv;
- try {
- File var42 = new File("rpg.dat");
- NBTTagCompound var52 = new NBTTagCompound();
- var52 = CompressedStreamTools.readCompressed(new FileInputStream(var42));
- inv.readFromNBT(var52);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onCraftGuiClosed(EntityPlayer player)
- {
- try {
- File var4 = new File("rpg.dat");
- NBTTagCompound var2 = new NBTTagCompound();
- CompressedStreamTools.writeCompressed(var2, new FileOutputStream(var4));
- var2 = rpgInv.writeToNBT(new NBTTagCompound());
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public boolean doesGuiPauseGame()
- {
- return false;
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
- {
- return null;
- }
- public boolean canInteractWith(EntityPlayer var1) {
- return true;
- }
- }
- INVENTORY
- package RpgInventory;
- 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;
- public class RpgInventory implements IInventory {
- ItemStack[] armorSlots = new ItemStack[6];
- private EntityPlayer player;
- public RpgInventory instance;
- public RpgInventory(EntityPlayer par1EntityPlayer)
- {
- this.player = par1EntityPlayer;
- instance = this;
- }
- public boolean inventoryChanged = false;
- public int getSizeInventory() {
- return 6;
- }
- public ItemStack getJewelInSlot(int par1)
- {
- return this.armorSlots[par1];
- }
- /**
- * Returns a slot index in main inventory containing a specific itemID
- */
- private int findJewel(int par1)
- {
- for (int var2 = 0; var2 < this.armorSlots.length; ++var2)
- {
- if (this.armorSlots[var2] != null && this.armorSlots[var2].itemID == par1)
- {
- return var2;
- }
- }
- return -1;
- }
- public boolean getJewel(int par1)
- {
- int var2 = this.findJewel(par1);
- return var2 >= 0;
- }
- public ItemStack getJewelFromStack(int par1)
- {
- ItemStack[] var2 = this.armorSlots;
- if (par1 >= var2.length)
- {
- par1 -= var2.length;
- var2 = this.armorSlots;
- }
- return var2[par1];
- }
- /**
- * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
- * new stack.
- */
- public ItemStack decrStackSize(int par1, int par2)
- {
- ItemStack[] var3 = this.armorSlots;
- if (var3[par1] != null)
- {
- ItemStack var4;
- if (var3[par1].stackSize <= par2)
- {
- var4 = var3[par1];
- var3[par1] = null;
- return var4;
- }
- else
- {
- var4 = var3[par1].splitStack(par2);
- if (var3[par1].stackSize == 0)
- {
- var3[par1] = null;
- }
- return var4;
- }
- }
- else
- {
- return null;
- }
- }
- /**
- * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
- * like when you close a workbench GUI.
- */
- public ItemStack getStackInSlotOnClosing(int par1)
- {
- ItemStack[] var2 = this.armorSlots;
- if (var2[par1] != null)
- {
- ItemStack var3 = var2[par1];
- var2[par1] = null;
- return var3;
- }
- else
- {
- return null;
- }
- }
- public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
- {
- ItemStack[] var3 = this.armorSlots;
- var3[par1] = par2ItemStack;
- }
- public ItemStack getStackInSlot(int par1)
- {
- ItemStack[] var2 = this.armorSlots;
- return var2[par1];
- }
- public String getInvName()
- {
- return "RpgInventory";
- }
- public int getInventoryStackLimit()
- {
- return 64;
- }
- public void onInventoryChanged()
- {
- this.inventoryChanged = true;
- }
- public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
- {
- return this.player.isDead ? false : par1EntityPlayer.getDistanceSqToEntity(this.player) <= 64.0D;
- }
- /**
- * Writes the inventory out as a list of compound tags. This is where the slot indices are used (+100 for armor, +80
- * for crafting).
- */
- public NBTTagCompound writeToNBT(NBTTagCompound par1NBTTagCompound)
- {
- System.out.println("written to NBT");
- NBTTagList var2 = new NBTTagList();
- for (int var3 = 0; var3 < this.armorSlots.length; ++var3)
- {
- if (this.armorSlots[var3] != null)
- {
- NBTTagCompound compoundSlot = new NBTTagCompound();
- compoundSlot .setByte("Slot", (byte)var3);
- this.armorSlots[var3].writeToNBT(compoundSlot );
- var2.appendTag(compoundSlot);
- }
- }
- par1NBTTagCompound.setTag("ItemInSlotX", var2);
- return par1NBTTagCompound;
- }
- /**
- * Reads from the given tag list and fills the slots in the inventory with the correct items.
- */
- public void readFromNBT(NBTTagCompound par1NBTTagCompound)
- {
- System.out.println("read from NBT");
- NBTTagList var2 = par1NBTTagCompound.getTagList("ItemInSlotX");
- this.armorSlots = new ItemStack[6];
- for (int var3 = 0; var3 < var2.tagCount(); ++var3)
- {
- NBTTagCompound compoundSlot = (NBTTagCompound)var2.tagAt(var3);
- byte var5 = compoundSlot .getByte("Slot");
- if (var5 >= 0 && var5 < this.armorSlots.length)
- {
- this.armorSlots[var5] = ItemStack.loadItemStackFromNBT(compoundSlot );
- }
- }
- }
- public void openChest() {}
- public void closeChest() {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement