From ab8924691ec9f2699e477f55df0f0c6b1d498be6 Mon Sep 17 00:00:00 2001 From: draknyte1 Date: Sat, 18 Feb 2017 11:19:53 +1000 Subject: % Fish Trap Changes. --- .../gtPlusPlus/core/block/machine/FishTrap.java | 6 +- .../core/container/Container_FishTrap.java | 6 +- .../gtPlusPlus/core/gui/machine/GUI_FishTrap.java | 4 +- src/Java/gtPlusPlus/core/handler/GuiHandler.java | 6 +- .../core/inventories/InventoryFishTrap.java | 177 ++++++++++++++++++++ .../core/inventories/InventoryFishtrap.java | 185 --------------------- .../tileentities/general/TileEntityFishTrap.java | 4 +- 7 files changed, 190 insertions(+), 198 deletions(-) create mode 100644 src/Java/gtPlusPlus/core/inventories/InventoryFishTrap.java delete mode 100644 src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/core/block/machine/FishTrap.java b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java index fd91a1d500..089e63597b 100644 --- a/src/Java/gtPlusPlus/core/block/machine/FishTrap.java +++ b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java @@ -3,7 +3,7 @@ package gtPlusPlus.core.block.machine; import gtPlusPlus.GTplusplus; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.tileentities.general.TileEntityFishtrap; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -66,7 +66,7 @@ public class FishTrap extends BlockContainer if (world.isRemote) return true; TileEntity te = world.getTileEntity(x, y, z); - if (te != null && te instanceof TileEntityFishtrap){ + if (te != null && te instanceof TileEntityFishTrap){ player.openGui(GTplusplus.instance, 5, world, x, y, z); return true; } @@ -85,7 +85,7 @@ public class FishTrap extends BlockContainer @Override public TileEntity createNewTileEntity(World world, int p_149915_2_) { - return new TileEntityFishtrap(); + return new TileEntityFishTrap(); } } \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/container/Container_FishTrap.java b/src/Java/gtPlusPlus/core/container/Container_FishTrap.java index 9502ada19f..9e69ed4d46 100644 --- a/src/Java/gtPlusPlus/core/container/Container_FishTrap.java +++ b/src/Java/gtPlusPlus/core/container/Container_FishTrap.java @@ -3,7 +3,7 @@ package gtPlusPlus.core.container; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.inventories.*; import gtPlusPlus.core.slots.SlotNoInput; -import gtPlusPlus.core.tileentities.general.TileEntityFishtrap; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.*; @@ -12,7 +12,7 @@ import net.minecraft.world.World; public class Container_FishTrap extends Container { - protected TileEntityFishtrap tile_entity; + protected TileEntityFishTrap tile_entity; public final InventoryFishTrap inventoryChest; private World worldObj; @@ -27,7 +27,7 @@ public class Container_FishTrap extends Container { private int[] slotStorage = new int[15]; - public Container_FishTrap(InventoryPlayer inventory, TileEntityFishtrap te){ + public Container_FishTrap(InventoryPlayer inventory, TileEntityFishTrap te){ this.tile_entity = te; this.inventoryChest = te.getInventory(); diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java index 11beacaae7..81a37d2751 100644 --- a/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java @@ -2,7 +2,7 @@ package gtPlusPlus.core.gui.machine; import gtPlusPlus.core.container.Container_FishTrap; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.tileentities.general.TileEntityFishtrap; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; @@ -17,7 +17,7 @@ public class GUI_FishTrap extends GuiContainer { private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/FishTrap.png"); - public GUI_FishTrap(InventoryPlayer player_inventory, TileEntityFishtrap te){ + public GUI_FishTrap(InventoryPlayer player_inventory, TileEntityFishTrap te){ super(new Container_FishTrap(player_inventory, te)); } diff --git a/src/Java/gtPlusPlus/core/handler/GuiHandler.java b/src/Java/gtPlusPlus/core/handler/GuiHandler.java index f58ad539bc..5f2416413b 100644 --- a/src/Java/gtPlusPlus/core/handler/GuiHandler.java +++ b/src/Java/gtPlusPlus/core/handler/GuiHandler.java @@ -9,7 +9,7 @@ import gtPlusPlus.core.gui.machine.*; import gtPlusPlus.core.interfaces.IGuiManager; import gtPlusPlus.core.inventories.BaseInventoryBackpack; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.tileentities.general.TileEntityFishtrap; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbenchAdvanced; import gtPlusPlus.core.util.Utils; @@ -80,7 +80,7 @@ public class GuiHandler implements IGuiHandler { } if (ID == GUI6){ - return new Container_FishTrap(player.inventory, (TileEntityFishtrap)te); + return new Container_FishTrap(player.inventory, (TileEntityFishTrap)te); } } @@ -126,7 +126,7 @@ public class GuiHandler implements IGuiHandler { return new GUI_WorkbenchAdvanced(player.inventory, (TileEntityWorkbenchAdvanced)te); } if (ID == GUI6){ - return new GUI_FishTrap(player.inventory, (TileEntityFishtrap)te); + return new GUI_FishTrap(player.inventory, (TileEntityFishTrap)te); } } diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryFishTrap.java b/src/Java/gtPlusPlus/core/inventories/InventoryFishTrap.java new file mode 100644 index 0000000000..ca6d006740 --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/InventoryFishTrap.java @@ -0,0 +1,177 @@ +package gtPlusPlus.core.inventories; + +import gtPlusPlus.core.util.Utils; +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 InventoryFishTrap implements IInventory{ + + private String name = "Fishtrap"; + + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 15; + + /** Inventory's size must be same as number of slots you add to the Container class */ + private ItemStack[] inventory = new ItemStack[INV_SIZE]; + + public void readFromNBT(NBTTagCompound nbt){ + NBTTagList list = nbt.getTagList("Items", 10); + inventory = new ItemStack[INV_SIZE]; + for(int i = 0;i= 0 && slot < INV_SIZE){ + Utils.LOG_INFO("Trying to read NBT data from inventory."); + inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } + + public void writeToNBT(NBTTagCompound nbt){ + NBTTagList list = new NBTTagList(); + for(int i = 0;i amount) + { + stack = stack.splitStack(amount); + // Don't forget this line or your inventory will not be saved! + markDirty(); + } + else + { + // this method also calls markDirty, so we don't need to call it again + setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) + { + ItemStack stack = getStackInSlot(slot); + setInventorySlotContents(slot, null); + return stack; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) + { + inventory[slot] = stack; + + if (stack != null && stack.stackSize > getInventoryStackLimit()) + { + stack.stackSize = getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + markDirty(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return name; + } + + // 1.7.2+ renamed to hasCustomInventoryName + @Override + public boolean hasCustomInventoryName() + { + return name.length() > 0; + } + + @Override + public int getInventoryStackLimit() + { + return 64; + } + + /** + * This is the method that will handle saving the inventory contents, as it is called (or should be called!) + * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also + * let you change things in your inventory without ever opening a Gui, if you want. + */ + // 1.7.2+ renamed to markDirty + @Override + public void markDirty() + { + for (int i = 0; i < getSizeInventory(); ++i) + { + ItemStack temp = getStackInSlot(i); + if (temp != null){ + //Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize); + } + + if (temp != null && temp.stackSize == 0) { + inventory[i] = null; + } + } + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) + { + return true; + } + + // 1.7.2+ renamed to openInventory(EntityPlayer player) + @Override + public void openInventory() {} + + // 1.7.2+ renamed to closeInventory(EntityPlayer player) + @Override + public void closeInventory() {} + + /** + * This method doesn't seem to do what it claims to do, as + * items can still be left-clicked and placed in the inventory + * even when this returns false + */ + @Override + public boolean isItemValidForSlot(int slot, ItemStack itemstack) + { + // Don't want to be able to store the inventory item within itself + // Bad things will happen, like losing your inventory + // Actually, this needs a custom Slot to work + return true; + } + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java b/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java deleted file mode 100644 index 834173a768..0000000000 --- a/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java +++ /dev/null @@ -1,185 +0,0 @@ -package gtPlusPlus.core.inventories; - -import gtPlusPlus.core.util.Utils; -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 InventoryFishTrap implements IInventory{ - - private String name = "Fishtrap"; - - /** Defining your inventory size this way is handy */ - public static final int INV_SIZE = 15; - - /** Inventory's size must be same as number of slots you add to the Container class */ - private ItemStack[] inventory = new ItemStack[INV_SIZE]; - - /** - * @param itemstack - the ItemStack to which this inventory belongs - */ - public InventoryFishTrap() - { - - } - - public void readFromNBT(NBTTagCompound nbt){ - NBTTagList list = nbt.getTagList("Items", 10); - inventory = new ItemStack[INV_SIZE]; - for(int i = 0;i= 0 && slot < INV_SIZE){ - Utils.LOG_INFO("Trying to read NBT data from inventory."); - inventory[slot] = ItemStack.loadItemStackFromNBT(data); - } - } - } - - public void writeToNBT(NBTTagCompound nbt){ - NBTTagList list = new NBTTagList(); - for(int i = 0;i amount) - { - stack = stack.splitStack(amount); - // Don't forget this line or your inventory will not be saved! - markDirty(); - } - else - { - // this method also calls markDirty, so we don't need to call it again - setInventorySlotContents(slot, null); - } - } - return stack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int slot) - { - ItemStack stack = getStackInSlot(slot); - setInventorySlotContents(slot, null); - return stack; - } - - @Override - public void setInventorySlotContents(int slot, ItemStack stack) - { - inventory[slot] = stack; - - if (stack != null && stack.stackSize > getInventoryStackLimit()) - { - stack.stackSize = getInventoryStackLimit(); - } - - // Don't forget this line or your inventory will not be saved! - markDirty(); - } - - // 1.7.2+ renamed to getInventoryName - @Override - public String getInventoryName() - { - return name; - } - - // 1.7.2+ renamed to hasCustomInventoryName - @Override - public boolean hasCustomInventoryName() - { - return name.length() > 0; - } - - @Override - public int getInventoryStackLimit() - { - return 64; - } - - /** - * This is the method that will handle saving the inventory contents, as it is called (or should be called!) - * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also - * let you change things in your inventory without ever opening a Gui, if you want. - */ - // 1.7.2+ renamed to markDirty - @Override - public void markDirty() - { - for (int i = 0; i < getSizeInventory(); ++i) - { - ItemStack temp = getStackInSlot(i); - if (temp != null){ - //Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize); - } - - if (temp != null && temp.stackSize == 0) { - inventory[i] = null; - } - } - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) - { - return true; - } - - // 1.7.2+ renamed to openInventory(EntityPlayer player) - @Override - public void openInventory() {} - - // 1.7.2+ renamed to closeInventory(EntityPlayer player) - @Override - public void closeInventory() {} - - /** - * This method doesn't seem to do what it claims to do, as - * items can still be left-clicked and placed in the inventory - * even when this returns false - */ - @Override - public boolean isItemValidForSlot(int slot, ItemStack itemstack) - { - // Don't want to be able to store the inventory item within itself - // Bad things will happen, like losing your inventory - // Actually, this needs a custom Slot to work - return true; - } - -} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java index a91fda7a22..5f6bd802a3 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java @@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -public class TileEntityFishtrap extends TileEntity{ +public class TileEntityFishTrap extends TileEntity{ private int tickCount = 0; private boolean isInWater = false; @@ -23,7 +23,7 @@ public class TileEntityFishtrap extends TileEntity{ private int waterSides = 0; private int baseTickRate = 600*5; - public TileEntityFishtrap(){ + public TileEntityFishTrap(){ this.inventoryContents = new InventoryFishTrap();//number of slots - without product slot setTileLocation(); } -- cgit