diff options
5 files changed, 257 insertions, 13 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java index b137e93454..b402f19ced 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -243,6 +243,7 @@ public enum GregtechItemList implements GregtechItemContainer { //GT4 Shelves GT4_Shelf, GT4_Shelf_Iron, GT4_Shelf_FileCabinet, GT4_Shelf_Desk, GT4_Shelf_Compartment, + GT4_Shelf_Large, //Hi Amp Transformers @@ -332,7 +333,7 @@ public enum GregtechItemList implements GregtechItemContainer { Machine_Adv_ImplosionCompressor, //Advanced Vacuum Freezer Industrial_Cryogenic_Freezer, Casing_AdvancedVacuum, - FusionComputer_UV2 + FusionComputer_UV2, diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_SuperChest.java b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_SuperChest.java index 3d63f43b5c..52c21dc4b0 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_SuperChest.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_SuperChest.java @@ -14,7 +14,9 @@ import gregtech.api.gui.GT_Slot_Output; import gregtech.api.gui.GT_Slot_Render; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GT_MetaTileEntity_TieredChest; +import gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving.GT4Entity_Shelf_Large; public class CONTAINER_SuperChest extends GT_ContainerMetaTile_Machine { public int mContent = 0; @@ -32,9 +34,18 @@ public class CONTAINER_SuperChest extends GT_ContainerMetaTile_Machine { public void detectAndSendChanges() { super.detectAndSendChanges(); if (!this.mTileEntity.isClientSide() && this.mTileEntity.getMetaTileEntity() != null) { + if (this.mTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_TieredChest) { this.mContent = ((GT_MetaTileEntity_TieredChest) this.mTileEntity.getMetaTileEntity()).mItemCount; - } else { + } + + else if (ReflectionUtils.getField(this.mTileEntity, "mItemCount") != null) { + this.mContent = ReflectionUtils.getField(this.mTileEntity, "mItemCount"); + } + else if (this.mTileEntity.getMetaTileEntity() instanceof GT4Entity_Shelf_Large) { + this.mContent = ((GT4Entity_Shelf_Large) this.mTileEntity.getMetaTileEntity()).mItemCount; + } + else { this.mContent = 0; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java index 3a2f62a26a..2c24809f9a 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java @@ -28,6 +28,7 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { public byte mType = 0; public String mOldDesc = ""; public boolean mLocked = false; + protected byte mIndex = (byte) MathUtils.randInt(1, 3); public static GT_RenderedTexture texBottom = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_bottom")); public static GT_RenderedTexture texTop = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_top")); public static GT_RenderedTexture texSide = new GT_RenderedTexture(new CustomIcon("TileEntities/gt4/machine_side")); @@ -92,7 +93,10 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { } @Override - public boolean onRightclick(IGregTechTileEntity aTile, EntityPlayer aPlayer) { + public boolean onRightclick(IGregTechTileEntity aTile, EntityPlayer aPlayer) { + if (aTile.isClientSide()) { + return true; + } ItemStack tStack = aPlayer.inventory.getStackInSlot(aPlayer.inventory.currentItem); if (tStack == null) { if (KeyboardUtils.isCtrlKeyDown()) { @@ -104,11 +108,11 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { else { if ((this.mInventory[0] != null) && (this.mInventory[0].stackSize > 0)) { if (!this.mLocked) { - PlayerUtils.messagePlayer(aPlayer, "Removed "+this.mInventory[0].getDisplayName()+" x"+this.mInventory[0].stackSize+"."); - aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, this.mInventory[0]); - getBaseMetaTileEntity().setInventorySlotContents(0, null); - this.mType = 0; - return true; + PlayerUtils.messagePlayer(aPlayer, "Removed "+this.mInventory[0].getDisplayName()+" x"+this.mInventory[0].stackSize+"."); + aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, this.mInventory[0]); + getBaseMetaTileEntity().setInventorySlotContents(0, null); + this.mType = 0; + return true; } else { PlayerUtils.messagePlayer(aPlayer, "This container is locked. It belongs to "+aTile.getOwnerName()+"."); @@ -130,6 +134,9 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { return true; } else { + if (this.mInventory[0] == null) { + this.mType = 0; + } return super.onRightclick(aTile, aPlayer); } } @@ -166,12 +173,20 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { public void saveNBTData(NBTTagCompound aNBT) {//mLocked aNBT.setInteger("mType", this.mType); aNBT.setBoolean("mLocked", this.mLocked); + aNBT.setByte("mIndex", this.mIndex); } @Override public void loadNBTData(NBTTagCompound aNBT) { - this.mType = ((byte) aNBT.getInteger("mType")); - this.mLocked = (aNBT.getBoolean("mLocked")); + if (aNBT.hasKey("mIndex")) { + this.mType = ((byte) aNBT.getInteger("mType")); + } + if (aNBT.hasKey("mIndex")) { + this.mLocked = (aNBT.getBoolean("mLocked")); + } + if (aNBT.hasKey("mIndex")) { + this.mIndex = aNBT.getByte("mIndex"); + } } @Override @@ -189,9 +204,9 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { return new String[] { mOldDesc, "Decorative Item Storage", - "Right click to store something", - "Ctrl + right click to check contents", - "Ctrl + right click with a screwdriver to lock", + "Right click to store/remove something", + "Ctrl + Rmb to check contents", + "Ctrl + Rmb with a screwdriver to lock", CORE.GT_Tooltip }; } @@ -336,4 +351,9 @@ public class GT4Entity_Shelf extends GT_MetaTileEntity_BasicHull_NonElectric { } } + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + } + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java new file mode 100644 index 0000000000..bdb3584b89 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java @@ -0,0 +1,207 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.storage.shelving; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_SuperChest; +import gtPlusPlus.xmod.gregtech.api.gui.GUI_SuperChest; + +public class GT4Entity_Shelf_Large extends GT4Entity_Shelf { + + private final int mSize; + public int mItemCount; + public ItemStack mItemStack; + + + public GT4Entity_Shelf_Large(final int aID, final String aName, final String aNameRegional, final String aDescription, final int aSize) { + super(aID, aName, aNameRegional, aDescription); + this.mSize = aSize; + this.mItemCount = 0; + this.mItemStack = null; + } + + public GT4Entity_Shelf_Large(String mName, String mDescriptionArray, final int aSize, ITexture[][][] mTextures) { + super(mName, mDescriptionArray, mTextures); + this.mSize = aSize; + this.mItemCount = 0; + this.mItemStack = null; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_Shelf_Large(this.mName, this.mDescription, mSize, this.mTextures); + } + + /*@Override + public int getInvSize() { + return (mSize > 0 && mSize < 255 ? mSize : 255); + }*/ + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isDigitalChest() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + //Single Block Behaviour + //return super.onRightclick(aTile, aPlayer); + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + + String itemName = (this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing."); + String itemAmount = (this.mItemCount > 0 ? ""+this.mItemCount : "bad"); + String itemMessage = "This container currently holds "+(itemAmount.equalsIgnoreCase("bad") ? "nothing." : itemName+" x"+itemAmount+"."); + PlayerUtils.messagePlayer(aPlayer, itemMessage); + + aBaseMetaTileEntity.openGUI(aPlayer); + return true; + } + + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, + final IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_SuperChest(aPlayerInventory, aBaseMetaTileEntity); + } + + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, + final IGregTechTileEntity aBaseMetaTileEntity) { + return new GUI_SuperChest(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName()); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mItemCount", this.mItemCount); + if (this.mItemStack != null) { + aNBT.setTag("mItemStack", (NBTBase) this.mItemStack.writeToNBT(new NBTTagCompound())); + } + super.saveNBTData(aNBT); + + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mItemCount")) { + this.mItemCount = aNBT.getInteger("mItemCount"); + } + if (aNBT.hasKey("mItemStack")) { + this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); + } + super.loadNBTData(aNBT); + } + + @Override + public void onOpenGUI() { + super.onOpenGUI(); + } + + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { + if (this.getBaseMetaTileEntity().isServerSide() && this.getBaseMetaTileEntity().isAllowedToWork()) { + + if (this.mInventory[0] != null) { + this.mType = (byte) this.mIndex; + } + else { + this.mType = 0; + } + + if (this.getItemCount() <= 0) { + this.mItemStack = null; + this.mItemCount = 0; + } + if (this.mItemStack == null && this.mInventory[0] != null) { + this.mItemStack = this.mInventory[0].copy(); + } + if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount() + && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { + this.mItemCount += this.mInventory[0].stackSize; + if (this.mItemCount > this.getMaxItemCount()) { + this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); + this.mItemCount = this.getMaxItemCount(); + } else { + this.mInventory[0] = null; + } + } + if (this.mInventory[1] == null && this.mItemStack != null) { + this.mInventory[1] = this.mItemStack.copy(); + this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + this.mItemCount -= this.mInventory[1].stackSize; + } else if (this.mItemCount > 0 && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) + && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { + final int tmp = Math.min(this.mItemCount, + this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); + final ItemStack itemStack = this.mInventory[1]; + itemStack.stackSize += tmp; + this.mItemCount -= tmp; + } + if (this.mItemStack != null) { + this.mInventory[2] = this.mItemStack.copy(); + this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + } else { + this.mInventory[2] = null; + } + } + } + + private int getItemCount() { + return this.mItemCount; + } + + public void setItemCount(final int aCount) { + this.mItemCount = aCount; + } + + public int getProgresstime() { + return this.mItemCount + ((this.mInventory[0] == null) ? 0 : this.mInventory[0].stackSize) + + ((this.mInventory[1] == null) ? 0 : this.mInventory[1].stackSize); + } + + public int maxProgresstime() { + return this.getMaxItemCount(); + } + + public int getMaxItemCount() { + return this.mSize; + } + + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, + final ItemStack aStack) { + return aIndex == 1; + } + + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, + final ItemStack aStack) { + return aIndex == 0 && ((this.mInventory[0] == null && this.mItemStack == null) || GT_Utility.areStacksEqual(this.mInventory[0], aStack) || (this.mItemStack != null && GT_Utility.areStacksEqual(this.mItemStack, aStack))); + } + + public String[] getInfoData() { + if (this.mItemStack == null) { + return new String[]{ + this.getLocalName(), "No Items Stored", "Free Space: "+Integer.toString(this.getMaxItemCount())}; + } + return new String[]{ + this.getLocalName(), + "Storing: "+this.mItemStack.getDisplayName()+" x"+Integer.toString(this.mItemCount), + "Space Remaining: "+Integer.toString(this.getMaxItemCount()-this.getItemCount())+"/"+Integer.toString(this.getMaxItemCount())}; + } + + +} diff --git a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java index 810564b05b..0817202e85 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/registration/gregtech/Gregtech4Content.java @@ -59,6 +59,11 @@ public class Gregtech4Content { .getStackForm(1L)); GregtechItemList.GT4_Shelf_Compartment.set(new GT4Entity_Shelf_Compartment(874, "gtplusplus.shelf.compartment", "Compartment", "Stores Books & Things").getStackForm(1L)); + + //Custom Storage + GregtechItemList.GT4_Shelf_Large.set( + new GT4Entity_Shelf_Large(966, "gtplusplus.shelf.large", "Large Shelf", "A spacious shelf", 2048) + .getStackForm(1L)); } private static void thermalBoiler() { |