aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage
diff options
context:
space:
mode:
authorJordan Byrne <draknyte1@hotmail.com>2018-05-17 03:22:34 +1000
committerJordan Byrne <draknyte1@hotmail.com>2018-05-17 03:22:34 +1000
commit92494e56c33fc029f6b06be1c76e50bb5be56cbe (patch)
treeb7b9aa2213c4f4dca149289efe71ad018e9b4b11 /src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage
parent6a807650f8b57b4f94502d736249bda47e1117e3 (diff)
downloadGT5-Unofficial-92494e56c33fc029f6b06be1c76e50bb5be56cbe.tar.gz
GT5-Unofficial-92494e56c33fc029f6b06be1c76e50bb5be56cbe.tar.bz2
GT5-Unofficial-92494e56c33fc029f6b06be1c76e50bb5be56cbe.zip
+ Added a Large Storage Shelf.
$ Fixed shelves using wrong overlay.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf.java42
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/shelving/GT4Entity_Shelf_Large.java207
2 files changed, 238 insertions, 11 deletions
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())};
+ }
+
+
+}