diff options
Diffstat (limited to 'src/main/java')
5 files changed, 57 insertions, 151 deletions
diff --git a/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java b/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java index 5dd4f19..283eb4e 100644 --- a/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java +++ b/src/main/java/gmail/Lance5057/containers/Container_CrestMount.java @@ -9,40 +9,32 @@ import net.minecraft.item.ItemStack; public class Container_CrestMount extends Container { - private static final int INV_START = TileEntity_CrestMount.invSize, INV_END = INV_START+26, - HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8; - public final TileEntity_CrestMount inventory; - - public Container_CrestMount(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, TileEntity_CrestMount TileEntity_CrestMount) - { - this.inventory = TileEntity_CrestMount; - - int i; - - for (i = 0; i < TileEntity_CrestMount.invSize; ++i) - { - this.addSlotToContainer(new Slot(this.inventory, i, 80 + (18 * (int)(i/4)), 8 + (18*(i%4)))); - } - - for (i = 0; i < 3; ++i) - { - for (int j = 0; j < 9; ++j) - { - this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (i = 0; i < 9; ++i) - { - this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); - } + public Container_CrestMount(InventoryPlayer inventoryPlayer, TileEntity_CrestMount TileEntity_CrestMount) + { + addSlotToContainer(new Slot(TileEntity_CrestMount, 0, 0, 0)); + addSlotToContainer(new Slot(TileEntity_CrestMount, 1, 0, 16)); + addSlotToContainer(new Slot(TileEntity_CrestMount, 2, 0, 32)); + addSlotToContainer(new Slot(TileEntity_CrestMount, 3, 0, 48)); + + for (int x = 0; x < 9; x++) + { + addSlotToContainer(new Slot(inventoryPlayer, x, 8 + 18 * x, 142)); + } + + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 9; x++) + { + addSlotToContainer(new Slot(inventoryPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18)); + } + } } @Override public boolean canInteractWith(EntityPlayer player) { - return inventory.isUseableByPlayer(player); + return true; } /** @@ -51,93 +43,7 @@ public class Container_CrestMount extends Container */ public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { - ItemStack itemstack = null; - Slot slot = (Slot) this.inventorySlots.get(par2); - - if (slot != null && slot.getHasStack()) - { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - - // If item is in our custom Inventory or armor slot - if (par2 < INV_START) - { - // try to place in player inventory / action bar - if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)) - { - return null; - } - - slot.onSlotChange(itemstack1, itemstack); - } - // Item is in inventory / hotbar, try to place in custom inventory or armor slots - else - { - /* If your inventory only stores certain instances of Items, - * you can implement shift-clicking to your inventory like this: - // Check that the item is the right type - if (itemstack1.getItem() instanceof ItemCustom) - { - // Try to merge into your custom inventory slots - // We use 'InventoryItem.INV_SIZE' instead of INV_START just in case - // you also add armor or other custom slots - if (!this.mergeItemStack(itemstack1, 0, InventoryItem.INV_SIZE, false)) - { - return null; - } - } - // If you added armor slots, check them here as well: - // Item being shift-clicked is armor - try to put in armor slot - if (itemstack1.getItem() instanceof ItemArmor) - { - int type = ((ItemArmor) itemstack1.getItem()).armorType; - if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)) - { - return null; - } - } - * Otherwise, you have basically 2 choices: - * 1. shift-clicking between action bar and inventory - * 2. shift-clicking between player inventory and custom inventory - * I've implemented number 1: - */ - // item is in player's inventory, but not in action bar - if (par2 >= INV_START && par2 < HOTBAR_START) - { - // place in action bar - if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END + 1, false)) - { - return null; - } - } - // item in action bar - place in player inventory - else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1) - { - if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)) - { - return null; - } - } - } - - if (itemstack1.stackSize == 0) - { - slot.putStack((ItemStack) null); - } - else - { - slot.onSlotChanged(); - } - - if (itemstack1.stackSize == itemstack.stackSize) - { - return null; - } - - slot.onPickupFromSlot(par1EntityPlayer, itemstack1); - } - - return itemstack; + return null; } } diff --git a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java index 1ab1356..d7f6fad 100644 --- a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java +++ b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java @@ -11,6 +11,7 @@ import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.resources.I18n; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @@ -30,10 +31,10 @@ private static final ResourceLocation iconLocation = new ResourceLocation("TileE /** The inventory to render on screen */ private final TileEntity_CrestMount inventory; -public Gui_CrestMount(Container_CrestMount Container_CrestMount) +public Gui_CrestMount(InventoryPlayer invPlayer, TileEntity_CrestMount te_crest) { -super(Container_CrestMount); -this.inventory = Container_CrestMount.inventory; +super(new Container_CrestMount(invPlayer, te_crest)); +this.inventory = te_crest; } /** diff --git a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java index c3c6afe..90e883c 100644 --- a/src/main/java/gmail/Lance5057/proxy/ClientProxy.java +++ b/src/main/java/gmail/Lance5057/proxy/ClientProxy.java @@ -35,10 +35,4 @@ public class ClientProxy extends CommonProxy } return tutChest; //default, if whenever you should have passed on a wrong id } - - @Override - public EntityPlayer getPlayerEntity(MessageContext ctx) - { - return (ctx.side.isClient() ? Minecraft.getMinecraft().thePlayer : super.getPlayerEntity(ctx)); - } }
\ No newline at end of file diff --git a/src/main/java/gmail/Lance5057/proxy/CommonProxy.java b/src/main/java/gmail/Lance5057/proxy/CommonProxy.java index 3f82087..4fbfd93 100644 --- a/src/main/java/gmail/Lance5057/proxy/CommonProxy.java +++ b/src/main/java/gmail/Lance5057/proxy/CommonProxy.java @@ -43,7 +43,7 @@ public class CommonProxy implements IGuiHandler { if (ID == mod_TinkersDefense.GUI_ITEM_INV) { // Use the player's held item to create the inventory - return new Container_CrestMount(player, player.inventory, new TileEntity_CrestMount()); + return new Container_CrestMount(player.inventory, (TileEntity_CrestMount)world.getTileEntity(x, y, z)); } return null; } @@ -55,8 +55,8 @@ public class CommonProxy implements IGuiHandler { if (ID == mod_TinkersDefense.GUI_ITEM_INV) { // We have to cast the new container as our custom class - // and pass in currently held item for the inventory - return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player, player.inventory, new TileEntity_CrestMount())); + + return new Gui_CrestMount(player.inventory, (TileEntity_CrestMount)world.getTileEntity(x, y, z)); } return null; } diff --git a/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java b/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java index 505e3be..181f39d 100644 --- a/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java +++ b/src/main/java/gmail/Lance5057/tileentities/TileEntity_CrestMount.java @@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.Constants; public class TileEntity_CrestMount extends TileEntity implements IInventory { @@ -55,7 +56,7 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory if (stack != null) { - setInventorySlotContents(slot, null); + setInventorySlotContents(slot, stack); } return stack; } @@ -111,35 +112,39 @@ public class TileEntity_CrestMount extends TileEntity implements IInventory public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); - NBTTagList items = new NBTTagList(); - - for (int i = 0; i < getSizeInventory(); ++i) - { - if (getStackInSlot(i) != null) - { - NBTTagCompound item = new NBTTagCompound(); - item.setByte("Slot", (byte) i); - getStackInSlot(i).writeToNBT(item); - items.appendTag(item); - } - } - compound.setTag("Items", items); + writeInventoryToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); - NBTTagList items = compound.getTagList("Items", compound.getId()); - for (int i = 0; i < items.tagCount(); ++i) - { - NBTTagCompound item = items.getCompoundTagAt(i); - byte slot = item.getByte("Slot"); - - if (slot >= 0 && slot < getSizeInventory()) - { - inventory[slot] = ItemStack.loadItemStackFromNBT(item); - } + readInventoryFromNBT(compound); + } + + public void readInventoryFromNBT(NBTTagCompound tags) { + NBTTagList nbttaglist = tags.getTagList("Items", Constants.NBT.TAG_COMPOUND); + for (int iter = 0; iter < nbttaglist.tagCount(); iter++) { + NBTTagCompound tagList = (NBTTagCompound) nbttaglist.getCompoundTagAt(iter); + byte slotID = tagList.getByte("Slot"); + if (slotID >= 0 && slotID < inventory.length) { + inventory[slotID] = ItemStack.loadItemStackFromNBT(tagList); } } + } + + +public void writeInventoryToNBT(NBTTagCompound tags) { + NBTTagList nbttaglist = new NBTTagList(); + for (int iter = 0; iter < inventory.length; iter++) { + if (inventory[iter] != null) { + NBTTagCompound tagList = new NBTTagCompound(); + tagList.setByte("Slot", (byte) iter); + inventory[iter].writeToNBT(tagList); + nbttaglist.appendTag(tagList); + } + } + + tags.setTag("Items", nbttaglist); + } } |
