diff options
Diffstat (limited to 'src/main/java/gregtech/common')
6 files changed, 137 insertions, 166 deletions
diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index 946325f5f4..bcc6d7e14c 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -43,6 +43,16 @@ public class GT_Item_Machines extends ItemBlock implements IFluidContainerItem { setCreativeTab(GregTech_API.TAB_GREGTECH); } + public static IMetaTileEntity getMetaTileEntity(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) + return null; + if (!(aStack.getItem() instanceof GT_Item_Machines)) + return null; + if (aStack.getItemDamage() < 0 || aStack.getItemDamage() > GregTech_API.METATILEENTITIES.length) + return null; + return GregTech_API.METATILEENTITIES[aStack.getItemDamage()]; + } + @Override public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean par4) { try { diff --git a/src/main/java/gregtech/common/gui/GT_Container_TypeFilter.java b/src/main/java/gregtech/common/gui/GT_Container_TypeFilter.java deleted file mode 100644 index 762a9868bf..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_TypeFilter.java +++ /dev/null @@ -1,112 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.gui.GT_Slot_Render; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_TypeFilter; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_TypeFilter extends GT_ContainerMetaTile_Machine { - public GT_Container_TypeFilter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(this.mTileEntity, 0, 98, 5)); - addSlotToContainer(new Slot(this.mTileEntity, 1, 116, 5)); - addSlotToContainer(new Slot(this.mTileEntity, 2, 134, 5)); - addSlotToContainer(new Slot(this.mTileEntity, 3, 98, 23)); - addSlotToContainer(new Slot(this.mTileEntity, 4, 116, 23)); - addSlotToContainer(new Slot(this.mTileEntity, 5, 134, 23)); - addSlotToContainer(new Slot(this.mTileEntity, 6, 98, 41)); - addSlotToContainer(new Slot(this.mTileEntity, 7, 116, 41)); - addSlotToContainer(new Slot(this.mTileEntity, 8, 134, 41)); - - addSlotToContainer(new GT_Slot_Render(this.mTileEntity, 9, 35, 23)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 8, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 26, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 44, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 62, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 80, 63, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 9) { - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); - if (tSlot != null) { - if (this.mTileEntity.getMetaTileEntity() == null) { - return null; - } - if (aSlotIndex == 9) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).clickTypeIcon(aMouseclick != 0); - return null; - } - if (aSlotIndex == 10) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bOutput = (!((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, trans("116","Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, trans("117","Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 11) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = (!((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer(aPlayer, trans("122","Emit Redstone if slots contain something")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, trans("123","Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 12) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvert = (!((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, trans("120","Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, trans("121","Don't invert Redstone")); - } - return null; - } - if (aSlotIndex == 13) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter = (!((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter); - if (((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter) { - GT_Utility.sendChatToPlayer(aPlayer, trans("124","Invert Filter")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, trans("125","Don't invert Filter")); - } - return null; - } - if (aSlotIndex == 14) { - ((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed = (!((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed); - if (((GT_MetaTileEntity_TypeFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed) { - GT_Utility.sendChatToPlayer(aPlayer, trans("126","Ignore NBT")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, trans("127","NBT has to match")); - } - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public int getSlotCount() { - return 9; - } - - @Override - public int getShiftClickSlotCount() { - return 9; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java new file mode 100644 index 0000000000..07f81ccf80 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java @@ -0,0 +1,21 @@ +package gregtech.common.gui; + +import gregtech.api.gui.GT_Container_SpecialFilter; +import gregtech.api.gui.GT_GUIContainer_SpecialFilter; +import gregtech.api.gui.widgets.GT_GuiSlotTooltip; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import net.minecraft.entity.player.InventoryPlayer; + +public class GT_GUIContainer_RecipeFilter extends GT_GUIContainer_SpecialFilter { + + private static final String REPRESENTATION_SLOT_TOOLTIP = "GT5U.recipe_filter.representation_slot.tooltip"; + + public GT_GUIContainer_RecipeFilter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { + super(aInventoryPlayer, aTileEntity); + } + + @Override + protected void setupTooltips() { + addToolTip(new GT_GuiSlotTooltip(((GT_Container_SpecialFilter) mContainer).getSpecialSlot(), mTooltipCache.getData(REPRESENTATION_SLOT_TOOLTIP))); + } +} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_TypeFilter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_TypeFilter.java deleted file mode 100644 index d312c0b76a..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_TypeFilter.java +++ /dev/null @@ -1,19 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_TypeFilter extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_TypeFilter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_TypeFilter(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/TypeFilter.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { - super.drawGuiContainerBackgroundLayer(par1, par2, par3); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - } -} 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; } } |