diff options
| author | Glease <4586901+Glease@users.noreply.github.com> | 2022-01-15 01:39:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-14 18:39:57 +0100 |
| commit | 77f926b06d21cdcf484e7e2e84db9becd1b549ab (patch) | |
| tree | 4090d8c804a87be4b1e8c1339d3e7c2c25b2059c /src/main/java/gregtech/common/tileentities/automation | |
| parent | 119de99ec6386aa413480e5dd6a3e815c9fe06f8 (diff) | |
| download | GT5-Unofficial-77f926b06d21cdcf484e7e2e84db9becd1b549ab.tar.gz GT5-Unofficial-77f926b06d21cdcf484e7e2e84db9becd1b549ab.tar.bz2 GT5-Unofficial-77f926b06d21cdcf484e7e2e84db9becd1b549ab.zip | |
Add recipe filter block (#870)
* add recipe filter block
* Add tooltip to recipe filter GUI & improve type filter UI interaction
now you can click special slot in type filter UI to directly set the oreprefix based on the stack held on the cursor
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/automation')
2 files changed, 106 insertions, 35 deletions
diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java new file mode 100644 index 0000000000..a2f86103f5 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java @@ -0,0 +1,89 @@ +package gregtech.common.tileentities.automation; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_SpecialFilter; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Recipe; +import gregtech.common.blocks.GT_Item_Machines; +import gregtech.common.gui.GT_GUIContainer_RecipeFilter; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER; +import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER_GLOW; + +public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFilter { + public GT_Recipe.GT_Recipe_Map mRecipeMap; + + public GT_MetaTileEntity_RecipeFilter(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, new String[]{ + "Filters 1 Recipe Type", + "Use Screwdriver to regulate output stack size", + "Does not consume energy to move Item"}); + } + + public GT_MetaTileEntity_RecipeFilter(String aName, int aTier, int aInvSlotCount, String aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + public GT_MetaTileEntity_RecipeFilter(String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); + } + + @Override + public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new GT_GUIContainer_RecipeFilter(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override + public void clickTypeIcon(boolean aRightClick, ItemStack aHandStack) { + if (!aRightClick) { + IMetaTileEntity mte = GT_Item_Machines.getMetaTileEntity(aHandStack); + if (mte instanceof GT_MetaTileEntity_BasicMachine) { + GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mte; + GT_Recipe.GT_Recipe_Map recipeList = machine.getRecipeList(); + if (recipeList != null) { + mInventory[SPECIAL_SLOT_INDEX] = machine.getStackForm(1); + mRecipeMap = recipeList; + return; + } + } + } + mInventory[SPECIAL_SLOT_INDEX] = null; + mRecipeMap = null; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RecipeFilter(this.mName, this.mTier, this.mInventory.length, this.mDescriptionArray, this.mTextures); + } + + @Override + public ITexture getOverlayIcon() { + return TextureFactory.of( + TextureFactory.of(AUTOMATION_RECIPEFILTER), + TextureFactory.builder().addIcon(AUTOMATION_RECIPEFILTER_GLOW).glow().build()); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (mRecipeMap != null) + aNBT.setString("mRecipeMap", this.mRecipeMap.mUniqueIdentifier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mRecipeMap = GT_Recipe.GT_Recipe_Map.sIndexedMappings.getOrDefault(aNBT.getString("mRecipeMap"), null); + } + + @Override + protected boolean isStackAllowed(ItemStack aStack) { + return mRecipeMap != null && mRecipeMap.containsInput(aStack); + } +} diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java index 61f0b5cb29..95b11bcb54 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_TypeFilter.java @@ -4,14 +4,11 @@ import gregtech.api.enums.OrePrefixes; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_SpecialFilter; import gregtech.api.objects.ItemData; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_TypeFilter; -import gregtech.common.gui.GT_GUIContainer_TypeFilter; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -19,14 +16,12 @@ import static gregtech.api.enums.GT_Values.W; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_TYPEFILTER; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_TYPEFILTER_GLOW; -public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_Buffer { - public boolean bNBTAllowed = false; - public boolean bInvertFilter = false; +public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilter { public int mRotationIndex = 0; public OrePrefixes mPrefix = OrePrefixes.ore; public GT_MetaTileEntity_TypeFilter(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 11, new String[]{ + super(aID, aName, aNameRegional, aTier, new String[]{ "Filters 1 Item Type", "Use Screwdriver to regulate output stack size", "Does not consume energy to move Item"}); @@ -52,23 +47,14 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_Buffer { TextureFactory.builder().addIcon(AUTOMATION_TYPEFILTER_GLOW).glow().build()); } - @Override - public boolean isValidSlot(int aIndex) { - return aIndex < 9; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_TypeFilter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_TypeFilter(aPlayerInventory, aBaseMetaTileEntity); - } - - public void clickTypeIcon(boolean aRightClick) { + public void clickTypeIcon(boolean aRightClick, ItemStack aHandStack) { if (getBaseMetaTileEntity().isServerSide()) { + ItemData data = GT_OreDictUnificator.getAssociation(aHandStack); + if (data != null && data.hasValidPrefixData()) { + this.mPrefix = data.mPrefix; + this.mRotationIndex = -1; + return; + } for (int i = 0; i < OrePrefixes.values().length; i++) { if (this.mPrefix == OrePrefixes.values()[i]) { for (this.mPrefix = null; this.mPrefix == null; this.mPrefix = OrePrefixes.values()[i]) { @@ -101,33 +87,29 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_Buffer { super.onPreTick(aBaseMetaTileEntity, aTick); if ((!getBaseMetaTileEntity().isServerSide()) || ((aTick % 8L != 0L) && mRotationIndex != -1)) return; if (this.mPrefix.mPrefixedItems.isEmpty()) { - this.mInventory[9] = null; + this.mInventory[SPECIAL_SLOT_INDEX] = null; return; } - this.mInventory[9] = GT_Utility.copyAmount(1L, this.mPrefix.mPrefixedItems.get(this.mRotationIndex = (this.mRotationIndex + 1) % this.mPrefix.mPrefixedItems.size())); - if (this.mInventory[9] == null) return; - if (this.mInventory[9].getItemDamage() == W) this.mInventory[9].setItemDamage(0); - this.mInventory[9].setStackDisplayName(this.mPrefix.toString()); + this.mInventory[SPECIAL_SLOT_INDEX] = GT_Utility.copyAmount(1L, this.mPrefix.mPrefixedItems.get(this.mRotationIndex = (this.mRotationIndex + 1) % this.mPrefix.mPrefixedItems.size())); + if (this.mInventory[SPECIAL_SLOT_INDEX] == null) return; + if (this.mInventory[SPECIAL_SLOT_INDEX].getItemDamage() == W) this.mInventory[9].setItemDamage(0); + this.mInventory[SPECIAL_SLOT_INDEX].setStackDisplayName(this.mPrefix.toString()); } @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setString("mPrefix", this.mPrefix.toString()); - aNBT.setBoolean("bInvertFilter", this.bInvertFilter); - aNBT.setBoolean("bNBTAllowed", this.bNBTAllowed); } @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); this.mPrefix = OrePrefixes.getPrefix(aNBT.getString("mPrefix"), this.mPrefix); - this.bInvertFilter = aNBT.getBoolean("bInvertFilter"); - this.bNBTAllowed = aNBT.getBoolean("bNBTAllowed"); } @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + protected boolean isStackAllowed(ItemStack aStack) { boolean tAllowPrefix = this.mPrefix.contains(aStack); if (this.mPrefix == OrePrefixes.ore) { ItemData tData = GT_OreDictUnificator.getItemData(aStack); @@ -148,6 +130,6 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_Buffer { tFix == OrePrefixes.oreMarble) tAllowPrefix = true; } } - return (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && ((this.bNBTAllowed) || (!aStack.hasTagCompound())) && (tAllowPrefix != this.bInvertFilter); + return tAllowPrefix; } } |
