From eaa93a0a753b92f37ab5ec82e7ab487f1ee41dc3 Mon Sep 17 00:00:00 2001 From: Dimach Date: Wed, 12 Dec 2018 09:25:36 +0200 Subject: [PATCH 1/2] Add disable sort option for input bus. Default behavior will stay same --- .../GT_MetaTileEntity_Hatch_InputBus.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index d053bc65..8c36c2af 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -6,24 +6,29 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { public GT_Recipe_Map mRecipeMap = null; + public boolean disableSort; public GT_MetaTileEntity_Hatch_InputBus(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{"Item Input for Multiblocks", - "Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")}); + super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{ + "Item Input for Multiblocks", + "Shift + right click with screwdriver to turn Sort mode on/off", + "Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")}); } public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); } - + public GT_MetaTileEntity_Hatch_InputBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { super(aName, aTier, aTier < 1 ? 1 : aTier == 1 ? 4 : aTier == 2 ? 9 : 16, aDescription, aTextures); } @@ -114,11 +119,43 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { } protected void fillStacksIntoFirstSlots() { - for (int i = 0; i < mInventory.length; i++) - for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) { - GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); - } + if (disableSort) { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null && mInventory[j].stackSize <= 0 && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) + GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + } else { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) + if (mInventory[j] != null && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) + GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("disableSort", disableSort); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + disableSort = aNBT.getBoolean("disableSort"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) + return; + if (aPlayer.isSneaking()) { + disableSort = !disableSort; + GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Sort mode: " + (disableSort ? "Disabled" : "Enabled"))); + } + } + + public String trans(String aKey, String aEnglish) { + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, false); } @Override From 81354d1ef3abde375dc6157fb7be3f6045727f6c Mon Sep 17 00:00:00 2001 From: Dimach Date: Fri, 21 Jun 2019 02:49:54 +0300 Subject: [PATCH 2/2] Changed description and optimized code. --- .../GT_MetaTileEntity_Hatch_InputBus.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java index 8c36c2af..4b81f39d 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_InputBus.java @@ -21,7 +21,7 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { public GT_MetaTileEntity_Hatch_InputBus(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, getSlots(aTier), new String[]{ "Item Input for Multiblocks", - "Shift + right click with screwdriver to turn Sort mode on/off", + "Shift + right click with screwdriver to toggle automatic item shuffling", "Capacity: " + getSlots(aTier) + " stack" + (getSlots(aTier) >= 2 ? "s" : "")}); } @@ -121,9 +121,8 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { protected void fillStacksIntoFirstSlots() { if (disableSort) { for (int i = 0; i < mInventory.length; i++) - for (int j = i + 1; j < mInventory.length; j++) - if (mInventory[j] != null && mInventory[j].stackSize <= 0 && (mInventory[i] == null || GT_Utility.areStacksEqual(mInventory[i], mInventory[j]))) - GT_Utility.moveStackFromSlotAToSlotB(getBaseMetaTileEntity(), getBaseMetaTileEntity(), j, i, (byte) 64, (byte) 1, (byte) 64, (byte) 1); + if (mInventory[i] != null && mInventory[i].stackSize <= 0) + mInventory[i] = null; } else { for (int i = 0; i < mInventory.length; i++) for (int j = i + 1; j < mInventory.length; j++) @@ -146,11 +145,9 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch { @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) - return; if (aPlayer.isSneaking()) { disableSort = !disableSort; - GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Sort mode: " + (disableSort ? "Disabled" : "Enabled"))); + GT_Utility.sendChatToPlayer(aPlayer, trans("200", "Automatic Item Shuffling: " + (disableSort ? "Disabled" : "Enabled"))); } }