diff options
Diffstat (limited to 'src/main/java/gregtech')
218 files changed, 10847 insertions, 9377 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index 1f2591f2a2..5a46014ce4 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -100,6 +100,7 @@ import org.apache.logging.log4j.Logger; guiFactory = "gregtech.client.GT_GuiFactory", dependencies = " required-after:IC2;" + " required-after:structurelib;" + " required-after:gtnhlib;" + + " required-after:modularui;" + " after:dreamcraft;" + " after:Forestry;" + " after:PFAAGeologica;" diff --git a/src/main/java/gregtech/api/enums/Dyes.java b/src/main/java/gregtech/api/enums/Dyes.java index 46207ee781..2a546e6138 100644 --- a/src/main/java/gregtech/api/enums/Dyes.java +++ b/src/main/java/gregtech/api/enums/Dyes.java @@ -125,4 +125,8 @@ public enum Dyes implements IColorModulationContainer { public short[] getRGBA() { return mRGBa; } + + public static Dyes getDyeFromIndex(short index) { + return index != -1 ? Dyes.get(index) : Dyes.MACHINE_METAL; + } } diff --git a/src/main/java/gregtech/api/enums/SteamVariant.java b/src/main/java/gregtech/api/enums/SteamVariant.java new file mode 100644 index 0000000000..333f678900 --- /dev/null +++ b/src/main/java/gregtech/api/enums/SteamVariant.java @@ -0,0 +1,15 @@ +package gregtech.api.enums; + +import java.util.Locale; + +public enum SteamVariant { + BRONZE, + STEEL, + PRIMITIVE, + NONE; + + @Override + public String toString() { + return super.toString().toLowerCase(Locale.ENGLISH); + } +} diff --git a/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java index f2774bbd38..588fb415c2 100644 --- a/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java +++ b/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java @@ -2,7 +2,7 @@ package gregtech.api.gui; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; diff --git a/src/main/java/gregtech/api/gui/GT_Container_1by1.java b/src/main/java/gregtech/api/gui/GT_Container_1by1.java index 3c65c5e590..882b4d0502 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_1by1.java +++ b/src/main/java/gregtech/api/gui/GT_Container_1by1.java @@ -4,6 +4,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +@Deprecated public class GT_Container_1by1 extends GT_ContainerMetaTile_Machine { public GT_Container_1by1(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { diff --git a/src/main/java/gregtech/api/gui/GT_Container_2by2.java b/src/main/java/gregtech/api/gui/GT_Container_2by2.java index 92d50b3aae..4267423b75 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_2by2.java +++ b/src/main/java/gregtech/api/gui/GT_Container_2by2.java @@ -4,6 +4,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +@Deprecated public class GT_Container_2by2 extends GT_ContainerMetaTile_Machine { public GT_Container_2by2(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { diff --git a/src/main/java/gregtech/api/gui/GT_Container_2by2_Fluid.java b/src/main/java/gregtech/api/gui/GT_Container_2by2_Fluid.java deleted file mode 100644 index d2d6249e5b..0000000000 --- a/src/main/java/gregtech/api/gui/GT_Container_2by2_Fluid.java +++ /dev/null @@ -1,97 +0,0 @@ -package gregtech.api.gui; - -import gregtech.api.interfaces.IFluidAccess; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_MultiInput; -import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class GT_Container_2by2_Fluid extends GT_ContainerMetaTile_Machine { - - public GT_Container_2by2_Fluid(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - /** - * Subclasses must ensure third slot (aSlotIndex==2) is drainable fluid display item slot. - * Otherwise, subclasses must intercept the appropriate the slotClick event and call super.slotClick(2, xxx) if necessary - */ - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Render(mTileEntity, 0, 71, 26)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 1, 89, 26)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 71, 44)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 3, 89, 44)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 4 && aSlotIndex >= 0 && aMouseclick < 2) { - GT_MetaTileEntity_Hatch_MultiInput tTank = - (GT_MetaTileEntity_Hatch_MultiInput) mTileEntity.getMetaTileEntity(); - if (mTileEntity.isClientSide()) { - /* - * See comment in gregtech.api.gui.GT_Container_BasicTank.slotClick on why this is necessary - */ - Slot slot = (Slot) inventorySlots.get(aSlotIndex); - tTank.setFluid(GT_Utility.getFluidFromDisplayStack(slot.getStack()), aSlotIndex); - } - MultiFluidAccess tDrainableAccess = MultiFluidAccess.from(tTank, aSlotIndex); - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackHeld, true); - if (tDrainableAccess.isMatch(tFluidHeld, aSlotIndex)) - return handleFluidSlotClick( - tDrainableAccess, aPlayer, aMouseclick == 0, true, !tTank.isDrainableStackSeparate()); - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public int getSlotCount() { - return 0; - } - - @Override - public int getShiftClickSlotCount() { - return 0; - } - - static class MultiFluidAccess implements IFluidAccess { - private final GT_MetaTileEntity_Hatch_MultiInput mTank; - private final int mSlot; - - public MultiFluidAccess(GT_MetaTileEntity_Hatch_MultiInput aTank, int aSlot) { - this.mTank = aTank; - this.mSlot = aSlot; - } - - public boolean isMatch(FluidStack stack, int slot) { - if (!mTank.hasFluid(stack)) return true; - if (stack == null) return true; - return stack.equals(mTank.getFluid(slot)); - } - - @Override - public void set(FluidStack stack) { - mTank.setFluid(stack, mSlot); - } - - @Override - public FluidStack get() { - return mTank.getFluid(mSlot); - } - - @Override - public int getCapacity() { - return mTank.getCapacity(); - } - - static MultiFluidAccess from(GT_MetaTileEntity_Hatch_MultiInput aTank, int aSlot) { - return new MultiFluidAccess(aTank, aSlot); - } - } -} diff --git a/src/main/java/gregtech/api/gui/GT_Container_3by3.java b/src/main/java/gregtech/api/gui/GT_Container_3by3.java index 282d740347..80f3e213d6 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_3by3.java +++ b/src/main/java/gregtech/api/gui/GT_Container_3by3.java @@ -4,6 +4,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +@Deprecated public class GT_Container_3by3 extends GT_ContainerMetaTile_Machine { public GT_Container_3by3(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { diff --git a/src/main/java/gregtech/api/gui/GT_Container_4by4.java b/src/main/java/gregtech/api/gui/GT_Container_4by4.java index 0b38a265a6..6aa0717a11 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_4by4.java +++ b/src/main/java/gregtech/api/gui/GT_Container_4by4.java @@ -4,6 +4,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; +@Deprecated public class GT_Container_4by4 extends GT_ContainerMetaTile_Machine { public GT_Container_4by4(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java index dc306ec223..bc0ac72a8b 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicTank.java @@ -6,7 +6,6 @@ import gregtech.api.interfaces.IFluidAccess; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalTankBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ICrafting; @@ -123,8 +122,6 @@ public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine { public void set(FluidStack stack) { if (mIsFillableStack) mTank.setFillableStack(stack); else mTank.setDrainableStack(stack); - if (mTank instanceof GT_MetaTileEntity_DigitalTankBase) - ((GT_MetaTileEntity_DigitalTankBase) mTank).onEmptyingContainerWhenEmpty(); } @Override diff --git a/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java b/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java deleted file mode 100644 index f12f2a2ad0..0000000000 --- a/src/main/java/gregtech/api/gui/GT_Container_DigitalTank.java +++ /dev/null @@ -1,185 +0,0 @@ -package gregtech.api.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.interfaces.IFluidAccess; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalTankBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_DigitalTank extends GT_Container_BasicTank { - - public boolean outputFluid = false; - public boolean mLockFluid = false; - public boolean mVoidFluidPart = false; - public boolean mVoidFluidFull = false; - public boolean mAllowInputFromOutputSide = false; - - public Slot slotAutoOutput; - public Slot slotLockFLuid; - public Slot slotVoidOverFlow; - public Slot slotVoidFull; - public Slot slotInputFromOutput; - - public GT_Container_DigitalTank(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(mTileEntity, 0, 81, 17)); - addSlotToContainer(new GT_Slot_Output(mTileEntity, 1, 81, 44)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42)); - addSlotToContainer(slotAutoOutput = new GT_Slot_Holo(mTileEntity, 3, 8, 64, false, true, 1)); - addSlotToContainer(slotLockFLuid = new GT_Slot_Holo(mTileEntity, 4, 26, 64, false, true, 1)); - addSlotToContainer(slotVoidOverFlow = new GT_Slot_Holo(mTileEntity, 5, 152, 8, false, true, 1)); - addSlotToContainer(slotVoidFull = new GT_Slot_Holo(mTileEntity, 6, 152, 26, false, true, 1)); - addSlotToContainer(slotInputFromOutput = new GT_Slot_Holo(mTileEntity, 7, 44, 64, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - - GT_MetaTileEntity_DigitalTankBase mte = ((GT_MetaTileEntity_DigitalTankBase) mTileEntity.getMetaTileEntity()); - - if (aSlotIndex == 3) { - mte.mOutputFluid = !mte.mOutputFluid; - if (!mte.mOutputFluid) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("262", "Fluid Auto Output Disabled")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("263", "Fluid Auto Output Enabled")); - } - return null; - } - if (aSlotIndex == 4) { - String inBrackets; - mte.mLockFluid = !mte.mLockFluid; - if (mte.mLockFluid) { - if (mte.mFluid == null) { - mte.setLockedFluidName(null); - inBrackets = GT_Utility.trans("264", "currently none, will be locked to the next that is put in"); - } else { - mte.setLockedFluidName(mte.getDrainableStack().getFluid().getName()); - inBrackets = mte.getDrainableStack().getLocalizedName(); - } - GT_Utility.sendChatToPlayer( - aPlayer, String.format("%s (%s)", GT_Utility.trans("265", "1 specific Fluid"), inBrackets)); - } else { - mte.setLockedFluidName(null); - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("266", "Lock Fluid Mode Disabled")); - } - return null; - } - if (aSlotIndex == 5) { - mte.mVoidFluidPart = !mte.mVoidFluidPart; - if (!mte.mVoidFluidPart) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("267", "Overflow Voiding Mode Disabled")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("268", "Overflow Voiding Mode Enabled")); - } - return null; - } - if (aSlotIndex == 6) { - mte.mVoidFluidFull = !mte.mVoidFluidFull; - if (!mte.mVoidFluidFull) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("269", "Void Full Mode Disabled")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("270", "Void Full Mode Enabled")); - return null; - } - } - if (aSlotIndex == 7) { - mte.mAllowInputFromOutputSide = !mte.mAllowInputFromOutputSide; - if (!mte.mAllowInputFromOutputSide) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.getTrans("096")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.getTrans("095")); - } - return null; - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void sendProgressBar() { - GT_MetaTileEntity_DigitalTankBase mte = ((GT_MetaTileEntity_DigitalTankBase) mTileEntity.getMetaTileEntity()); - - for (Object crafter : this.crafters) { - ICrafting player = (ICrafting) crafter; - if (mContent != oContent) { - player.sendProgressBarUpdate(this, 100, mContent & 65535); - player.sendProgressBarUpdate(this, 101, mContent >>> 16); - } - if (outputFluid != mte.mOutputFluid) { - player.sendProgressBarUpdate(this, 103, mte.mOutputFluid ? 1 : 0); - } - if (mLockFluid != mte.mLockFluid) { - player.sendProgressBarUpdate(this, 104, mte.mLockFluid ? 1 : 0); - } - if (mVoidFluidPart != mte.mVoidFluidPart) { - player.sendProgressBarUpdate(this, 105, mte.mVoidFluidPart ? 1 : 0); - } - if (mVoidFluidFull != mte.mVoidFluidFull) { - player.sendProgressBarUpdate(this, 106, mte.mVoidFluidFull ? 1 : 0); - } - if (mAllowInputFromOutputSide != mte.mAllowInputFromOutputSide) { - player.sendProgressBarUpdate(this, 107, mte.mAllowInputFromOutputSide ? 1 : 0); - } - } - - outputFluid = mte.mOutputFluid; - mLockFluid = mte.mLockFluid; - mVoidFluidPart = mte.mVoidFluidPart; - mVoidFluidFull = mte.mVoidFluidFull; - mAllowInputFromOutputSide = mte.mAllowInputFromOutputSide; - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 103: - outputFluid = (value != 0); - break; - case 104: - mLockFluid = (value != 0); - break; - case 105: - mVoidFluidPart = (value != 0); - break; - case 106: - mVoidFluidFull = (value != 0); - break; - case 107: - mAllowInputFromOutputSide = (value != 0); - break; - } - } - - @Override - protected IFluidAccess constructFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { - return new DigitalTankFluidAccess(aTank, aIsFillableStack); - } - - static class DigitalTankFluidAccess extends BasicTankFluidAccess { - - public DigitalTankFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { - super(aTank, aIsFillableStack); - } - - @Override - public int getRealCapacity() { - return ((GT_MetaTileEntity_DigitalTankBase) mTank).getRealCapacity(); - } - - @Override - public void verifyFluidStack() {} - } -} diff --git a/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java b/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java deleted file mode 100644 index fcaf618b56..0000000000 --- a/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java +++ /dev/null @@ -1,30 +0,0 @@ -package gregtech.api.gui; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; - -public class GT_Container_MaintenanceHatch extends GT_ContainerMetaTile_Machine { - - public GT_Container_MaintenanceHatch(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 0, 80, 35, false, false, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex != 0) return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - ItemStack tStack = aPlayer.inventory.getItemStack(); - if (tStack != null) { - ((GT_MetaTileEntity_Hatch_Maintenance) mTileEntity.getMetaTileEntity()).onToolClick(tStack, aPlayer); - if (tStack.stackSize <= 0) aPlayer.inventory.setItemStack(null); - } - return null; - } -} diff --git a/src/main/java/gregtech/api/gui/GT_Container_MultiMachine.java b/src/main/java/gregtech/api/gui/GT_Container_MultiMachine.java index 722057950b..4bfc14ad57 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_MultiMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_MultiMachine.java @@ -9,6 +9,7 @@ import net.minecraft.inventory.Slot; * <p/> * The Container I use for all my Basic Machines */ +@Deprecated public class GT_Container_MultiMachine extends GT_ContainerMetaTile_Machine { public GT_Container_MultiMachine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); diff --git a/src/main/java/gregtech/api/gui/GT_Container_SpecialFilter.java b/src/main/java/gregtech/api/gui/GT_Container_SpecialFilter.java deleted file mode 100644 index 0622f52865..0000000000 --- a/src/main/java/gregtech/api/gui/GT_Container_SpecialFilter.java +++ /dev/null @@ -1,123 +0,0 @@ -package gregtech.api.gui; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_SpecialFilter; -import gregtech.api.util.GT_Utility; -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_SpecialFilter extends GT_ContainerMetaTile_Machine { - - private GT_Slot_Render mSpecialSlot; - - public GT_Container_SpecialFilter(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(mSpecialSlot = 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_SpecialFilter) this.mTileEntity.getMetaTileEntity()) - .clickTypeIcon(aMouseclick != 0, aPlayer.inventory.getItemStack()); - return null; - } - if (aSlotIndex == 10) { - ((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 11) { - ((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = - (!((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer( - aPlayer, GT_Utility.trans("122", "Emit Redstone if slots contain something")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("123", "Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 12) { - ((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvert = - (!((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("120", "Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("121", "Don't invert Redstone")); - } - return null; - } - if (aSlotIndex == 13) { - ((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter = - (!((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter); - if (((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bInvertFilter) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("124", "Invert Filter")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("125", "Don't invert Filter")); - } - return null; - } - if (aSlotIndex == 14) { - ((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed = - (!((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed); - if (((GT_MetaTileEntity_SpecialFilter) this.mTileEntity.getMetaTileEntity()).bNBTAllowed) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("126", "Ignore NBT")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.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; - } - - public GT_Slot_Render getSpecialSlot() { - return mSpecialSlot; - } -} diff --git a/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java index 63c7b224b5..f934102eb9 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java +++ b/src/main/java/gregtech/api/gui/GT_GUIColorOverride.java @@ -13,12 +13,16 @@ public class GT_GUIColorOverride { public GT_GUIColorOverride(String guiTexturePath) { try { + // this is dumb, but CombTypeTest causes cascading class load + // and leads to instantiation of GT_CoverBehaviorBase + if (Minecraft.getMinecraft() == null) return; IResource ir = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(guiTexturePath)); if (ir.hasMetadata()) { cmSection = (ColorsMetadataSection) ir.getMetadata("colors"); } - } catch (IOException ignore) { + } catch (IOException | NoClassDefFoundError ignore) { + // this is also dumb, but FMLCommonHandler#getEffectiveSide doesn't work during test } } diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java index 0752324678..19aa8fa9a8 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java @@ -9,7 +9,7 @@ import gregtech.api.gui.widgets.GT_GuiTabLine.DisplayStyle; import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet; import gregtech.api.gui.widgets.GT_GuiTabLine.GT_ITabRenderer; import gregtech.api.gui.widgets.GT_GuiTooltipManager.GT_IToolTipRenderer; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java index 16ef27c941..694b212872 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_1by1.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +@Deprecated public class GT_GUIContainer_1by1 extends GT_GUIContainerMetaTile_Machine { private final String mName; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java index 909a5b0d6a..069e6f67fe 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +@Deprecated public class GT_GUIContainer_2by2 extends GT_GUIContainerMetaTile_Machine { private final String mName; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java deleted file mode 100644 index d896349f0a..0000000000 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_2by2_Fluid.java +++ /dev/null @@ -1,32 +0,0 @@ -package gregtech.api.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; - -public class GT_GUIContainer_2by2_Fluid extends GT_GUIContainerMetaTile_Machine { - - private final String mName; - private final int textColor = this.getTextColorOrDefault("title", 0x404040); - - public GT_GUIContainer_2by2_Fluid(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { - super(new GT_Container_2by2_Fluid(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "2by2fluid.png"); - mName = aName; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColor); - fontRendererObj.drawString(mName, 8, 6, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - } -} diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java index 97caa08946..2ce72e054c 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_3by3.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +@Deprecated public class GT_GUIContainer_3by3 extends GT_GUIContainerMetaTile_Machine { private final String mName; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java index 40441e3093..df8e3d137b 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_4by4.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.RES_PATH_GUI; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.entity.player.InventoryPlayer; +@Deprecated public class GT_GUIContainer_4by4 extends GT_GUIContainerMetaTile_Machine { private final String mName; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java index 35dcf047a7..50272f4820 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java @@ -22,9 +22,6 @@ import net.minecraft.util.StatCollector; * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> * The GUI-Container I use for all my Basic Machines - * <p/> - * As the NEI-RecipeTransferRect Handler can't handle one GUI-Class for all GUIs I needed to produce some dummy-classes - * which extend this class */ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machine implements NEI_TransferRectHost { private static final int NEEDS_STEAM_VENTING = 64; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java deleted file mode 100644 index 163aaa2929..0000000000 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_DigitalTank.java +++ /dev/null @@ -1,111 +0,0 @@ -package gregtech.api.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.widgets.GT_GuiSlotTooltip; -import gregtech.api.interfaces.IDragAndDropSupport; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.net.GT_Packet_SetLockedFluid; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalTankBase; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class GT_GUIContainer_DigitalTank extends GT_GUIContainerMetaTile_Machine implements IDragAndDropSupport { - - private final String mName; - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF); - private final int textColorTitle = this.getTextColorOrDefault("title", 0x404040); - private final int textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); - - private static final String DIGITALTANK_AUTOOUTPUT_TOOLTIP = "GT5U.machines.digitaltank.autooutput.tooltip"; - private static final String DIGITALTANK_LOCKFLUID_TOOLTIP = "GT5U.machines.digitaltank.lockfluid.tooltip"; - private static final String DIGITALTANK_VOIDOVERFLOW_TOOLTIP = "GT5U.machines.digitaltank.voidoverflow.tooltip"; - private static final String DIGITALTANK_VOIDFULL_TOOLTIP = "GT5U.machines.digitaltank.voidfull.tooltip"; - private static final String DIGITALTANK_INPUTFROMOUTPUT_TOOLTIP = - "GT5U.machines.digitaltank.inputfromoutput.tooltip"; - - public GT_GUIContainer_DigitalTank( - InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { - super(new GT_Container_DigitalTank(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "DigitalTank.png"); - mName = aName; - } - - @Override - protected void setupTooltips() { - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotAutoOutput, mTooltipCache.getData(DIGITALTANK_AUTOOUTPUT_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotLockFLuid, mTooltipCache.getData(DIGITALTANK_LOCKFLUID_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotVoidOverFlow, mTooltipCache.getData(DIGITALTANK_VOIDOVERFLOW_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotVoidFull, mTooltipCache.getData(DIGITALTANK_VOIDFULL_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotInputFromOutput, mTooltipCache.getData(DIGITALTANK_INPUTFROMOUTPUT_TOOLTIP))); - } - - private GT_Container_DigitalTank getContainer() { - return (GT_Container_DigitalTank) mContainer; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString(mName, 8, 6, textColorTitle); - if (mContainer != null) { - fontRendererObj.drawString("Liquid Amount", 10, 20, textColor); - fontRendererObj.drawString( - GT_Utility.parseNumberToString(((GT_Container_DigitalTank) mContainer).mContent), - 10, - 30, - textColorValue); - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - if (mContainer != null) { - if (((GT_Container_DigitalTank) mContainer).mLockFluid) { - drawTexturedModalRect(x + 25, y + 63, 176, 0, 18, 18); - } - if (((GT_Container_DigitalTank) mContainer).outputFluid) { - drawTexturedModalRect(x + 7, y + 63, 176, 18, 18, 18); - } - if (((GT_Container_DigitalTank) mContainer).mVoidFluidPart) { - drawTexturedModalRect(x + 151, y + 7, 176, 36, 18, 18); - } - if (((GT_Container_DigitalTank) mContainer).mVoidFluidFull) { - drawTexturedModalRect(x + 151, y + 25, 176, 54, 18, 18); - } - if (((GT_Container_DigitalTank) mContainer).mAllowInputFromOutputSide) { - drawTexturedModalRect(x + 43, y + 63, 176, 72, 18, 18); - } - } - } - - @Override - public boolean handleDragAndDropGT( - GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button, boolean isGhost) { - if (!(gui instanceof GT_GUIContainer_DigitalTank) - || !((GT_GUIContainer_DigitalTank) gui).isMouseOverSlot(2, mousex, mousey) - || !isGhost) return false; - FluidStack fluidStack = GT_Utility.getFluidFromContainerOrFluidDisplay(draggedStack); - if (fluidStack == null) return false; - IGregTechTileEntity te = ((GT_GUIContainer_DigitalTank) gui).mContainer.mTileEntity; - GT_MetaTileEntity_DigitalTankBase mte = (GT_MetaTileEntity_DigitalTankBase) te.getMetaTileEntity(); - if (mte == null || !mte.allowChangingLockedFluid(fluidStack.getFluid().getName())) return false; - - GT_Values.NW.sendToServer(new GT_Packet_SetLockedFluid(te, fluidStack)); - draggedStack.stackSize = 0; - // propagate to client too - mte.setLockedFluidName(fluidStack.getFluid().getName()); - return true; - } -} diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java deleted file mode 100644 index 07ca031345..0000000000 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_MaintenanceHatch.java +++ /dev/null @@ -1,29 +0,0 @@ -package gregtech.api.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_MaintenanceHatch extends GT_GUIContainerMetaTile_Machine { - private final int textColor = this.getTextColorOrDefault("text", 0x404040), - textColorTitle = this.getTextColorOrDefault("title", 0x404040); - - public GT_GUIContainer_MaintenanceHatch(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_MaintenanceHatch(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "Maintenance.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString("Maintenance Hatch", 8, 4, textColorTitle); - fontRendererObj.drawString("Click with Tool to repair.", 8, 12, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - } -} diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java index 1f9170f3fb..7fb5026cd3 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_MultiMachine.java @@ -15,9 +15,8 @@ import net.minecraft.item.ItemStack; * NEVER INCLUDE THIS FILE IN YOUR MOD!!! * <p/> * The GUI-Container I use for all my Basic Machines - * <p/> - * As the NEI-RecipeTransferRect Handler can't handle one GUI-Class for all GUIs I needed to produce some dummy-classes which extend this class */ +@Deprecated public class GT_GUIContainer_MultiMachine extends GT_GUIContainerMetaTile_Machine { String mName; diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_SpecialFilter.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_SpecialFilter.java deleted file mode 100644 index 8f43dffffa..0000000000 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_SpecialFilter.java +++ /dev/null @@ -1,18 +0,0 @@ -package gregtech.api.gui; - -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_SpecialFilter extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_SpecialFilter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_SpecialFilter(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/SpecialFilter.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java index 635a27d6ef..cef3ddb3bf 100644 --- a/src/main/java/gregtech/api/gui/GT_GUICover.java +++ b/src/main/java/gregtech/api/gui/GT_GUICover.java @@ -5,6 +5,7 @@ import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_GtTileEntityGuiRequest; import net.minecraft.item.ItemStack; +@Deprecated public abstract class GT_GUICover extends GT_GUIScreen { public final ICoverable tile; diff --git a/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java b/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java index c077b02bf7..b0c381f104 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java +++ b/src/main/java/gregtech/api/gui/GT_GUIDialogSelectItem.java @@ -12,6 +12,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; +@Deprecated public class GT_GUIDialogSelectItem extends GT_GUIScreen { public static final int UNSELECTED = -1; private static final int cols = 9; diff --git a/src/main/java/gregtech/api/gui/GT_GUIScreen.java b/src/main/java/gregtech/api/gui/GT_GUIScreen.java index d39a6b738e..470c1045a4 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIScreen.java +++ b/src/main/java/gregtech/api/gui/GT_GUIScreen.java @@ -20,6 +20,7 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; +@Deprecated public abstract class GT_GUIScreen extends GuiScreen implements GT_IToolTipRenderer, IGuiScreen { protected GT_GuiTooltipManager ttManager = new GT_GuiTooltipManager(); diff --git a/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java b/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java deleted file mode 100644 index 205a6d74dc..0000000000 --- a/src/main/java/gregtech/api/gui/GT_Slot_Holo_ME.java +++ /dev/null @@ -1,10 +0,0 @@ -package gregtech.api.gui; - -import net.minecraft.inventory.IInventory; - -public class GT_Slot_Holo_ME extends GT_Slot_Holo { - public GT_Slot_Holo_ME( - IInventory inventory, int slotIndex, int xPos, int yPos, boolean aCanInsertItem, boolean aCanStackItem) { - super(inventory, slotIndex, xPos, yPos, aCanInsertItem, aCanStackItem, Integer.MAX_VALUE); - } -} diff --git a/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java new file mode 100644 index 0000000000..811ad8be5f --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/GT_CoverUIBuildContext.java @@ -0,0 +1,70 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import gregtech.api.interfaces.tileentity.ICoverable; +import net.minecraft.entity.player.EntityPlayer; + +public class GT_CoverUIBuildContext extends UIBuildContext { + + // cover data is not synced to client, while ID is + private final int coverID; + private final byte side; + private final ICoverable tile; + private final boolean anotherWindow; + private final int guiColorization; + + /** + * @param player Player opened this UI + * @param coverID See {@link ICoverable#getCoverIDAtSide} + * @param side Side this cover is attached to + * @param tile Tile this cover is attached to + * @param anotherWindow If cover UI is shown on top of another window + * @param guiColorization The color used to render machine's GUI + */ + public GT_CoverUIBuildContext( + EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow, int guiColorization) { + super(player); + this.coverID = coverID; + this.side = side; + this.tile = tile; + this.anotherWindow = anotherWindow; + this.guiColorization = guiColorization; + } + + /** + * @param player Player opened this UI + * @param coverID See {@link ICoverable#getCoverIDAtSide} + * @param side Side this cover is attached to + * @param tile Tile this cover is attached to + * @param anotherWindow If cover GUI is shown in opened on top of another window + */ + public GT_CoverUIBuildContext(EntityPlayer player, int coverID, byte side, ICoverable tile, boolean anotherWindow) { + this(player, coverID, side, tile, anotherWindow, tile.getGUIColorization()); + } + + public int getCoverID() { + return coverID; + } + + public byte getCoverSide() { + return side; + } + + /** + * Note that this will return different object between client v.s. server side on SP. + */ + public ICoverable getTile() { + return tile; + } + + /** + * If cover GUI is shown in opened on top of another window. + */ + public boolean isAnotherWindow() { + return anotherWindow; + } + + public int getGuiColorization() { + return guiColorization; + } +} diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java new file mode 100644 index 0000000000..2d776ce71e --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java @@ -0,0 +1,204 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.UIInfos; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.builder.UIBuilder; +import com.gtnewhorizons.modularui.common.builder.UIInfo; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; +import gregtech.api.net.GT_Packet_SendCoverData; +import gregtech.api.util.GT_CoverBehaviorBase; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class GT_UIInfos { + + /** + * Generator for {@link UIInfo} which is responsible for registering and opening UIs. + * Unlike {@link com.gtnewhorizons.modularui.api.UIInfos#TILE_MODULAR_UI}, this accepts + * custom constructors for UI. + * <br> Do NOT run {@link UIBuilder#build} on-the-fly, otherwise MP client won't register UIs. + * Instead, store to static field, just like {@link #GTTileEntityDefaultUI}. + * Such mistake can be easily overlooked by testing only SP. + */ + public static final Function<ContainerConstructor, UIInfo<?, ?>> GTTileEntityUIFactory = + containerConstructor -> UIBuilder.of() + .container((player, world, x, y, z) -> { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof ITileWithModularUI) { + return createTileEntityContainer( + player, + ((ITileWithModularUI) te)::createWindow, + te::markDirty, + containerConstructor); + } + return null; + }) + .gui(((player, world, x, y, z) -> { + if (!world.isRemote) return null; + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof ITileWithModularUI) { + return createTileEntityGuiContainer( + player, ((ITileWithModularUI) te)::createWindow, containerConstructor); + } + return null; + })) + .build(); + + private static final UIInfo<?, ?> GTTileEntityDefaultUI = GTTileEntityUIFactory.apply(ModularUIContainer::new); + + private static final Map<Byte, UIInfo<?, ?>> coverUI = new HashMap<>(); + + static { + for (byte i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + final byte side = i; + coverUI.put( + side, + UIBuilder.of() + .container((player, world, x, y, z) -> { + TileEntity te = world.getTileEntity(x, y, z); + if (!(te instanceof ICoverable)) return null; + ICoverable gtTileEntity = (ICoverable) te; + GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side); + return createCoverContainer( + player, + cover::createWindow, + te::markDirty, + gtTileEntity.getCoverIDAtSide(side), + side, + gtTileEntity); + }) + .gui((player, world, x, y, z) -> { + if (!world.isRemote) return null; + TileEntity te = world.getTileEntity(x, y, z); + if (!(te instanceof ICoverable)) return null; + ICoverable gtTileEntity = (ICoverable) te; + GT_CoverBehaviorBase<?> cover = gtTileEntity.getCoverBehaviorAtSideNew(side); + return createCoverGuiContainer( + player, + cover::createWindow, + gtTileEntity.getCoverIDAtSide(side), + side, + gtTileEntity); + }) + .build()); + } + } + + /** + * Opens TileEntity UI, created by {@link ITileWithModularUI#createWindow}. + */ + public static void openGTTileEntityUI(IHasWorldObjectAndCoords aTileEntity, EntityPlayer aPlayer) { + if (aTileEntity.isClientSide()) return; + GTTileEntityDefaultUI.open( + aPlayer, + aTileEntity.getWorld(), + aTileEntity.getXCoord(), + aTileEntity.getYCoord(), + aTileEntity.getZCoord()); + } + + /** + * Opens cover UI, created by {@link GT_CoverBehaviorBase#createWindow}. + */ + public static void openCoverUI(ICoverable tileEntity, EntityPlayer player, byte side) { + if (tileEntity.isClientSide()) return; + + GT_Values.NW.sendToPlayer( + new GT_Packet_SendCoverData( + side, + tileEntity.getCoverIDAtSide(side), + tileEntity.getComplexCoverDataAtSide(side), + tileEntity), + (EntityPlayerMP) player); + + coverUI.get(side) + .open( + player, + tileEntity.getWorld(), + tileEntity.getXCoord(), + tileEntity.getYCoord(), + tileEntity.getZCoord()); + } + + /** + * Opens UI for player's item, created by {@link com.gtnewhorizons.modularui.api.screen.IItemWithModularUI#createWindow}. + */ + public static void openPlayerHeldItemUI(EntityPlayer player) { + if (NetworkUtils.isClient()) return; + UIInfos.PLAYER_HELD_ITEM_UI.open(player); + } + + private static ModularUIContainer createTileEntityContainer( + EntityPlayer player, + Function<UIBuildContext, ModularWindow> windowCreator, + Runnable onWidgetUpdate, + ContainerConstructor containerCreator) { + UIBuildContext buildContext = new UIBuildContext(player); + ModularWindow window = windowCreator.apply(buildContext); + if (window == null) { + return null; + } + return containerCreator.of(new ModularUIContext(buildContext, onWidgetUpdate), window); + } + + @SideOnly(Side.CLIENT) + private static ModularGui createTileEntityGuiContainer( + EntityPlayer player, + Function<UIBuildContext, ModularWindow> windowCreator, + ContainerConstructor containerConstructor) { + ModularUIContainer container = createTileEntityContainer(player, windowCreator, null, containerConstructor); + if (container == null) { + return null; + } + return new ModularGui(container); + } + + private static ModularUIContainer createCoverContainer( + EntityPlayer player, + Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, + Runnable onWidgetUpdate, + int coverID, + byte side, + ICoverable tile) { + GT_CoverUIBuildContext buildContext = new GT_CoverUIBuildContext(player, coverID, side, tile, false); + ModularWindow window = windowCreator.apply(buildContext); + if (window == null) { + return null; + } + return new ModularUIContainer(new ModularUIContext(buildContext, onWidgetUpdate), window); + } + + @SideOnly(Side.CLIENT) + private static ModularGui createCoverGuiContainer( + EntityPlayer player, + Function<GT_CoverUIBuildContext, ModularWindow> windowCreator, + int coverID, + byte side, + ICoverable tile) { + ModularUIContainer container = createCoverContainer(player, windowCreator, null, coverID, side, tile); + if (container == null) { + return null; + } + return new ModularGui(container); + } + + @FunctionalInterface + public interface ContainerConstructor { + ModularUIContainer of(ModularUIContext context, ModularWindow mainWindow); + } +} diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java new file mode 100644 index 0000000000..76b4874838 --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java @@ -0,0 +1,347 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import java.util.function.BiFunction; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class GT_UITextures { + + private static final String MODID = "gregtech"; + + public static final UITexture TRANSPARENT = UITexture.fullImage(MODID, "gui/picture/transparent"); + + public static final AdaptableUITexture BACKGROUND_SINGLEBLOCK_DEFAULT = + AdaptableUITexture.of(MODID, "gui/background/singleblock_default", 176, 166, 4); + public static final SteamTexture BACKGROUND_STEAM = + SteamTexture.adaptableTexture(MODID, "gui/background/%s", 176, 166, 4); + public static final UITexture BACKGROUND_FUSION_COMPUTER = + UITexture.fullImage(MODID, "gui/background/fusion_computer"); + public static final AdaptableUITexture BACKGROUND_TEXT_FIELD = + AdaptableUITexture.of(MODID, "gui/background/text_field", 142, 28, 1); + public static final AdaptableUITexture BACKGROUND_TEXT_FIELD_LIGHT_GRAY = + AdaptableUITexture.of(MODID, "gui/background/text_field_light_gray", 61, 12, 1); + + public static final SteamTexture SLOT_ITEM_STEAM = SteamTexture.fullImage(MODID, "gui/slot/item_%s"); + public static final AdaptableUITexture SLOT_DARK_GRAY = + AdaptableUITexture.of(MODID, "gui/slot/dark_gray", 18, 18, 1); + public static final AdaptableUITexture SLOT_MAINTENANCE = + AdaptableUITexture.of(MODID, "gui/slot/maintenance", 20, 20, 1); + public static final AdaptableUITexture SLOT_UPLIFTED = AdaptableUITexture.of(MODID, "gui/slot/uplifted", 18, 18, 1); + + public static final UITexture OVERLAY_SLOT_ARROW_ME = UITexture.fullImage(MODID, "gui/overlay_slot/arrow_me"); + public static final UITexture OVERLAY_SLOT_BEAKER_1 = UITexture.fullImage(MODID, "gui/overlay_slot/beaker_1"); + public static final UITexture OVERLAY_SLOT_BEAKER_2 = UITexture.fullImage(MODID, "gui/overlay_slot/beaker_2"); + public static final UITexture OVERLAY_SLOT_BEE_DRONE = UITexture.fullImage(MODID, "gui/overlay_slot/bee_drone"); + public static final UITexture OVERLAY_SLOT_BEE_QUEEN = UITexture.fullImage(MODID, "gui/overlay_slot/bee_queen"); + public static final UITexture OVERLAY_SLOT_BENDER = UITexture.fullImage(MODID, "gui/overlay_slot/bender"); + public static final UITexture OVERLAY_SLOT_BOX = UITexture.fullImage(MODID, "gui/overlay_slot/box"); + public static final UITexture OVERLAY_SLOT_BOXED = UITexture.fullImage(MODID, "gui/overlay_slot/boxed"); + public static final UITexture OVERLAY_SLOT_CANISTER = UITexture.fullImage(MODID, "gui/overlay_slot/canister"); + public static final SteamTexture OVERLAY_SLOT_CANISTER_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/canister_%s"); + public static final UITexture OVERLAY_SLOT_CANNER = UITexture.fullImage(MODID, "gui/overlay_slot/canner"); + public static final UITexture OVERLAY_SLOT_CAULDRON = UITexture.fullImage(MODID, "gui/overlay_slot/cauldron"); + public static final UITexture OVERLAY_SLOT_CENTRIFUGE = UITexture.fullImage(MODID, "gui/overlay_slot/centrifuge"); + public static final UITexture OVERLAY_SLOT_CENTRIFUGE_FLUID = + UITexture.fullImage(MODID, "gui/overlay_slot/centrifuge_fluid"); + public static final SteamTexture OVERLAY_SLOT_CENTRIFUGE_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/centrifuge_%s"); + public static final UITexture OVERLAY_SLOT_CHARGER = UITexture.fullImage(MODID, "gui/overlay_slot/charger"); + public static final UITexture OVERLAY_SLOT_CHARGER_FLUID = + UITexture.fullImage(MODID, "gui/overlay_slot/charger_fluid"); + public static final UITexture OVERLAY_SLOT_CIRCUIT = UITexture.fullImage(MODID, "gui/overlay_slot/circuit"); + public static final SteamTexture OVERLAY_SLOT_COAL_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/coal_%s"); + public static final UITexture OVERLAY_SLOT_COMPRESSOR = UITexture.fullImage(MODID, "gui/overlay_slot/compressor"); + public static final SteamTexture OVERLAY_SLOT_COMPRESSOR_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/compressor_%s"); + public static final UITexture OVERLAY_SLOT_CRUSHED_ORE = UITexture.fullImage(MODID, "gui/overlay_slot/crushed_ore"); + public static final SteamTexture OVERLAY_SLOT_CRUSHED_ORE_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/crushed_ore_%s"); + public static final UITexture OVERLAY_SLOT_CUTTER_SLICED = + UITexture.fullImage(MODID, "gui/overlay_slot/cutter_sliced"); + public static final UITexture OVERLAY_SLOT_DATA_ORB = UITexture.fullImage(MODID, "gui/overlay_slot/data_orb"); + public static final UITexture OVERLAY_SLOT_DATA_STICK = UITexture.fullImage(MODID, "gui/overlay_slot/data_stick"); + public static final UITexture OVERLAY_SLOT_DUST = UITexture.fullImage(MODID, "gui/overlay_slot/dust"); + public static final SteamTexture OVERLAY_SLOT_DUST_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/dust_%s"); + public static final UITexture OVERLAY_SLOT_EXPLOSIVE = UITexture.fullImage(MODID, "gui/overlay_slot/explosive"); + public static final UITexture OVERLAY_SLOT_EXTRUDER_SHAPE = + UITexture.fullImage(MODID, "gui/overlay_slot/extruder_shape"); + public static final UITexture OVERLAY_SLOT_FURNACE = UITexture.fullImage(MODID, "gui/overlay_slot/furnace"); + public static final SteamTexture OVERLAY_SLOT_FURNACE_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/furnace_%s"); + public static final UITexture OVERLAY_SLOT_GEM = UITexture.fullImage(MODID, "gui/overlay_slot/gem"); + public static final UITexture OVERLAY_SLOT_HAMMER = UITexture.fullImage(MODID, "gui/overlay_slot/hammer"); + public static final SteamTexture OVERLAY_SLOT_HAMMER_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/hammer_%s"); + public static final UITexture OVERLAY_SLOT_HEATER_1 = UITexture.fullImage(MODID, "gui/overlay_slot/heater_1"); + public static final UITexture OVERLAY_SLOT_HEATER_2 = UITexture.fullImage(MODID, "gui/overlay_slot/heater_2"); + public static final UITexture OVERLAY_SLOT_IMPLOSION = UITexture.fullImage(MODID, "gui/overlay_slot/implosion"); + public static final UITexture OVERLAY_SLOT_IN = UITexture.fullImage(MODID, "gui/overlay_slot/in"); + public static final SteamTexture OVERLAY_SLOT_IN_STEAM = SteamTexture.fullImage(MODID, "gui/overlay_slot/in_%s"); + public static final SteamTexture OVERLAY_SLOT_INGOT_STEAM = + SteamTexture.fullImage(MODID, "gui/overlay_slot/ingot_%s"); + public static final UITexture OVERLAY_SLOT_INT_CIRCUIT = UITexture.fullImage(MODID, "gui/overlay_slot/int_circuit"); + public static final UITexture OVERLAY_SLOT_LENS = UITexture.fullImage(MODID, "gui/overlay_slot/lens"); + public static final UITexture OVERLAY_SLOT_MICROSCOPE = UITexture.fullImage(MODID, "gui/overlay_slot/microscope"); + public static final UITexture OVERLAY_SLOT_MOLD = UITexture.fullImage(MODID, "gui/overlay_slot/mold"); + public static final UITexture OVERLAY_SLOT_MOLECULAR_1 = UITexture.fullImage(MODID, "gui/overlay_slot/molecular_1"); + public static final UITexture OVERLAY_SLOT_MOLECULAR_2 = UITexture.fullImage(MODID, "gui/overlay_slot/molecular_2"); + public static final UITexture OVERLAY_SLOT_MOLECULAR_3 = UITexture.fullImage(MODID, "gui/overlay_slot/molecular_3"); + public static final UITexture OVERLAY_SLOT_OUT = UITexture.fullImage(MODID, "gui/overlay_slot/out"); + public static final SteamTexture OVERLAY_SLOT_OUT_STEAM = SteamTexture.fullImage(MODID, "gui/overlay_slot/out_%s"); + public static final UITexture OVERLAY_SLOT_PAGE_BLANK = UITexture.fullImage(MODID, "gui/overlay_slot/page_blank"); + public static final UITexture OVERLAY_SLOT_PAGE_PRINTED = + UITexture.fullImage(MODID, "gui/overlay_slot/page_printed"); + public static final UITexture OVERLAY_SLOT_PRESS_1 = UITexture.fullImage(MODID, "gui/overlay_slot/press_1"); + public static final UITexture OVERLAY_SLOT_PRESS_2 = UITexture.fullImage(MODID, "gui/overlay_slot/press_2"); + public static final UITexture OVERLAY_SLOT_PRESS_3 = UITexture.fullImage(MODID, "gui/overlay_slot/press_3"); + public static final UITexture OVERLAY_SLOT_RECYCLE = UITexture.fullImage(MODID, "gui/overlay_slot/recycle"); + public static final UITexture OVERLAY_SLOT_ROD_1 = UITexture.fullImage(MODID, "gui/overlay_slot/rod_1"); + public static final UITexture OVERLAY_SLOT_ROD_2 = UITexture.fullImage(MODID, "gui/overlay_slot/rod_2"); + public static final UITexture OVERLAY_SLOT_SLICE_SHAPE = UITexture.fullImage(MODID, "gui/overlay_slot/slice_shape"); + public static final UITexture OVERLAY_SLOT_SLICER_SLICED = + UITexture.fullImage(MODID, "gui/overlay_slot/slicer_sliced"); + public static final UITexture OVERLAY_SLOT_SQUARE = UITexture.fullImage(MODID, "gui/overlay_slot/square"); + public static final UITexture OVERLAY_SLOT_UUA = UITexture.fullImage(MODID, "gui/overlay_slot/uua"); + public static final UITexture OVERLAY_SLOT_UUM = UITexture.fullImage(MODID, "gui/overlay_slot/uum"); + public static final UITexture OVERLAY_SLOT_VIAL_1 = UITexture.fullImage(MODID, "gui/overlay_slot/vial_1"); + public static final UITexture OVERLAY_SLOT_VIAL_2 = UITexture.fullImage(MODID, "gui/overlay_slot/vial_2"); + public static final UITexture OVERLAY_SLOT_WIREMILL = UITexture.fullImage(MODID, "gui/overlay_slot/wiremill"); + public static final UITexture OVERLAY_SLOT_WRENCH = UITexture.fullImage(MODID, "gui/overlay_slot/wrench"); + public static final UITexture[] OVERLAY_SLOTS_NUMBER = IntStream.range(0, 12) + .mapToObj(i -> UITexture.fullImage(MODID, "gui/overlay_slot/number_" + i)) + .collect(Collectors.toList()) + .toArray(new UITexture[0]); + + public static final UITexture PROGRESSBAR_ARROW = UITexture.fullImage(MODID, "gui/progressbar/arrow"); + public static final SteamTexture PROGRESSBAR_ARROW_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/arrow_%s"); + public static final SteamTexture PROGRESSBAR_ARROW_2_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/arrow_2_%s"); + public static final UITexture PROGRESSBAR_ARROW_MULTIPLE = + UITexture.fullImage(MODID, "gui/progressbar/arrow_multiple"); + public static final UITexture PROGRESSBAR_ASSEMBLE = UITexture.fullImage(MODID, "gui/progressbar/assemble"); + public static final UITexture PROGRESSBAR_ASSEMBLY_LINE_1 = + UITexture.fullImage(MODID, "gui/progressbar/assemblyline_1"); + public static final UITexture PROGRESSBAR_ASSEMBLY_LINE_2 = + UITexture.fullImage(MODID, "gui/progressbar/assemblyline_2"); + public static final UITexture PROGRESSBAR_ASSEMBLY_LINE_3 = + UITexture.fullImage(MODID, "gui/progressbar/assemblyline_3"); + public static final UITexture PROGRESSBAR_BATH = UITexture.fullImage(MODID, "gui/progressbar/bath"); + public static final UITexture PROGRESSBAR_BENDING = UITexture.fullImage(MODID, "gui/progressbar/bending"); + public static final SteamTexture PROGRESSBAR_BOILER_EMPTY_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/boiler_empty_%s"); + public static final UITexture PROGRESSBAR_BOILER_HEAT = UITexture.fullImage(MODID, "gui/progressbar/boiler_heat"); + public static final UITexture PROGRESSBAR_BOILER_STEAM = UITexture.fullImage(MODID, "gui/progressbar/boiler_steam"); + public static final UITexture PROGRESSBAR_BOILER_WATER = UITexture.fullImage(MODID, "gui/progressbar/boiler_water"); + public static final UITexture PROGRESSBAR_CANNER = UITexture.fullImage(MODID, "gui/progressbar/canner"); + public static final UITexture PROGRESSBAR_CIRCUIT_ASSEMBLER = + UITexture.fullImage(MODID, "gui/progressbar/circuit_assembler"); + public static final UITexture PROGRESSBAR_COMPRESS = UITexture.fullImage(MODID, "gui/progressbar/compress"); + public static final SteamTexture PROGRESSBAR_COMPRESS_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/compress_%s"); + public static final UITexture PROGRESSBAR_CUT = UITexture.fullImage(MODID, "gui/progressbar/cut"); + public static final UITexture PROGRESSBAR_EXTRACT = UITexture.fullImage(MODID, "gui/progressbar/extract"); + public static final SteamTexture PROGRESSBAR_EXTRACT_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/extract_%s"); + public static final UITexture PROGRESSBAR_EXTRUDE = UITexture.fullImage(MODID, "gui/progressbar/extrude"); + public static final SteamTexture PROGRESSBAR_FUEL_STEAM = SteamTexture.fullImage(MODID, "gui/progressbar/fuel_%s"); + public static final UITexture PROGRESSBAR_HAMMER = UITexture.fullImage(MODID, "gui/progressbar/hammer"); + public static final UITexture PROGRESSBAR_HAMMER_BASE = UITexture.fullImage(MODID, "gui/progressbar/hammer_base"); + public static final SteamTexture PROGRESSBAR_HAMMER_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/hammer_%s"); + public static final SteamTexture PROGRESSBAR_HAMMER_BASE_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/hammer_base_%s"); + public static final UITexture PROGRESSBAR_LATHE = UITexture.fullImage(MODID, "gui/progressbar/lathe"); + public static final UITexture PROGRESSBAR_LATHE_BASE = UITexture.fullImage(MODID, "gui/progressbar/lathe_base"); + public static final UITexture PROGRESSBAR_MACERATE = UITexture.fullImage(MODID, "gui/progressbar/macerate"); + public static final SteamTexture PROGRESSBAR_MACERATE_STEAM = + SteamTexture.fullImage(MODID, "gui/progressbar/macerate_%s"); + public static final UITexture PROGRESSBAR_MAGNET = UITexture.fullImage(MODID, "gui/progressbar/magnet"); + public static final UITexture PROGRESSBAR_MIXER = UITexture.fullImage(MODID, "gui/progressbar/mixer"); + public static final UITexture PROGRESSBAR_RECYCLE = UITexture.fullImage(MODID, "gui/progressbar/recycle"); + public static final UITexture PROGRESSBAR_SIFT = UITexture.fullImage(MODID, "gui/progressbar/sift"); + public static final UITexture PROGRESSBAR_SLICE = UITexture.fullImage(MODID, "gui/progressbar/slice"); + public static final UITexture PROGRESSBAR_STORED_EU = UITexture.fullImage(MODID, "gui/progressbar/stored_eu"); + public static final UITexture PROGRESSBAR_WIREMILL = UITexture.fullImage(MODID, "gui/progressbar/wiremill"); + + public static final UITexture TAB_COVER_NORMAL = UITexture.fullImage(MODID, "gui/tab/cover_normal"); + public static final UITexture TAB_COVER_HIGHLIGHT = UITexture.fullImage(MODID, "gui/tab/cover_highlight"); + public static final UITexture TAB_COVER_DISABLED = UITexture.fullImage(MODID, "gui/tab/cover_disabled"); + public static final SteamTexture TAB_COVER_STEAM_NORMAL = SteamTexture.fullImage(MODID, "gui/tab/cover_%s_normal"); + public static final SteamTexture TAB_COVER_STEAM_HIGHLIGHT = + SteamTexture.fullImage(MODID, "gui/tab/cover_%s_highlight"); + public static final SteamTexture TAB_COVER_STEAM_DISABLED = + SteamTexture.fullImage(MODID, "gui/tab/cover_%s_disabled"); + public static final AdaptableUITexture TAB_TITLE = AdaptableUITexture.of(MODID, "gui/tab/title", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_DARK = + AdaptableUITexture.of(MODID, "gui/tab/title_dark", 28, 28, 4); + public static final SteamTexture TAB_TITLE_STEAM = + SteamTexture.adaptableTexture(MODID, "gui/tab/title_%s", 28, 28, 4); + public static final SteamTexture TAB_TITLE_DARK_STEAM = + SteamTexture.adaptableTexture(MODID, "gui/tab/title_dark_%s", 28, 28, 4); + public static final AdaptableUITexture TAB_TITLE_ANGULAR = + AdaptableUITexture.of(MODID, "gui/tab/title_angular", 28, 28, 4); + public static final SteamTexture TAB_TITLE_ANGULAR_STEAM = + SteamTexture.adaptableTexture(MODID, "gui/tab/title_angular_%s", 28, 28, 4); + + public static final UITexture BUTTON_STANDARD = UITexture.fullImage(MODID, "gui/button/standard"); + public static final UITexture BUTTON_STANDARD_TOGGLE = UITexture.fullImage(MODID, "gui/button/standard_toggle"); + public static final UITexture BUTTON_COVER_NORMAL = UITexture.fullImage(MODID, "gui/button/cover_normal"); + public static final UITexture BUTTON_COVER_NORMAL_HOVERED = + UITexture.fullImage(MODID, "gui/button/cover_normal_hovered"); + public static final UITexture BUTTON_COVER_NORMAL_DISABLED = + UITexture.fullImage(MODID, "gui/button/cover_normal_disabled"); + + public static final UITexture OVERLAY_BUTTON_DISABLE = UITexture.fullImage(MODID, "gui/overlay_button/disable"); + public static final UITexture OVERLAY_BUTTON_REDSTONE_OFF = + UITexture.fullImage(MODID, "gui/overlay_button/redstone_off"); + public static final UITexture OVERLAY_BUTTON_REDSTONE_ON = + UITexture.fullImage(MODID, "gui/overlay_button/redstone_on"); + public static final UITexture OVERLAY_BUTTON_CHECKMARK = UITexture.fullImage(MODID, "gui/overlay_button/checkmark"); + public static final UITexture OVERLAY_BUTTON_CROSS = UITexture.fullImage(MODID, "gui/overlay_button/cross"); + public static final UITexture OVERLAY_BUTTON_WHITELIST = UITexture.fullImage(MODID, "gui/overlay_button/whitelist"); + public static final UITexture OVERLAY_BUTTON_BLACKLIST = UITexture.fullImage(MODID, "gui/overlay_button/blacklist"); + public static final UITexture OVERLAY_BUTTON_PROGRESS = UITexture.fullImage(MODID, "gui/overlay_button/progress"); + public static final UITexture OVERLAY_BUTTON_EXPORT = UITexture.fullImage(MODID, "gui/overlay_button/export"); + public static final UITexture OVERLAY_BUTTON_IMPORT = UITexture.fullImage(MODID, "gui/overlay_button/import"); + public static final UITexture OVERLAY_BUTTON_AUTOOUTPUT_ITEM = + UITexture.fullImage(MODID, "gui/overlay_button/autooutput_item"); + public static final UITexture OVERLAY_BUTTON_AUTOOUTPUT_FLUID = + UITexture.fullImage(MODID, "gui/overlay_button/autooutput_fluid"); + public static final UITexture OVERLAY_BUTTON_ALLOW_INPUT = + UITexture.fullImage(MODID, "gui/overlay_button/allow_input"); + public static final UITexture OVERLAY_BUTTON_BLOCK_INPUT = + UITexture.fullImage(MODID, "gui/overlay_button/block_input"); + public static final UITexture OVERLAY_BUTTON_ARROW_GREEN_UP = + UITexture.fullImage(MODID, "gui/overlay_button/arrow_green_up"); + public static final UITexture OVERLAY_BUTTON_ARROW_GREEN_DOWN = + UITexture.fullImage(MODID, "gui/overlay_button/arrow_green_down"); + public static final UITexture OVERLAY_BUTTON_CYCLIC = UITexture.fullImage(MODID, "gui/overlay_button/cyclic"); + public static final UITexture OVERLAY_BUTTON_EMIT_ENERGY = + UITexture.fullImage(MODID, "gui/overlay_button/emit_energy"); + public static final UITexture OVERLAY_BUTTON_EMIT_REDSTONE = + UITexture.fullImage(MODID, "gui/overlay_button/emit_redstone"); + public static final UITexture OVERLAY_BUTTON_INVERT_REDSTONE = + UITexture.fullImage(MODID, "gui/overlay_button/invert_redstone"); + public static final UITexture OVERLAY_BUTTON_STOCKING_MODE = + UITexture.fullImage(MODID, "gui/overlay_button/stocking_mode"); + public static final UITexture OVERLAY_BUTTON_INVERT_FILTER = + UITexture.fullImage(MODID, "gui/overlay_button/invert_filter"); + public static final UITexture OVERLAY_BUTTON_NBT = UITexture.fullImage(MODID, "gui/overlay_button/nbt"); + public static final UITexture OVERLAY_BUTTON_PRINT = UITexture.fullImage(MODID, "gui/overlay_button/print"); + public static final UITexture OVERLAY_BUTTON_TRANSPOSE = UITexture.fullImage(MODID, "gui/overlay_button/transpose"); + public static final UITexture OVERLAY_BUTTON_BOUNDING_BOX = + UITexture.fullImage(MODID, "gui/overlay_button/bounding_box"); + public static final UITexture OVERLAY_BUTTON_MINUS_SMALL = + UITexture.fullImage(MODID, "gui/overlay_button/minus_small"); + public static final UITexture OVERLAY_BUTTON_MINUS_LARGE = + UITexture.fullImage(MODID, "gui/overlay_button/minus_large"); + public static final UITexture OVERLAY_BUTTON_PLUS_SMALL = + UITexture.fullImage(MODID, "gui/overlay_button/plus_small"); + public static final UITexture OVERLAY_BUTTON_PLUS_LARGE = + UITexture.fullImage(MODID, "gui/overlay_button/plus_large"); + public static final UITexture OVERLAY_BUTTON_GATE_AND = UITexture.fullImage(MODID, "gui/overlay_button/gate_and"); + public static final UITexture OVERLAY_BUTTON_GATE_NAND = UITexture.fullImage(MODID, "gui/overlay_button/gate_nand"); + public static final UITexture OVERLAY_BUTTON_GATE_OR = UITexture.fullImage(MODID, "gui/overlay_button/gate_or"); + public static final UITexture OVERLAY_BUTTON_GATE_NOR = UITexture.fullImage(MODID, "gui/overlay_button/gate_nor"); + public static final UITexture OVERLAY_BUTTON_ANALOG = UITexture.fullImage(MODID, "gui/overlay_button/analog"); + public static final UITexture OVERLAY_BUTTON_LOCK = UITexture.fullImage(MODID, "gui/overlay_button/lock"); + public static final UITexture OVERLAY_BUTTON_INPUT_FROM_OUTPUT_SIDE = + UITexture.fullImage(MODID, "gui/overlay_button/input_from_output_side"); + public static final UITexture OVERLAY_BUTTON_VOID_EXCESS = + UITexture.fullImage(MODID, "gui/overlay_button/void_excess"); + public static final UITexture OVERLAY_BUTTON_VOID_ALL = UITexture.fullImage(MODID, "gui/overlay_button/void_all"); + public static final UITexture OVERLAY_BUTTON_NEI = UITexture.fullImage(MODID, "gui/overlay_button/nei"); + + /** + * Can adjust size as needed. + */ + public static final AdaptableUITexture PICTURE_SCREEN_BLACK = + AdaptableUITexture.of(MODID, "gui/picture/screen_black", 16, 16, 2); + + public static final UITexture PICTURE_GT_LOGO_17x17_TRANSPARENT = + UITexture.fullImage(MODID, "gui/picture/gt_logo_17x17_transparent"); + public static final UITexture PICTURE_GT_LOGO_17x17_TRANSPARENT_GRAY = + UITexture.fullImage(MODID, "gui/picture/gt_logo_17x17_transparent_gray"); + public static final SteamTexture PICTURE_GT_LOGO_17x17_TRANSPARENT_STEAM = + SteamTexture.fullImage(MODID, "gui/picture/gt_logo_17x17_transparent_%s"); + public static final UITexture PICTURE_GT_LOGO_18x18 = UITexture.fullImage(MODID, "gui/picture/gt_logo_18x18"); + public static final UITexture PICTURE_GT_LOGO_19x19 = UITexture.fullImage(MODID, "gui/picture/gt_logo_19x19"); + public static final UITexture PICTURE_INFORMATION = UITexture.fullImage(MODID, "gui/picture/information"); + public static final UITexture PICTURE_STALLED_ELECTRICITY = + UITexture.fullImage(MODID, "gui/picture/stalled_electricity"); + public static final UITexture PICTURE_STALLED_STEAM = UITexture.fullImage(MODID, "gui/picture/stalled_steam"); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_22_RED = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_22_red", + 87, + 22, + fromRight ? 87 - width : 0, + 0, + fromRight ? 87 : width, + 22); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_22_BLUE = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_22_blue", + 87, + 22, + fromRight ? 87 - width : 0, + 0, + fromRight ? 87 : width, + 22); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_22_WHITE = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_22_white", + 87, + 22, + fromRight ? 87 - width : 0, + 0, + fromRight ? 87 : width, + 22); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_24_RED = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_24_red", + 69, + 24, + fromRight ? 69 - width : 0, + 0, + fromRight ? 69 : width, + 24); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_24_BLUE = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_24_blue", + 69, + 24, + fromRight ? 69 - width : 0, + 0, + fromRight ? 69 : width, + 24); + public static final BiFunction<Integer, Boolean, UITexture> PICTURE_ARROW_24_WHITE = + (width, fromRight) -> UITexture.partly( + MODID, + "gui/picture/arrow_24_white", + 69, + 24, + fromRight ? 69 - width : 0, + 0, + fromRight ? 69 : width, + 24); + public static final UITexture PICTURE_FLUID_WINDOW = UITexture.fullImage(MODID, "gui/picture/fluid_window"); + public static final UITexture PICTURE_FLUID_TANK = UITexture.fullImage(MODID, "gui/picture/fluid_tank"); + public static final UITexture PICTURE_SLOTS_HOLO_3BY3 = UITexture.fullImage(MODID, "gui/picture/slots_holo_3by3"); + public static final UITexture PICTURE_ARROW_DOUBLE = UITexture.fullImage(MODID, "gui/picture/arrow_double"); + public static final UITexture PICTURE_SUPER_BUFFER = UITexture.fullImage(MODID, "gui/picture/super_buffer"); + public static final UITexture PICTURE_SQUARE_LIGHT_GRAY = + UITexture.fullImage(MODID, "gui/picture/square_light_gray"); + public static final UITexture PICTURE_GAUGE = UITexture.fullImage(MODID, "gui/picture/gauge"); +} diff --git a/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java b/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java new file mode 100644 index 0000000000..13d7eadfee --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java @@ -0,0 +1,150 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import gregtech.api.enums.SteamVariant; +import java.util.function.Function; + +/** + * Set of textures that is commonly used for GUI but can vary depending on "style" of machines, + * e.g. bronze steam or steel steam. + * <br> This has builder pattern; Textures you didn't specify will fall back to default ones. + */ +public class GUITextureSet { + private UITexture mainBackground; + private UITexture itemSlot; + private UITexture fluidSlot; + private UITexture coverTabNormal; + private UITexture coverTabHighlight; + private UITexture coverTabDisabled; + private UITexture coverTabNormalFlipped; + private UITexture coverTabHighlightFlipped; + private UITexture coverTabDisabledFlipped; + private AdaptableUITexture titleTabNormal; + private AdaptableUITexture titleTabDark; + private AdaptableUITexture titleTabAngular; + private UITexture gregtechLogo; + + public static final GUITextureSet DEFAULT = new GUITextureSet() + .setMainBackground(GT_UITextures.BACKGROUND_SINGLEBLOCK_DEFAULT) + .setItemSlot(ModularUITextures.ITEM_SLOT) + .setFluidSlot(ModularUITextures.FLUID_SLOT) + .setCoverTab( + GT_UITextures.TAB_COVER_NORMAL, GT_UITextures.TAB_COVER_HIGHLIGHT, GT_UITextures.TAB_COVER_DISABLED) + .setTitleTab(GT_UITextures.TAB_TITLE, GT_UITextures.TAB_TITLE_DARK, GT_UITextures.TAB_TITLE_ANGULAR) + .setGregTechLogo(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT); + + public static final Function<SteamVariant, GUITextureSet> STEAM = steamVariant -> new GUITextureSet() + .setMainBackground(GT_UITextures.BACKGROUND_STEAM.get(steamVariant)) + .setItemSlot(GT_UITextures.SLOT_ITEM_STEAM.get(steamVariant)) + .setCoverTab( + GT_UITextures.TAB_COVER_STEAM_NORMAL.get(steamVariant), + GT_UITextures.TAB_COVER_STEAM_HIGHLIGHT.get(steamVariant), + GT_UITextures.TAB_COVER_STEAM_DISABLED.get(steamVariant)) + .setTitleTab( + GT_UITextures.TAB_TITLE_STEAM.getAdaptable(steamVariant), + GT_UITextures.TAB_TITLE_DARK_STEAM.getAdaptable(steamVariant), + GT_UITextures.TAB_TITLE_ANGULAR_STEAM.getAdaptable(steamVariant)) + .setGregTechLogo(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT_STEAM.get(steamVariant)); + + public GUITextureSet() {} + + // region setters + + public GUITextureSet setMainBackground(UITexture mainBackground) { + this.mainBackground = mainBackground; + return this; + } + + public GUITextureSet setItemSlot(UITexture itemSlot) { + this.itemSlot = itemSlot; + return this; + } + + public GUITextureSet setFluidSlot(UITexture fluidSlot) { + this.fluidSlot = fluidSlot; + return this; + } + + public GUITextureSet setCoverTab(UITexture coverNormal, UITexture coverHighlight, UITexture coverDisabled) { + this.coverTabNormal = coverNormal; + this.coverTabHighlight = coverHighlight; + this.coverTabDisabled = coverDisabled; + this.coverTabNormalFlipped = coverNormal.getFlipped(true, false); + this.coverTabHighlightFlipped = coverHighlight.getFlipped(true, false); + this.coverTabDisabledFlipped = coverDisabled.getFlipped(true, false); + return this; + } + + public GUITextureSet setTitleTab( + AdaptableUITexture titleNormal, AdaptableUITexture titleDark, AdaptableUITexture titleTabAngular) { + this.titleTabNormal = titleNormal; + this.titleTabDark = titleDark; + this.titleTabAngular = titleTabAngular; + return this; + } + + public GUITextureSet setGregTechLogo(UITexture gregtechLogo) { + this.gregtechLogo = gregtechLogo; + return this; + } + + // endregion + + // region getters + + public UITexture getMainBackground() { + return mainBackground != null ? mainBackground : DEFAULT.mainBackground; + } + + public UITexture getItemSlot() { + return itemSlot != null ? itemSlot : DEFAULT.itemSlot; + } + + public UITexture getFluidSlot() { + return fluidSlot != null ? fluidSlot : DEFAULT.fluidSlot; + } + + public UITexture getCoverTabNormal() { + return coverTabNormal != null ? coverTabNormal : DEFAULT.coverTabNormal; + } + + public UITexture getCoverTabHighlight() { + return coverTabHighlight != null ? coverTabHighlight : DEFAULT.coverTabHighlight; + } + + public UITexture getCoverTabDisabled() { + return coverTabDisabled != null ? coverTabDisabled : DEFAULT.coverTabDisabled; + } + + public UITexture getCoverTabNormalFlipped() { + return coverTabNormalFlipped != null ? coverTabNormalFlipped : DEFAULT.coverTabNormalFlipped; + } + + public UITexture getCoverTabHighlightFlipped() { + return coverTabHighlightFlipped != null ? coverTabHighlightFlipped : DEFAULT.coverTabHighlightFlipped; + } + + public UITexture getCoverTabDisabledFlipped() { + return coverTabDisabledFlipped != null ? coverTabDisabledFlipped : DEFAULT.coverTabDisabledFlipped; + } + + public AdaptableUITexture getTitleTabNormal() { + return titleTabNormal != null ? titleTabNormal : DEFAULT.titleTabNormal; + } + + public AdaptableUITexture getTitleTabDark() { + return titleTabDark != null ? titleTabDark : DEFAULT.titleTabDark; + } + + public AdaptableUITexture getTitleTabAngular() { + return titleTabAngular != null ? titleTabAngular : DEFAULT.titleTabAngular; + } + + public UITexture getGregTechLogo() { + return gregtechLogo != null ? gregtechLogo : DEFAULT.gregtechLogo; + } + + // endregion +} diff --git a/src/main/java/gregtech/api/gui/modularui/IDataFollowerWidget.java b/src/main/java/gregtech/api/gui/modularui/IDataFollowerWidget.java new file mode 100644 index 0000000000..40ebcea0f4 --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/IDataFollowerWidget.java @@ -0,0 +1,48 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.widget.Widget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.DataControllerWidget; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * Widget whose state is controlled by specific data. + * Data can be anything, e.g. {@link ISerializableObject} or machine recipe mode. + * <br> No widgets implementing this interface should not sync; + * Instead, {@link DataControllerWidget} will sync data, either when this widget triggers update on client + * or data update is detected on server. + * @param <T> Data type stored in the parent widget + * @param <U> State type stored in this widget + * @see DataControllerWidget + */ +@SuppressWarnings("UnusedReturnValue") +public interface IDataFollowerWidget<T, U> { + + /** + * Sets function to get widget state from provided data. This function will be called when client receives data + * from server and {@link DataControllerWidget} updates all children, including this widget. + */ + Widget setDataToStateGetter(Function<T, U> dataToStateGetter); + + /** + * Sets setter called when this widget gets action from player. + * Basically the same functionality with widgets that have getter/setter. + */ + Widget setStateSetter(Consumer<U> setter); + + /** + * Updates state of this widget with provided data. + * On server {@link DataControllerWidget} won't propagate data update to this widget, + * so this method is client-only. + */ + @SideOnly(Side.CLIENT) + void updateState(T data); + + /** + * Called on {@link Widget#onPostInit}. + */ + default void onPostInit() {} +} diff --git a/src/main/java/gregtech/api/gui/modularui/SteamTexture.java b/src/main/java/gregtech/api/gui/modularui/SteamTexture.java new file mode 100644 index 0000000000..9e52c0f874 --- /dev/null +++ b/src/main/java/gregtech/api/gui/modularui/SteamTexture.java @@ -0,0 +1,74 @@ +package gregtech.api.gui.modularui; + +import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import gregtech.api.enums.SteamVariant; + +/** + * Wrapper for {@link UITexture}s used to + * ease in choosing between Bronze, Steel and Primitive textures. + */ +public class SteamTexture { + + private final UITexture bronzeTexture; + private final UITexture steelTexture; + private final UITexture primitiveTexture; + + private SteamTexture(UITexture bronzeTexture, UITexture steelTexture, UITexture primitiveTexture) { + this.bronzeTexture = bronzeTexture; + this.steelTexture = steelTexture; + this.primitiveTexture = primitiveTexture; + } + + public static SteamTexture fullImage(String mod, String location) { + return new SteamTexture( + UITexture.fullImage(mod, String.format(location, SteamVariant.BRONZE)), + UITexture.fullImage(mod, String.format(location, SteamVariant.STEEL)), + UITexture.fullImage(mod, String.format(location, SteamVariant.PRIMITIVE))); + } + + public static SteamTexture adaptableTexture( + String mod, String location, int imageWidth, int imageHeight, int borderWidthPixel) { + return new SteamTexture( + AdaptableUITexture.of( + mod, String.format(location, SteamVariant.BRONZE), imageWidth, imageHeight, borderWidthPixel), + AdaptableUITexture.of( + mod, String.format(location, SteamVariant.STEEL), imageWidth, imageHeight, borderWidthPixel), + AdaptableUITexture.of( + mod, + String.format(location, SteamVariant.PRIMITIVE), + imageWidth, + imageHeight, + borderWidthPixel)); + } + + public UITexture get(SteamVariant variant) { + switch (variant) { + case BRONZE: + return bronzeTexture; + case STEEL: + return steelTexture; + case PRIMITIVE: + return primitiveTexture; + default: + return null; + } + } + + public AdaptableUITexture getAdaptable(SteamVariant variant) { + switch (variant) { + case BRONZE: + return (AdaptableUITexture) bronzeTexture; + case STEEL: + return (AdaptableUITexture) steelTexture; + case PRIMITIVE: + return (AdaptableUITexture) primitiveTexture; + default: + return null; + } + } + + public UITexture get(boolean isHighPressure) { + return isHighPressure ? steelTexture : bronzeTexture; + } +} diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IConfigurationCircuitSupport.java b/src/main/java/gregtech/api/interfaces/IConfigurationCircuitSupport.java index 59a70b450d..b2d32b2fc4 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IConfigurationCircuitSupport.java +++ b/src/main/java/gregtech/api/interfaces/IConfigurationCircuitSupport.java @@ -1,11 +1,11 @@ -package gregtech.api.interfaces.metatileentity; +package gregtech.api.interfaces; import gregtech.api.GregTech_API; import java.util.List; import net.minecraft.item.ItemStack; /** - * Implement this interface if your metatileentity supports configuration circuits + * Implement this interface if your tileentity (or metatileentity) supports configuration circuits * to resolve recipe conflicts. */ public interface IConfigurationCircuitSupport { diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java index 29b0a56a89..59d048e618 100644 --- a/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntity.java @@ -1,14 +1,18 @@ package gregtech.api.interfaces.metatileentity; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.Dyes; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IGetGUITextureSet; import gregtech.api.interfaces.tileentity.IGearEnergyTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IGregtechWailaProvider; import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_Util; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -38,7 +42,8 @@ public interface IMetaTileEntity IFluidHandler, IGearEnergyTileEntity, IMachineBlockUpdateable, - IGregtechWailaProvider { + IGregtechWailaProvider, + IGetGUITextureSet { /** * This determines the BaseMetaTileEntity belonging to this MetaTileEntity by using the Meta ID of the Block itself. * <p/> @@ -193,13 +198,28 @@ public interface IMetaTileEntity /** * @return the Server Side Container + * @deprecated Use ModularUI */ - Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity); + @Deprecated + default Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + throw new UnsupportedOperationException(); + } /** * @return the Client Side GUI Container + * @deprecated Use ModularUI + */ + @Deprecated + default Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + throw new UnsupportedOperationException(); + } + + /** + * For back compatibility, you need to override this if this MetaTileEntity uses ModularUI. */ - Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity); + default boolean useModularUI() { + return false; + } /** * From new ISidedInventory @@ -406,6 +426,17 @@ public interface IMetaTileEntity void onColorChangeClient(byte aColor); + /** + * @return Actual color shown on GUI + */ + default int getGUIColorization() { + if (getBaseMetaTileEntity() != null) { + return getBaseMetaTileEntity().getGUIColorization(); + } else { + return GT_Util.getRGBInt(Dyes.MACHINE_METAL.getRGBA()); + } + } + int getLightOpacity(); boolean allowGeneralRedstoneOutput(); @@ -461,4 +492,31 @@ public interface IMetaTileEntity default void onRandomDisplayTick(IGregTechTileEntity aBaseMetaTileEntity) { /* do nothing */ } + + default int getGUIWidth() { + return 176; + } + + default int getGUIHeight() { + return 166; + } + + /* + * ModularUI Support + */ + default ItemStackHandler getInventoryHandler() { + return null; + } + + default String getLocalName() { + return "Unknown"; + } + + default boolean doesBindPlayerInventory() { + return true; + } + + default int getTextColorOrDefault(String textType, int defaultColor) { + return defaultColor; + } } diff --git a/src/main/java/gregtech/api/interfaces/modularui/IAddGregtechLogo.java b/src/main/java/gregtech/api/interfaces/modularui/IAddGregtechLogo.java new file mode 100644 index 0000000000..d90d310dc8 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IAddGregtechLogo.java @@ -0,0 +1,7 @@ +package gregtech.api.interfaces.modularui; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; + +public interface IAddGregtechLogo { + default void addGregTechLogo(ModularWindow.Builder builder) {} +} diff --git a/src/main/java/gregtech/api/interfaces/modularui/IAddInventorySlots.java b/src/main/java/gregtech/api/interfaces/modularui/IAddInventorySlots.java new file mode 100644 index 0000000000..70e33aa2c8 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IAddInventorySlots.java @@ -0,0 +1,14 @@ +package gregtech.api.interfaces.modularui; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; + +public interface IAddInventorySlots { + default void add1by1Slot(ModularWindow.Builder builder, IDrawable... background) {} + + default void add2by2Slots(ModularWindow.Builder builder, IDrawable... background) {} + + default void add3by3Slots(ModularWindow.Builder builder, IDrawable... background) {} + + default void add4by4Slots(ModularWindow.Builder builder, IDrawable... background) {} +} diff --git a/src/main/java/gregtech/api/interfaces/modularui/IAddUIWidgets.java b/src/main/java/gregtech/api/interfaces/modularui/IAddUIWidgets.java new file mode 100644 index 0000000000..7b70fd724c --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IAddUIWidgets.java @@ -0,0 +1,8 @@ +package gregtech.api.interfaces.modularui; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +public interface IAddUIWidgets { + default void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {} +} diff --git a/src/main/java/gregtech/api/interfaces/modularui/IBindPlayerInventoryUI.java b/src/main/java/gregtech/api/interfaces/modularui/IBindPlayerInventoryUI.java new file mode 100644 index 0000000000..426a24ad38 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IBindPlayerInventoryUI.java @@ -0,0 +1,9 @@ +package gregtech.api.interfaces.modularui; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; + +public interface IBindPlayerInventoryUI { + + void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext); +} diff --git a/src/main/java/gregtech/api/interfaces/modularui/IGetGUITextureSet.java b/src/main/java/gregtech/api/interfaces/modularui/IGetGUITextureSet.java new file mode 100644 index 0000000000..409523b008 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IGetGUITextureSet.java @@ -0,0 +1,9 @@ +package gregtech.api.interfaces.modularui; + +import gregtech.api.gui.modularui.GUITextureSet; + +public interface IGetGUITextureSet { + default GUITextureSet getGUITextureSet() { + return null; + } +} diff --git a/src/main/java/gregtech/api/interfaces/modularui/IGetTitleColor.java b/src/main/java/gregtech/api/interfaces/modularui/IGetTitleColor.java new file mode 100644 index 0000000000..a1f79d1568 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/modularui/IGetTitleColor.java @@ -0,0 +1,10 @@ +package gregtech.api.interfaces.modularui; + +import gregtech.api.enums.Dyes; +import gregtech.api.util.GT_Util; + +public interface IGetTitleColor { + default int getTitleColor() { + return GT_Util.getRGBaInt(Dyes.dyeWhite.getRGBA()); + } +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java index ddbb550dfc..3bcf441128 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IColoredTileEntity.java @@ -1,5 +1,8 @@ package gregtech.api.interfaces.tileentity; +import gregtech.api.enums.Dyes; +import gregtech.api.util.GT_Util; + public interface IColoredTileEntity { /** * @return 0 - 15 are Colors, while -1 means uncolored @@ -12,4 +15,12 @@ public interface IColoredTileEntity { * @param aColor the Color you want to set it to. -1 for reset. */ byte setColorization(byte aColor); + + /** + * @return Actual color shown on GUI + */ + default int getGUIColorization() { + return GT_Util.getRGBInt( + (getColorization() != -1 ? Dyes.get(getColorization()) : Dyes.MACHINE_METAL).getRGBA()); + } } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java index ad2af44e9e..b389c8be6c 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IGregTechTileEntity.java @@ -4,6 +4,8 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.interfaces.IDescribable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddInventorySlots; +import gregtech.api.interfaces.modularui.IGetGUITextureSet; import gregtech.common.blocks.GT_Block_Machines; import java.util.ArrayList; import java.util.List; @@ -34,7 +36,9 @@ public interface IGregTechTileEntity IDigitalChest, IDescribable, IMachineBlockUpdateable, - IGregtechWailaProvider { + IGregtechWailaProvider, + IGetGUITextureSet, + IAddInventorySlots { /** * gets the Error displayed on the GUI */ diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java index 2464816045..7f31d17d11 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IHasWorldObjectAndCoords.java @@ -164,11 +164,19 @@ public interface IHasWorldObjectAndCoords { /** * Opens the GUI with this ID of this MetaTileEntity + * @deprecated Use ModularUI */ - boolean openGUI(EntityPlayer aPlayer, int aID); + @Deprecated + default boolean openGUI(EntityPlayer aPlayer, int aID) { + return false; + } /** * Opens the GUI with the ID = 0 of this TileEntity + * @deprecated Use ModularUI */ - boolean openGUI(EntityPlayer aPlayer); + @Deprecated + default boolean openGUI(EntityPlayer aPlayer) { + return false; + } } diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index ebf0672815..395c73570c 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -1671,6 +1671,7 @@ public class BaseMetaTileEntity extends CommonMetaTileEntity GT_Log.err.println( "Encountered Exception while rightclicking TileEntity, the Game should've crashed now, but I prevented that. Please report immediately to GregTech Intergalactical!!!"); e.printStackTrace(GT_Log.err); + e.printStackTrace(); } return false; diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 1f6fb0c68d..23a247468a 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -7,25 +7,61 @@ import static gregtech.api.enums.GT_Values.NW; import static gregtech.api.enums.GT_Values.SIDE_DOWN; import static gregtech.api.enums.GT_Values.SIDE_UP; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.GT_Mod; +import gregtech.api.enums.Dyes; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddInventorySlots; +import gregtech.api.interfaces.modularui.IGetGUITextureSet; import gregtech.api.interfaces.tileentity.IGTEnet; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.api.interfaces.tileentity.IIC2Enet; import gregtech.api.net.GT_Packet_Block_Event; +import gregtech.api.net.GT_Packet_SetConfigurationCircuit; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; import ic2.api.energy.event.EnergyTileLoadEvent; import ic2.api.energy.event.EnergyTileUnloadEvent; import java.util.Arrays; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.Chunk; @@ -38,7 +74,14 @@ import net.minecraftforge.fluids.IFluidHandler; * <p/> * Basically everything a TileEntity should have. */ -public abstract class BaseTileEntity extends TileEntity implements IHasWorldObjectAndCoords, IIC2Enet, IGTEnet { +public abstract class BaseTileEntity extends TileEntity + implements IHasWorldObjectAndCoords, + IIC2Enet, + IGTEnet, + ITileWithModularUI, + IAddGregtechLogo, + IGetGUITextureSet, + IAddInventorySlots { protected boolean mInventoryChanged = false; /** @@ -138,11 +181,13 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje } @Override + @Deprecated public final boolean openGUI(EntityPlayer aPlayer) { return openGUI(aPlayer, 0); } @Override + @Deprecated public final boolean openGUI(EntityPlayer aPlayer, int aID) { if (aPlayer == null) return false; aPlayer.openGui(GT, aID, worldObj, xCoord, yCoord, zCoord); @@ -536,6 +581,37 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje return GT_Utility.trans(aKey, aEnglish); } + protected Supplier<Boolean> getValidator() { + return () -> !this.isDead(); + } + + public boolean useModularUI() { + return false; + } + + @Override + public ModularWindow createWindow(UIBuildContext buildContext) { + if (!useModularUI()) return null; + + buildContext.setValidator(getValidator()); + final ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight()); + builder.setBackground(getGUITextureSet().getMainBackground()); + builder.setGuiTint(getGUIColorization()); + if (doesBindPlayerInventory()) { + bindPlayerInventoryUI(builder, buildContext); + } + addUIWidgets(builder, buildContext); + addTitleToUI(builder); + addCoverTabs(builder, buildContext); + final IConfigurationCircuitSupport csc = getConfigurationCircuitSupport(); + if (csc != null && csc.allowSelectCircuit()) { + addConfigurationCircuitSlot(builder); + } else { + addGregTechLogo(builder); + } + return builder.build(); + } + /* * IC2 Energy Compat */ @@ -571,4 +647,338 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(ic2EnergySink)); } } + + // === GUI stuff === + + public ItemStackHandler getInventoryHandler() { + return null; + } + + protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + + // Tooltip localization keys + public static final String BATTERY_SLOT_TOOLTIP = "GT5U.machines.battery_slot.tooltip", + BATTERY_SLOT_TOOLTIP_ALT = "GT5U.machines.battery_slot.tooltip.alternative", + UNUSED_SLOT_TOOLTIP = "GT5U.machines.unused_slot.tooltip", + SPECIAL_SLOT_TOOLTIP = "GT5U.machines.special_slot.tooltip", + FLUID_INPUT_TOOLTIP = "GT5U.machines.fluid_input_slot.tooltip", + FLUID_OUTPUT_TOOLTIP = "GT5U.machines.fluid_output_slot.tooltip", + STALLED_STUTTERING_TOOLTIP = "GT5U.machines.stalled_stuttering.tooltip", + STALLED_VENT_TOOLTIP = "GT5U.machines.stalled_vent.tooltip", + FLUID_TRANSFER_TOOLTIP = "GT5U.machines.fluid_transfer.tooltip", + ITEM_TRANSFER_TOOLTIP = "GT5U.machines.item_transfer.tooltip", + POWER_SOURCE_KEY = "GT5U.machines.powersource.", + NEI_TRANSFER_STEAM_TOOLTIP = "GT5U.machines.nei_transfer.steam.tooltip", + NEI_TRANSFER_VOLTAGE_TOOLTIP = "GT5U.machines.nei_transfer.voltage.tooltip"; + + public static final int TOOLTIP_DELAY = 5; + + /** + * Override this to add {@link com.gtnewhorizons.modularui.api.widget.Widget}s for your UI. + */ + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {} + + public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.bindPlayerInventory( + buildContext.getPlayer(), 7, getGUITextureSet().getItemSlot()); + } + + public String getLocalName() { + return "Unknown"; + } + + protected void addTitleToUI(ModularWindow.Builder builder) { + addTitleToUI(builder, getLocalName()); + } + + protected void addTitleToUI(ModularWindow.Builder builder, String title) { + if (GT_Mod.gregtechproxy.mTitleTabStyle == 2) { + addTitleItemIconStyle(builder, title); + } else { + addTitleTextStyle(builder, title); + } + } + + protected void addTitleTextStyle(ModularWindow.Builder builder, String title) { + final int TAB_PADDING = 3; + final int TITLE_PADDING = 2; + int titleWidth = 0, titleHeight = 0; + if (NetworkUtils.isClient()) { + final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + //noinspection unchecked + final List<String> titleLines = + fontRenderer.listFormattedStringToWidth(title, getGUIWidth() - (TAB_PADDING + TITLE_PADDING) * 2); + titleWidth = titleLines.size() > 1 + ? getGUIWidth() - (TAB_PADDING + TITLE_PADDING) * 2 + : fontRenderer.getStringWidth(title); + //noinspection PointlessArithmeticExpression + titleHeight = titleLines.size() * fontRenderer.FONT_HEIGHT + (titleLines.size() - 1) * 1; + } + + final DrawableWidget tab = new DrawableWidget(); + final TextWidget text = new TextWidget(title) + .setDefaultColor(getTitleColor()) + .setTextAlignment(Alignment.CenterLeft) + .setMaxWidth(titleWidth); + if (GT_Mod.gregtechproxy.mTitleTabStyle == 1) { + tab.setDrawable(getGUITextureSet().getTitleTabAngular()) + .setPos(0, -(titleHeight + TAB_PADDING) + 1) + .setSize(getGUIWidth(), titleHeight + TAB_PADDING * 2); + text.setPos(TAB_PADDING + TITLE_PADDING, -titleHeight + TAB_PADDING); + } else { + tab.setDrawable(getGUITextureSet().getTitleTabDark()) + .setPos(0, -(titleHeight + TAB_PADDING * 2) + 1) + .setSize(titleWidth + (TAB_PADDING + TITLE_PADDING) * 2, titleHeight + TAB_PADDING * 2 - 1); + text.setPos(TAB_PADDING + TITLE_PADDING, -titleHeight); + } + builder.widget(tab).widget(text); + } + + protected void addTitleItemIconStyle(ModularWindow.Builder builder, String title) { + builder.widget(new MultiChildWidget() + .addChild(new DrawableWidget() + .setDrawable(getGUITextureSet().getTitleTabNormal()) + .setPos(0, 0) + .setSize(24, 24)) + .addChild(new ItemDrawable(getStackForm(1)).asWidget().setPos(4, 4)) + .addTooltip(title) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(0, -24 + 3)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.DEFAULT; + } + + protected int getTitleColor() { + return COLOR_TITLE.get(); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(152, 63)); + } + + protected int getGUIWidth() { + return 176; + } + + protected int getGUIHeight() { + return 166; + } + + protected boolean doesBindPlayerInventory() { + return true; + } + + @Override + public void add1by1Slot(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 1) + .startFromSlot(0) + .endAtSlot(0) + .background(background) + .build() + .setPos(79, 34)); + } + + @Override + public void add2by2Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(0) + .endAtSlot(3) + .background(background) + .build() + .setPos(70, 25)); + } + + @Override + public void add3by3Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .background(background) + .build() + .setPos(61, 16)); + } + + @Override + public void add4by4Slots(ModularWindow.Builder builder, IDrawable... background) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (background.length == 0) { + background = new IDrawable[] {getGUITextureSet().getItemSlot()}; + } + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .background(background) + .build() + .setPos(52, 7)); + } + + public void addCoverTabs(ModularWindow.Builder builder, UIBuildContext buildContext) { + /* Do nothing */ + } + + public IConfigurationCircuitSupport getConfigurationCircuitSupport() { + if (!(this instanceof IConfigurationCircuitSupport)) return null; + return (IConfigurationCircuitSupport) this; + } + + protected void addConfigurationCircuitSlot(ModularWindow.Builder builder) { + final ItemStackHandler inventoryHandler = getInventoryHandler(); + if (inventoryHandler == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + final AtomicBoolean dialogOpened = new AtomicBoolean(false); + builder.widget( + new SlotWidget(new BaseSlot(inventoryHandler, ccs.getCircuitSlot(), true)) { + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + final ItemStack newCircuit; + if (clickData.shift) { + if (clickData.mouseButton == 0) { + if (NetworkUtils.isClient() && !dialogOpened.get()) { + openSelectCircuitDialog(getContext(), dialogOpened); + } + return; + } else { + newCircuit = null; + } + } else { + final List<ItemStack> tCircuits = ccs.getConfigurationCircuits(); + final int index = GT_Utility.findMatchingStackInList(tCircuits, cursorStack); + if (index < 0) { + int curIndex = GT_Utility.findMatchingStackInList( + tCircuits, inv.getStackInSlot(ccs.getCircuitSlot())) + + 1; + if (clickData.mouseButton == 0) { + curIndex += 1; + } else { + curIndex -= 1; + } + curIndex = Math.floorMod(curIndex, tCircuits.size() + 1) - 1; + newCircuit = curIndex < 0 ? null : tCircuits.get(curIndex); + } else { + // set to whatever it is + newCircuit = tCircuits.get(index); + } + } + inv.setInventorySlotContents(ccs.getCircuitSlot(), newCircuit); + } + + @Override + protected void phantomScroll(int direction) { + phantomClick(new ClickData(direction > 0 ? 1 : 0, false, false, false)); + } + + @Override + public List<String> getExtraTooltip() { + return Arrays.asList( + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.1")), + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.2")), + EnumChatFormatting.DARK_GRAY + + EnumChatFormatting.getTextWithoutFormattingCodes( + StatCollector.translateToLocal( + "GT5U.machines.select_circuit.tooltip.3"))); + } + }.setOverwriteItemStackTooltip(list -> { + list.removeIf(line -> + line.contains(StatCollector.translateToLocal("gt.integrated_circuit.tooltip.0")) + || line.contains( + StatCollector.translateToLocal("gt.integrated_circuit.tooltip.1"))); + return list; + }) + .disableShiftInsert() + .setHandlePhantomActionClient(true) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_INT_CIRCUIT) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.select_circuit.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(ccs.getCircuitSlotX() - 1, ccs.getCircuitSlotY() - 1)); + } + + protected void openSelectCircuitDialog(ModularUIContext uiContext, AtomicBoolean dialogOpened) { + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + final List<ItemStack> circuits = ccs.getConfigurationCircuits(); + uiContext.openClientWindow(player -> new SelectItemUIFactory( + StatCollector.translateToLocal("GT5U.machines.select_circuit"), + getStackForm(0), + this::onCircuitSelected, + circuits, + GT_Utility.findMatchingStackInList(circuits, inv.getStackInSlot(ccs.getCircuitSlot()))) + .setAnotherWindow(true, dialogOpened) + .setGuiTint(getGUIColorization()) + .setCurrentGetter(() -> inv.getStackInSlot(ccs.getCircuitSlot())) + .createWindow(new UIBuildContext(player))); + } + + protected void onCircuitSelected(ItemStack selected) { + final IConfigurationCircuitSupport ccs = getConfigurationCircuitSupport(); + if (ccs == null) return; + + if (!(this instanceof IInventory)) return; + final IInventory inv = (IInventory) this; + + GT_Values.NW.sendToServer(new GT_Packet_SetConfigurationCircuit(this, selected)); + // we will not do any validation on client side + // it doesn't get to actually decide what inventory contains anyway + inv.setInventorySlotContents(ccs.getCircuitSlot(), selected); + } + + protected int getTextColorOrDefault(String textType, int defaultColor) { + return defaultColor; + } + + protected Supplier<Integer> COLOR_TITLE = () -> getTextColorOrDefault("title", 0x404040); + protected Supplier<Integer> COLOR_TITLE_WHITE = () -> getTextColorOrDefault("title_white", 0xfafaff); + protected Supplier<Integer> COLOR_TEXT_WHITE = () -> getTextColorOrDefault("text_white", 0xfafaff); + protected Supplier<Integer> COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x404040); + protected Supplier<Integer> COLOR_TEXT_RED = () -> getTextColorOrDefault("text_red", 0xff0000); + + public int getGUIColorization() { + return GT_Util.getRGBaInt(Dyes.dyeWhite.getRGBA()); + } + + public ItemStack getStackForm(long aAmount) { + return null; + } } diff --git a/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java index bf835b51bb..e2860d6292 100644 --- a/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CommonMetaTileEntity.java @@ -2,9 +2,18 @@ package gregtech.api.metatileentity; import static gregtech.GT_Mod.GT_FML_LOGGER; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.modularui.IBindPlayerInventoryUI; +import gregtech.api.interfaces.modularui.IGetTitleColor; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_Log; @@ -167,4 +176,123 @@ public abstract class CommonMetaTileEntity extends CoverableTileEntity implement final IMetaTileEntity meta = getMetaTileEntity(); return meta != null && meta.shouldJoinIc2Enet(); } + + /* + * Modular UI Support + */ + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IAddUIWidgets) { + ((IAddUIWidgets) getMetaTileEntity()).addUIWidgets(builder, buildContext); + return; + } + super.addUIWidgets(builder, buildContext); + } + + @Override + public void bindPlayerInventoryUI(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IBindPlayerInventoryUI) { + ((IBindPlayerInventoryUI) getMetaTileEntity()).bindPlayerInventoryUI(builder, buildContext); + return; + } + super.bindPlayerInventoryUI(builder, buildContext); + } + + @Override + public IConfigurationCircuitSupport getConfigurationCircuitSupport() { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IConfigurationCircuitSupport) { + return (IConfigurationCircuitSupport) getMetaTileEntity(); + } + return null; + } + + @Override + public ItemStackHandler getInventoryHandler() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getInventoryHandler(); + } + return null; + } + + @Override + public boolean useModularUI() { + return hasValidMetaTileEntity() && getMetaTileEntity().useModularUI(); + } + + @Override + public String getLocalName() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getLocalName(); + return super.getLocalName(); + } + + @Override + protected int getGUIWidth() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getGUIWidth(); + + return super.getGUIWidth(); + } + + @Override + protected int getGUIHeight() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().getGUIHeight(); + + return super.getGUIHeight(); + } + + @Override + protected boolean doesBindPlayerInventory() { + if (hasValidMetaTileEntity()) return getMetaTileEntity().doesBindPlayerInventory(); + + return super.doesBindPlayerInventory(); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IAddGregtechLogo) { + ((IAddGregtechLogo) getMetaTileEntity()).addGregTechLogo(builder); + return; + } + super.addGregTechLogo(builder); + } + + @Override + public ItemStack getStackForm(long aAmount) { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getStackForm(aAmount); + } + return super.getStackForm(aAmount); + } + + @Override + public int getTitleColor() { + if (hasValidMetaTileEntity() && getMetaTileEntity() instanceof IGetTitleColor) { + return ((IGetTitleColor) getMetaTileEntity()).getTitleColor(); + } + return super.getTitleColor(); + } + + @Override + public int getGUIColorization() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getGUIColorization(); + } + return super.getGUIColorization(); + } + + @Override + protected int getTextColorOrDefault(String textType, int defaultColor) { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getTextColorOrDefault(textType, defaultColor); + } + return defaultColor; + } + + @Override + public GUITextureSet getGUITextureSet() { + if (hasValidMetaTileEntity()) { + return getMetaTileEntity().getGUITextureSet(); + } + return super.getGUITextureSet(); + } } diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index 9511488a3f..580fc136e6 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -6,31 +6,52 @@ import static gregtech.api.enums.GT_Values.NW; import static gregtech.api.util.GT_LanguageManager.FACES; import static gregtech.api.util.GT_LanguageManager.getTranslation; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.Column; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregtechWailaProvider; import gregtech.api.net.GT_Packet_RequestCoverData; import gregtech.api.net.GT_Packet_SendCoverData; +import gregtech.api.net.GT_Packet_TileEntityCoverGUI; import gregtech.api.objects.GT_ItemStack; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.ISerializableObject; import gregtech.common.GT_Client; import gregtech.common.covers.GT_Cover_Fluidfilter; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.IntStream; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; +import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidRegistry; @@ -526,4 +547,134 @@ public abstract class CoverableTileEntity extends BaseTileEntity implements ICov } } } + + protected ModularWindow createCoverWindow(EntityPlayer player, byte side) { + final GT_CoverBehaviorBase<?> coverBehavior = getCoverBehaviorAtSideNew(side); + final GT_CoverUIBuildContext buildContext = + new GT_CoverUIBuildContext(player, getCoverIDAtSide(side), side, this, true); + return coverBehavior.createWindow(buildContext); + } + + protected static final int COVER_WINDOW_ID_START = 1; + + @Override + public void addCoverTabs(ModularWindow.Builder builder, UIBuildContext buildContext) { + final int COVER_TAB_LEFT = -16, + COVER_TAB_TOP = 1, + COVER_TAB_HEIGHT = 20, + COVER_TAB_WIDTH = 18, + COVER_TAB_SPACING = 2, + ICON_SIZE = 16; + final boolean flipHorizontally = GT_Mod.gregtechproxy.mCoverTabsFlipped; + + final Column columnWidget = new Column(); + builder.widget(columnWidget); + final int xPos = flipHorizontally ? (getGUIWidth() - COVER_TAB_LEFT - COVER_TAB_WIDTH) : COVER_TAB_LEFT; + if (GT_Mod.gregtechproxy.mCoverTabsVisible) { + columnWidget.setPos(xPos, COVER_TAB_TOP).setEnabled(widget -> ((Column) widget) + .getChildren().stream().anyMatch(Widget::isEnabled)); + } else { + columnWidget.setEnabled(false); + } + columnWidget.setAlignment(MainAxisAlignment.SPACE_BETWEEN).setSpace(COVER_TAB_SPACING); + + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + final byte side = (byte) direction.ordinal(); + buildContext.addSyncedWindow(side + COVER_WINDOW_ID_START, player -> createCoverWindow(player, side)); + columnWidget.addChild(new MultiChildWidget() + .addChild( + new ButtonWidget() { + @Override + public IDrawable[] getBackground() { + final List<IDrawable> backgrounds = new ArrayList<>(); + final GUITextureSet tabIconSet = getGUITextureSet(); + + if (getCoverBehaviorAtSideNew(side).hasCoverGUI()) { + if (isHovering()) { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabHighlightFlipped() + : tabIconSet.getCoverTabHighlight()); + } else { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabNormalFlipped() + : tabIconSet.getCoverTabNormal()); + } + } else { + backgrounds.add( + flipHorizontally + ? tabIconSet.getCoverTabDisabledFlipped() + : tabIconSet.getCoverTabDisabled()); + } + return backgrounds.toArray(new IDrawable[] {}); + } + }.setOnClick((clickData, widget) -> onTabClicked(clickData, widget, side)) + .dynamicTooltip(() -> getCoverTabTooltip(side)) + .setSize(COVER_TAB_WIDTH, COVER_TAB_HEIGHT)) + .addChild(new ItemDrawable(() -> { + return getCoverItemAtSide(side); + }) + .asWidget() + .setPos( + (COVER_TAB_WIDTH - ICON_SIZE) / 2 + (flipHorizontally ? -1 : 1), + (COVER_TAB_HEIGHT - ICON_SIZE) / 2)) + .setEnabled(widget -> { + return getCoverItemAtSide(side) != null; + })); + } + } + + @SideOnly(Side.CLIENT) + protected List<String> getCoverTabTooltip(byte side) { + final String[] SIDE_TOOLTIPS = new String[] { + "GT5U.interface.coverTabs.down", + "GT5U.interface.coverTabs.up", + "GT5U.interface.coverTabs.north", + "GT5U.interface.coverTabs.south", + "GT5U.interface.coverTabs.west", + "GT5U.interface.coverTabs.east" + }; + final ItemStack coverItem = getCoverItemAtSide(side); + if (coverItem == null) return Collections.emptyList(); + boolean coverHasGUI = getCoverBehaviorAtSideNew(side).hasCoverGUI(); + + //noinspection unchecked + List<String> tooltip = coverItem.getTooltip(Minecraft.getMinecraft().thePlayer, true); + for (int i = 0; i < tooltip.size(); i++) { + if (i == 0) { + tooltip.set( + 0, + (coverHasGUI ? EnumChatFormatting.UNDERLINE : EnumChatFormatting.DARK_GRAY) + + StatCollector.translateToLocal(SIDE_TOOLTIPS[side]) + + (coverHasGUI ? EnumChatFormatting.RESET + ": " : ": " + EnumChatFormatting.RESET) + + tooltip.get(0)); + } else { + tooltip.set(i, EnumChatFormatting.GRAY + tooltip.get(i)); + } + } + return tooltip; + } + + protected void onTabClicked(Widget.ClickData clickData, Widget widget, byte side) { + if (isClientSide()) return; + + final GT_CoverBehaviorBase<?> coverBehavior = getCoverBehaviorAtSideNew(side); + if (coverBehavior.useModularUI()) { + widget.getContext().openSyncedWindow(side + COVER_WINDOW_ID_START); + } else { + final GT_Packet_TileEntityCoverGUI packet = new GT_Packet_TileEntityCoverGUI( + getXCoord(), + getYCoord(), + getZCoord(), + side, + getCoverIDAtSide(side), + getComplexCoverDataAtSide(side), + getWorld().provider.dimensionId, + widget.getContext().getPlayer().getEntityId(), + 0); + GT_Values.NW.sendToPlayer( + packet, (EntityPlayerMP) widget.getContext().getPlayer()); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java index 105ec073ec..ff9ac7517d 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java @@ -8,6 +8,7 @@ import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; +import gregtech.api.enums.Dyes; import gregtech.api.interfaces.metatileentity.IConnectable; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; @@ -1047,4 +1048,17 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable { } public void reloadLocks() {} + + @Override + public int getGUIColorization() { + Dyes dye = Dyes.dyeWhite; + if (GregTech_API.sColoredGUI) { + if (GregTech_API.sMachineMetalGUI) { + dye = Dyes.MACHINE_METAL; + } else if (getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + } + } + return GT_Util.getRGBInt(dye.getRGBA()); + } } diff --git a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java index 5c8f1c33bb..586b52fd99 100644 --- a/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/MetaTileEntity.java @@ -6,14 +6,19 @@ import appeng.api.networking.energy.IEnergyGrid; import appeng.api.networking.pathing.IPathingGrid; import appeng.api.util.AECableType; import appeng.me.helpers.AENetworkProxy; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gnu.trove.list.TIntList; import gnu.trove.list.array.TIntArrayList; import gregtech.api.GregTech_API; +import gregtech.api.enums.Dyes; import gregtech.api.enums.SoundResource; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.GT_GUIColorOverride; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.metatileentity.IMachineCallback; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -23,12 +28,15 @@ import gregtech.api.util.GT_Config; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_TooltipDataCache; +import gregtech.api.util.GT_Util; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Client; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.function.Supplier; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.block.Block; @@ -71,6 +79,19 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac */ public final ItemStack[] mInventory; + /** + * Inventory wrapper for ModularUI + */ + public final ItemStackHandler inventoryHandler; + + protected GT_GUIColorOverride colorOverride; + protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + + @Override + public ItemStackHandler getInventoryHandler() { + return inventoryHandler; + } + public boolean doTickProfilingInThisTick = true; private MetaTileEntity mCallBackTile; @@ -107,6 +128,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac getBaseMetaTileEntity().setMetaTileID((short) aID); GT_LanguageManager.addStringLocalization("gt.blockmachines." + mName + ".name", aRegionalName); mInventory = new ItemStack[aInvSlotCount]; + inventoryHandler = new ItemStackHandler(mInventory); } /** @@ -115,6 +137,9 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac public MetaTileEntity(String aName, int aInvSlotCount) { mInventory = new ItemStack[aInvSlotCount]; mName = aName; + inventoryHandler = new ItemStackHandler(mInventory); + colorOverride = new GT_GUIColorOverride( + getGUITextureSet().getMainBackground().location.getResourcePath()); } /** @@ -151,6 +176,7 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac getBaseMetaTileEntity().getMetaTileID()); } + @Override public String getLocalName() { return GT_LanguageManager.getTranslation("gt.blockmachines." + mName + ".name"); } @@ -396,6 +422,14 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac } /** + * @return what type of texture does this machine use for GUI, + * i.e. Bronze, Steel, or Primitive + */ + public SteamVariant getSteamVariant() { + return SteamVariant.NONE; + } + + /** * @return true if this Device emits Energy at all */ public boolean isEnetOutput() { @@ -991,11 +1025,19 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac // } + /** + * @deprecated Use ModularUI + */ + @Deprecated @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; } + /** + * @deprecated Use ModularUI + */ + @Deprecated @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return null; @@ -1048,64 +1090,32 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Override public void doExplosion(long aExplosionPower) { - float tStrength = aExplosionPower < V[0] - ? 1.0F - : aExplosionPower < V[1] - ? 2.0F - : aExplosionPower < V[2] - ? 3.0F - : aExplosionPower < V[3] - ? 4.0F - : aExplosionPower < V[4] - ? 5.0F - : aExplosionPower < V[4] * 2 - ? 6.0F - : aExplosionPower < V[5] - ? 7.0F - : aExplosionPower < V[6] - ? 8.0F - : aExplosionPower < V[7] - ? 9.0F - : aExplosionPower < V[8] - ? 10.0F - : aExplosionPower < V[8] * 2 - ? 11.0F - : aExplosionPower < V[9] - ? 12.0F - : aExplosionPower - < V[ - 10] - ? 13.0F - : aExplosionPower - < V[ - 11] - ? 14.0F - : aExplosionPower - < V[ - 12] - ? 15.0F - : aExplosionPower - < V[ - 12] - * 2 - ? 16.0F - : aExplosionPower - < V[ - 13] - ? 17.0F - : aExplosionPower - < V[ - 14] - ? 18.0F - : aExplosionPower - < V[ - 15] - ? 19.0F - : 20.0F; - int tX = getBaseMetaTileEntity().getXCoord(), - tY = getBaseMetaTileEntity().getYCoord(), - tZ = getBaseMetaTileEntity().getZCoord(); - World tWorld = getBaseMetaTileEntity().getWorld(); + // spotless:off + float tStrength = + aExplosionPower < V[0] ? 1.0F : + aExplosionPower < V[1] ? 2.0F : + aExplosionPower < V[2] ? 3.0F : + aExplosionPower < V[3] ? 4.0F : + aExplosionPower < V[4] ? 5.0F : + aExplosionPower < V[4] * 2 ? 6.0F : + aExplosionPower < V[5] ? 7.0F : + aExplosionPower < V[6] ? 8.0F : + aExplosionPower < V[7] ? 9.0F : + aExplosionPower < V[8] ? 10.0F : + aExplosionPower < V[8] * 2 ? 11.0F : + aExplosionPower < V[9] ? 12.0F : + aExplosionPower < V[10] ? 13.0F : + aExplosionPower < V[11] ? 14.0F : + aExplosionPower < V[12] ? 15.0F : + aExplosionPower < V[12] * 2 ? 16.0F : + aExplosionPower < V[13] ? 17.0F : + aExplosionPower < V[14] ? 18.0F : + aExplosionPower < V[15] ? 19.0F : 20.0F; + // spotless:on + final int tX = getBaseMetaTileEntity().getXCoord(); + final int tY = getBaseMetaTileEntity().getYCoord(); + final int tZ = getBaseMetaTileEntity().getZCoord(); + final World tWorld = getBaseMetaTileEntity().getWorld(); GT_Utility.sendSoundToPlayers(tWorld, SoundResource.IC2_MACHINES_MACHINE_OVERLOAD, 1.0F, -1, tX, tY, tZ); tWorld.setBlock(tX, tY, tZ, Blocks.air); if (GregTech_API.sMachineExplosions) @@ -1174,6 +1184,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac return false; } + // === AE2 compat === + @Optional.Method(modid = "appliedenergistics2") public AECableType getCableConnectionType(ForgeDirection forgeDirection) { return AECableType.NONE; @@ -1187,6 +1199,8 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac @Optional.Method(modid = "appliedenergistics2") public void gridChanged() {} + // === Waila compat === + @Override public void getWailaBody( ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { @@ -1218,4 +1232,38 @@ public abstract class MetaTileEntity implements IMetaTileEntity, IMachineCallbac } return ""; } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.DEFAULT; + } + + @Override + public int getGUIColorization() { + Dyes dye = Dyes.dyeWhite; + if (this.colorOverride.sLoaded()) { + if (this.colorOverride.sGuiTintingEnabled() && getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + return this.colorOverride.getGuiTintOrDefault(dye.mName, GT_Util.getRGBInt(dye.getRGBA())); + } + } else if (GregTech_API.sColoredGUI) { + if (GregTech_API.sMachineMetalGUI) { + dye = Dyes.MACHINE_METAL; + } else if (getBaseMetaTileEntity() != null) { + dye = Dyes.getDyeFromIndex(getBaseMetaTileEntity().getColorization()); + } + } + return GT_Util.getRGBInt(dye.getRGBA()); + } + + @Override + public int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); + } + + protected Supplier<Integer> COLOR_TITLE = () -> getTextColorOrDefault("title", 0x404040); + protected Supplier<Integer> COLOR_TITLE_WHITE = () -> getTextColorOrDefault("title_white", 0xfafaff); + protected Supplier<Integer> COLOR_TEXT_WHITE = () -> getTextColorOrDefault("text_white", 0xfafaff); + protected Supplier<Integer> COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x404040); + protected Supplier<Integer> COLOR_TEXT_RED = () -> getTextColorOrDefault("text_red", 0xff0000); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java index 67c3c672ae..45c07cf4c3 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicBatteryBuffer.java @@ -2,17 +2,19 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.enums.Textures; -import gregtech.api.gui.*; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaBase_Item; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; import ic2.api.item.IElectricItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -23,7 +25,8 @@ import net.minecraft.util.EnumChatFormatting; * This is the main construct for my Basic Machines such as the Automatic Extractor * Extend this class to make a simple Machine */ -public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_TieredMachineBlock { +public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_TieredMachineBlock + implements IAddUIWidgets { public boolean mCharge = false, mDecharge = false; public int mBatteryCount = 0, mChargeableCount = 0; private long count = 0; @@ -208,42 +211,11 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { - case 1: - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - case 4: - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - case 9: - return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); - case 16: - return new GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { - case 1: - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 4: - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 9: - return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - case 16: - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { mCharge = aBaseMetaTileEntity.getStoredEU() / 2 > aBaseMetaTileEntity.getEUCapacity() / 3; @@ -357,4 +329,27 @@ public class GT_MetaTileEntity_BasicBatteryBuffer extends GT_MetaTileEntity_Tier public boolean isGivingInformation() { return true; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mInventory.length) { + case 4: + getBaseMetaTileEntity().add2by2Slots(builder); + break; + case 9: + getBaseMetaTileEntity().add3by3Slots(builder); + break; + case 16: + getBaseMetaTileEntity().add4by4Slots(builder); + break; + default: + getBaseMetaTileEntity().add1by1Slot(builder); + break; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java index 091c364b4f..ca5f255302 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicGenerator.java @@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.V; import gregtech.api.enums.ItemList; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.ItemData; @@ -85,8 +86,7 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -355,4 +355,9 @@ public abstract class GT_MetaTileEntity_BasicGenerator extends GT_MetaTileEntity public int getTankPressure() { return -100; } + + @Override + public boolean useModularUI() { + return true; + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java index 15ce40cebf..a07fb5fb0d 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine.java @@ -4,25 +4,57 @@ import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.debugCleanroom; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; +import static gregtech.api.metatileentity.BaseTileEntity.FLUID_INPUT_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.FLUID_OUTPUT_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.FLUID_TRANSFER_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.ITEM_TRANSFER_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.NEI_TRANSFER_STEAM_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.NEI_TRANSFER_VOLTAGE_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.POWER_SOURCE_KEY; +import static gregtech.api.metatileentity.BaseTileEntity.SPECIAL_SLOT_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.STALLED_STUTTERING_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.STALLED_VENT_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; +import static gregtech.api.metatileentity.BaseTileEntity.UNUSED_SLOT_TOOLTIP; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; import gregtech.api.enums.SoundResource; import gregtech.api.gui.GT_Container_BasicMachine; import gregtech.api.gui.GT_GUIContainer_BasicMachine; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.SteamTexture; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; import gregtech.api.render.TextureFactory; import gregtech.api.util.*; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gregtech.common.gui.modularui.UIHelper; +import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget; import gregtech.common.power.BasicMachineEUPower; import gregtech.common.power.Power; import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -39,6 +71,7 @@ import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; +import org.apache.commons.lang3.tuple.Pair; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -47,7 +80,7 @@ import net.minecraftforge.fluids.IFluidHandler; * Extend this class to make a simple Machine */ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_BasicTank - implements IConfigurationCircuitSupport { + implements IConfigurationCircuitSupport, IAddUIWidgets { /** * return values for checkRecipe() @@ -369,6 +402,10 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B return OTHER_SLOT_COUNT + mInputSlotCount; } + public int getSpecialSlotIndex() { + return 3; + } + @Override public int getStackDisplaySlot() { return 2; @@ -482,12 +519,20 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; if (!GT_Mod.gregtechproxy.mForceFreeFace) { - aBaseMetaTileEntity.openGUI(aPlayer); + if (useModularUI()) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + } return true; } for (byte i = 0; i < 6; i++) { if (aBaseMetaTileEntity.getAirAtSide(i)) { - aBaseMetaTileEntity.openGUI(aPlayer); + if (useModularUI()) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + } else { + aBaseMetaTileEntity.openGUI(aPlayer); + } return true; } } @@ -495,11 +540,13 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B return true; } + @Deprecated @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_Container_BasicMachine(aPlayerInventory, aBaseMetaTileEntity); } + @Deprecated @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_BasicMachine( @@ -685,7 +732,8 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B || aBaseMetaTileEntity.hasWorkJustBeenEnabled()) && hasEnoughEnergyToCheckRecipe()) { if (checkRecipe() == FOUND_AND_SUCCESSFULLY_USED_RECIPE) { - if (mInventory[3] != null && mInventory[3].stackSize <= 0) mInventory[3] = null; + if (getSpecialSlot() != null && getSpecialSlot().stackSize <= 0) + mInventory[getSpecialSlotIndex()] = null; for (int i = getInputSlot(), j = i + mInputSlotCount; i < j; i++) if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; for (int i = 0; i < mOutputItems.length; i++) { @@ -734,7 +782,15 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B @Override public void updateFluidDisplayItem() { + updateFluidOutputDisplayItem(); + updateFluidInputDisplayItem(); + } + + public void updateFluidOutputDisplayItem() { super.updateFluidDisplayItem(); + } + + public void updateFluidInputDisplayItem() { if (displaysInputFluid()) { int tDisplayStackSlot = OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length; if (getFillableStack() == null) { @@ -771,7 +827,7 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B } protected ItemStack getSpecialSlot() { - return mInventory[3]; + return mInventory[getSpecialSlotIndex()]; } protected ItemStack getOutputAt(int aIndex) { @@ -1231,6 +1287,13 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B return mPower; } + // GUI stuff + + @Override + public boolean useModularUI() { + return getRecipeList() != null && getRecipeList().useModularUI; + } + @Override public int getCircuitSlotX() { return 153; @@ -1240,4 +1303,252 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B public int getCircuitSlotY() { return 63; } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (!isSteampowered()) { + builder.widget(createFluidAutoOutputButton()); + builder.widget(createItemAutoOutputButton()); + } + + addIOSlots(builder); + + builder.widget(createChargerSlot(79, 62)); + if (getRecipeList() != null) { + builder.widget(setNEITransferRect( + createProgressBar( + isSteampowered() + ? getRecipeList().progressBarTextureSteam.get(getSteamVariant()) + : getRecipeList().progressBarTexture, + getRecipeList().getProgressBarImageSize(), + getRecipeList().progressBarDirection, + getRecipeList().progressBarPos, + getRecipeList().progressBarSize), + getRecipeList().mNEIName)); + addProgressBarSpecialTextures(builder); + } + builder.widget(createErrorStatusArea( + builder, + isSteampowered() ? GT_UITextures.PICTURE_STALLED_STEAM : GT_UITextures.PICTURE_STALLED_ELECTRICITY)); + } + + /** + * Adds item I/O, special item, and fluid I/O slots. + */ + protected void addIOSlots(ModularWindow.Builder builder) { + final boolean hasFluidInput = + getRecipeList() != null ? (getRecipeList().hasFluidInputs()) : (getCapacity() != 0); + final boolean hasFluidOutput = + getRecipeList() != null && getRecipeList().hasFluidOutputs(); + UIHelper.forEachSlots( + (i, backgrounds, pos) -> builder.widget(createItemInputSlot(i, backgrounds, pos)), + (i, backgrounds, pos) -> builder.widget(createItemOutputSlot(i, backgrounds, pos)), + (i, backgrounds, pos) -> builder.widget(createSpecialSlot(backgrounds, pos)), + (i, backgrounds, pos) -> builder.widget(createFluidInputSlot(backgrounds, pos)), + (i, backgrounds, pos) -> builder.widget(createFluidOutputSlot(backgrounds, pos)), + getGUITextureSet().getItemSlot(), + getGUITextureSet().getFluidSlot(), + getRecipeList(), + mInputSlotCount, + mOutputItems.length, + hasFluidInput ? 1 : 0, + hasFluidOutput ? 1 : 0, + getSteamVariant(), + Pos2d.ZERO); + } + + /** + * Override this as needed instead of calling. + */ + protected SlotWidget createItemInputSlot(int index, IDrawable[] backgrounds, Pos2d pos) { + return (SlotWidget) new SlotWidget(inventoryHandler, getInputSlot() + index) + .setAccess(true, true) + .setBackground(backgrounds) + .setPos(pos); + } + + /** + * Override this as needed instead of calling. + */ + protected SlotWidget createItemOutputSlot(int index, IDrawable[] backgrounds, Pos2d pos) { + return (SlotWidget) new SlotWidget(inventoryHandler, getOutputSlot() + index) + .setAccess(true, false) + .setBackground(backgrounds) + .setPos(pos); + } + + /** + * Override this as needed instead of calling. + */ + protected SlotWidget createSpecialSlot(IDrawable[] backgrounds, Pos2d pos) { + return (SlotWidget) new SlotWidget(inventoryHandler, getSpecialSlotIndex()) + .setAccess(true, true) + .disableShiftInsert() + .setGTTooltip(() -> mTooltipCache.getData( + getRecipeList() != null && getRecipeList().usesSpecialSlot() + ? SPECIAL_SLOT_TOOLTIP + : UNUSED_SLOT_TOOLTIP)) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setBackground(backgrounds) + .setPos(pos); + } + + protected FluidDisplaySlotWidget createFluidInputSlot(IDrawable[] backgrounds, Pos2d pos) { + return (FluidDisplaySlotWidget) new FluidDisplaySlotWidget( + inventoryHandler, OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length) + .setFluidAccessConstructor(() -> constructFluidAccess(true)) + .setIHasFluidDisplay(this) + .setCanDrain(true) + .setCanFill(true) + .setActionRealClick(FluidDisplaySlotWidget.Action.TRANSFER) + .setBeforeRealClick((clickData, widget) -> { + if (NetworkUtils.isClient()) { + // propagate display item content to actual fluid stored in this tank + setFillableStack(GT_Utility.getFluidFromDisplayStack( + widget.getMcSlot().getStack())); + } + return true; + }) + .setUpdateFluidDisplayItem(this::updateFluidInputDisplayItem) + .setGTTooltip(() -> mTooltipCache.getData(FLUID_INPUT_TOOLTIP, GT_Utility.formatNumbers(getCapacity()))) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setBackground(backgrounds) + .setPos(pos); + } + + protected FluidDisplaySlotWidget createFluidOutputSlot(IDrawable[] backgrounds, Pos2d pos) { + return (FluidDisplaySlotWidget) createDrainableFluidSlot() + .setUpdateFluidDisplayItem(this::updateFluidOutputDisplayItem) + .setGTTooltip( + () -> mTooltipCache.getData(FLUID_OUTPUT_TOOLTIP, GT_Utility.formatNumbers(getCapacity()))) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setBackground(backgrounds) + .setPos(pos); + } + + @Override + protected SlotWidget createChargerSlot(int x, int y) { + if (isSteampowered()) { + return (SlotWidget) createChargerSlot(x, y, UNUSED_SLOT_TOOLTIP, new String[0]) + .setBackground(getGUITextureSet().getItemSlot()); + } else { + return super.createChargerSlot(x, y); + } + } + + protected CycleButtonWidget createItemAutoOutputButton() { + return (CycleButtonWidget) new CycleButtonWidget() + .setToggle(() -> mItemTransfer, val -> mItemTransfer = val) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_AUTOOUTPUT_ITEM) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setGTTooltip(() -> mTooltipCache.getData(ITEM_TRANSFER_TOOLTIP)) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(25, 62) + .setSize(18, 18); + } + + protected CycleButtonWidget createFluidAutoOutputButton() { + return (CycleButtonWidget) new CycleButtonWidget() + .setToggle(() -> mFluidTransfer, val -> mFluidTransfer = val) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_AUTOOUTPUT_FLUID) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setGTTooltip(() -> mTooltipCache.getData(FLUID_TRANSFER_TOOLTIP)) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(7, 62) + .setSize(18, 18); + } + + protected ProgressBar createProgressBar( + UITexture texture, int imageSize, ProgressBar.Direction direction, Pos2d pos, Size size) { + final ProgressBar ret = new ProgressBar(); + ret.setProgress(() -> maxProgresstime() != 0 ? (float) getProgresstime() / maxProgresstime() : 0) + .setTexture(texture, imageSize) + .setDirection(direction) + .setPos(pos) + .setSize(size); + return ret; + } + + public boolean hasNEITransferRect() { + return getRecipeList() != null; + } + + protected Widget setNEITransferRect(Widget widget, String transferRectID) { + if (hasNEITransferRect()) { + final Power powerInfo = getPower(); + final String transferRectTooltip; + if (isSteampowered()) { + transferRectTooltip = + StatCollector.translateToLocalFormatted(NEI_TRANSFER_STEAM_TOOLTIP, powerInfo.getTierString()); + } else { + transferRectTooltip = StatCollector.translateToLocalFormatted( + NEI_TRANSFER_VOLTAGE_TOOLTIP, powerInfo.getTierString()); + } + widget.setNEITransferRect(transferRectID, new Object[] {powerInfo}, transferRectTooltip); + } + return widget; + } + + protected void addProgressBarSpecialTextures(ModularWindow.Builder builder) { + if (isSteampowered()) { + for (Pair<SteamTexture, Pair<Size, Pos2d>> specialTexture : getRecipeList().specialTexturesSteam) { + builder.widget(new DrawableWidget() + .setDrawable(specialTexture.getLeft().get(getSteamVariant())) + .setSize(specialTexture.getRight().getLeft()) + .setPos(specialTexture.getRight().getRight())); + } + } else { + for (Pair<IDrawable, Pair<Size, Pos2d>> specialTexture : getRecipeList().specialTextures) { + builder.widget(new DrawableWidget() + .setDrawable(specialTexture.getLeft()) + .setSize(specialTexture.getRight().getLeft()) + .setPos(specialTexture.getRight().getRight())); + } + } + } + + protected DrawableWidget createErrorStatusArea(ModularWindow.Builder builder, IDrawable picture) { + return (DrawableWidget) new DrawableWidget() + .setDrawable(picture) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setEnabled(widget -> !widget.getTooltip().isEmpty()) + .dynamicTooltip(this::getErrorDescriptions) + .dynamicTooltipShift(this::getErrorDescriptionsShift) + .setPos(79, 44) + .setSize(18, 18) + .attachSyncer( + new FakeSyncWidget.BooleanSyncer(() -> mStuttering, val -> mStuttering = val), + builder, + (widget, val) -> widget.notifyTooltipChange()) + .attachSyncer( + new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val)), + builder, + (widget, val) -> widget.notifyTooltipChange()); + } + + protected List<String> getErrorDescriptions() { + final GT_TooltipDataCache.TooltipData tooltip = getErrorTooltip(); + return tooltip != null ? tooltip.text : Collections.emptyList(); + } + + protected List<String> getErrorDescriptionsShift() { + final GT_TooltipDataCache.TooltipData tooltip = getErrorTooltip(); + return tooltip != null ? tooltip.shiftText : Collections.emptyList(); + } + + protected GT_TooltipDataCache.TooltipData getErrorTooltip() { + if (isSteampowered()) { + if ((getBaseMetaTileEntity().getErrorDisplayID() & 64) != 0) { + return mTooltipCache.getData(STALLED_VENT_TOOLTIP); + } + } + if (mStuttering) { + return mTooltipCache.getData( + STALLED_STUTTERING_TOOLTIP, + StatCollector.translateToLocal(POWER_SOURCE_KEY + (isSteampowered() ? "steam" : "power"))); + } + return null; + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java index aa893c0bc2..049aaa45bf 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java @@ -8,6 +8,8 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.Dyes; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ItemStack; @@ -427,4 +429,14 @@ public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileE TextureFactory.of(OVERLAY_PIPE_OUT) }; } + + @Override + public SteamVariant getSteamVariant() { + return SteamVariant.BRONZE; + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.STEAM.apply(getSteamVariant()); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Steel.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Steel.java index d69ab3aa14..592d27f74f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Steel.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Steel.java @@ -9,7 +9,9 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_STEEL_TOP; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; import gregtech.api.enums.Dyes; +import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IGetTitleColor; import gregtech.api.render.TextureFactory; import gregtech.common.power.Power; import gregtech.common.power.SteamPower; @@ -20,7 +22,8 @@ import gregtech.common.power.SteamPower; * This is the main construct for my Basic Machines such as the Automatic Extractor * Extend this class to make a simple Machine */ -public abstract class GT_MetaTileEntity_BasicMachine_Steel extends GT_MetaTileEntity_BasicMachine_Bronze { +public abstract class GT_MetaTileEntity_BasicMachine_Steel extends GT_MetaTileEntity_BasicMachine_Bronze + implements IGetTitleColor { public GT_MetaTileEntity_BasicMachine_Steel( int aID, String aName, @@ -188,4 +191,14 @@ public abstract class GT_MetaTileEntity_BasicMachine_Steel extends GT_MetaTileEn TextureFactory.of(OVERLAY_PIPE_OUT) }; } + + @Override + public SteamVariant getSteamVariant() { + return SteamVariant.STEEL; + } + + @Override + public int getTitleColor() { + return COLOR_TITLE_WHITE.get(); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java index c1b734baf6..0207178559 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicTank.java @@ -1,12 +1,22 @@ package gregtech.api.metatileentity.implementations; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.api.enums.ItemList; import gregtech.api.gui.GT_Container_BasicTank; import gregtech.api.gui.GT_GUIContainer_BasicTank; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.IFluidAccess; import gregtech.api.interfaces.IHasFluidDisplayItem; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -20,7 +30,7 @@ import net.minecraftforge.fluids.FluidTankInfo; * This is the main construct for my generic Tanks. Filling and emptying behavior have to be implemented manually */ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_TieredMachineBlock - implements IHasFluidDisplayItem { + implements IHasFluidDisplayItem, IAddUIWidgets { public FluidStack mFluid; protected int mOpenerCount; @@ -90,6 +100,9 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier public abstract boolean displaysItemStack(); + /** + * @return If fluid amount is shown on FluidDisplayItem + */ public abstract boolean displaysStackSize(); public int getInputSlot() { @@ -141,11 +154,13 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier return getDrainableStack(); } + @Deprecated @Override public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_Container_BasicTank(aPlayerInventory, aBaseMetaTileEntity); } + @Deprecated @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_BasicTank(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); @@ -329,4 +344,79 @@ public abstract class GT_MetaTileEntity_BasicTank extends GT_MetaTileEntity_Tier protected void onEmptyingContainerWhenEmpty() { // Do nothing } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 16) + .setSize(71, 45)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_GAUGE) + .setPos(79, 34) + .setSize(18, 18)) + .widget(new SlotWidget(inventoryHandler, getInputSlot()) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_IN) + .setPos(79, 16)) + .widget(new SlotWidget(inventoryHandler, getOutputSlot()) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_OUT) + .setPos(79, 52)) + .widget(createDrainableFluidSlot() + .setBackground(GT_UITextures.TRANSPARENT) + .setPos(58, 41)) + .widget(new TextWidget("Liquid Amount") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 20)) + .widget(TextWidget.dynamicString( + () -> GT_Utility.parseNumberToString(mFluid != null ? mFluid.amount : 0)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 30)); + } + + protected FluidDisplaySlotWidget createDrainableFluidSlot() { + return new FluidDisplaySlotWidget(inventoryHandler, getStackDisplaySlot()) + .setFluidAccessConstructor(() -> constructFluidAccess(false)) + .setIHasFluidDisplay(this) + .setCanDrain(true) + .setCanFill(!isDrainableStackSeparate()) + .setActionRealClick(FluidDisplaySlotWidget.Action.TRANSFER) + .setBeforeRealClick((clickData, widget) -> { + if (NetworkUtils.isClient()) { + // propagate display item content to actual fluid stored in this tank + setDrainableStack(GT_Utility.getFluidFromDisplayStack( + widget.getMcSlot().getStack())); + } + return true; + }); + } + + protected IFluidAccess constructFluidAccess(boolean aIsFillableStack) { + return new BasicTankFluidAccess(this, aIsFillableStack); + } + + protected static class BasicTankFluidAccess implements IFluidAccess { + protected final GT_MetaTileEntity_BasicTank mTank; + protected final boolean mIsFillableStack; + + public BasicTankFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { + this.mTank = aTank; + this.mIsFillableStack = aIsFillableStack; + } + + @Override + public void set(FluidStack stack) { + if (mIsFillableStack) mTank.setFillableStack(stack); + else mTank.setDrainableStack(stack); + } + + @Override + public FluidStack get() { + return mIsFillableStack ? mTank.getFillableStack() : mTank.getDrainableStack(); + } + + @Override + public int getCapacity() { + return mTank.getCapacity(); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java index 7354546002..6d327646fe 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Buffer.java @@ -3,6 +3,11 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.Textures.BlockIcons.*; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.render.TextureFactory; @@ -226,8 +231,7 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -429,4 +433,91 @@ public abstract class GT_MetaTileEntity_Buffer extends GT_MetaTileEntity_TieredM } return super.onSolderingToolRightClick(aSide, aWrenchingSide, aPlayer, aX, aY, aZ); } + + @Override + public boolean useModularUI() { + return true; + } + + protected void addEmitEnergyButton(ModularWindow.Builder builder) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bOutput = !bOutput; + if (bOutput) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("116", "Emit Energy to Outputside")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("117", "Don't emit Energy")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EMIT_ENERGY) + .setPos(7, 62) + .setSize(18, 18)); + } + + protected void addEmitRedstoneButton(ModularWindow.Builder builder) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bRedstoneIfFull = !bRedstoneIfFull; + if (bRedstoneIfFull) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), + GT_Utility.trans("118", "Emit Redstone if no Slot is free")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("119", "Don't emit Redstone")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_EMIT_REDSTONE) + .setPos(25, 62) + .setSize(18, 18)); + } + + protected void addInvertRedstoneButton(ModularWindow.Builder builder) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bInvert = !bInvert; + if (bInvert) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("120", "Invert Redstone")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("121", "Don't invert Redstone")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_REDSTONE) + .setPos(43, 62) + .setSize(18, 18)); + } + + protected void addStockingModeButton(ModularWindow.Builder builder) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bStockingMode = !bStockingMode; + if (bStockingMode) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), + GT_Utility.trans( + "217", + "Stocking mode. Keeps this many items in destination input slots. This mode can be server unfriendly.")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), + GT_Utility.trans( + "218", + "Transfer size mode. Add exactly this many items in destination input slots as long as there is room.")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_STOCKING_MODE) + .setPos(61, 62) + .setSize(18, 18)); + } + + protected void addInventorySlots(ModularWindow.Builder builder) { + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 9) + .endAtSlot(26) + .build() + .setPos(7, 4)); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DataAccess.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DataAccess.java index bc4b82477d..e60ffe0f58 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DataAccess.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_DataAccess.java @@ -2,21 +2,21 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_DATA_ACCESS; -import gregtech.api.gui.GT_Container_2by2; -import gregtech.api.gui.GT_Container_4by4; -import gregtech.api.gui.GT_GUIContainer_2by2; -import gregtech.api.gui.GT_GUIContainer_4by4; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_AssemblyLineUtils; 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_DataAccess extends GT_MetaTileEntity_Hatch { +public class GT_MetaTileEntity_Hatch_DataAccess extends GT_MetaTileEntity_Hatch implements IAddUIWidgets { private int timeout = 4; public GT_MetaTileEntity_Hatch_DataAccess(int aID, String aName, String aNameRegional, int aTier) { @@ -71,34 +71,11 @@ public class GT_MetaTileEntity_Hatch_DataAccess extends GT_MetaTileEntity_Hatch @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 4: - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - default: - return new GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 4: - return new GT_GUIContainer_2by2( - aPlayerInventory, aBaseMetaTileEntity, "Data Access Hatch", "DataAccess"); - default: - return new GT_GUIContainer_4by4( - aPlayerInventory, aBaseMetaTileEntity, "Data Access Hatch", "DataAccess"); - } - } - - @Override public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return mTier >= 8 && !aBaseMetaTileEntity.isActive(); } @@ -150,4 +127,23 @@ public class GT_MetaTileEntity_Hatch_DataAccess extends GT_MetaTileEntity_Hatch super.setInventorySlotContents(aIndex, aStack); GT_AssemblyLineUtils.processDataStick(aStack); } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mTier) { + case 4: + getBaseMetaTileEntity() + .add2by2Slots(builder, getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_CIRCUIT); + break; + default: + getBaseMetaTileEntity() + .add4by4Slots(builder, getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_CIRCUIT); + break; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java index cb2c869edc..ead36c10ab 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Input.java @@ -4,6 +4,7 @@ import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; import gregtech.GT_Mod; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -93,8 +94,7 @@ public class GT_MetaTileEntity_Hatch_Input extends GT_MetaTileEntity_Hatch { @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -162,4 +162,9 @@ public class GT_MetaTileEntity_Hatch_Input extends GT_MetaTileEntity_Hatch { public int getTankPressure() { return -100; } + + @Override + public boolean useModularUI() { + return true; + } } 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 f9daf9c605..b6ace5a630 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 @@ -2,10 +2,13 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.Textures.BlockIcons.*; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.GT_Mod; -import gregtech.api.gui.*; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; @@ -18,12 +21,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; -public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch implements IConfigurationCircuitSupport { +public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch + implements IConfigurationCircuitSupport, IAddUIWidgets { public GT_Recipe_Map mRecipeMap = null; public boolean disableSort; public boolean disableFilter = true; @@ -108,26 +111,11 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch im @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 0: - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - case 1: - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - case 2: - return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); - default: - return new GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - } - - @Override public int getCircuitSlotX() { return 153; } @@ -147,22 +135,6 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch im } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mInventory.length) { - case 2: - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, "Input Bus"); - case 5: - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Input Bus"); - case 10: - return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, "Input Bus"); - case 17: - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, "Input Bus"); - default: - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, "Input Bus"); - } - } - - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { updateSlots(); @@ -287,4 +259,27 @@ public class GT_MetaTileEntity_Hatch_InputBus extends GT_MetaTileEntity_Hatch im public int getCircuitSlot() { return getSlots(mTier); } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mTier) { + case 0: + getBaseMetaTileEntity().add1by1Slot(builder); + break; + case 1: + getBaseMetaTileEntity().add2by2Slots(builder); + break; + case 2: + getBaseMetaTileEntity().add3by3Slots(builder); + break; + default: + getBaseMetaTileEntity().add4by4Slots(builder); + break; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java index d0752d9f0d..98164c6863 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Maintenance.java @@ -7,16 +7,21 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_AUTOMAINTENANCE_IDL import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_DUCTTAPE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MAINTENANCE; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_Container_2by2; -import gregtech.api.gui.GT_Container_MaintenanceHatch; -import gregtech.api.gui.GT_GUIContainer_2by2; -import gregtech.api.gui.GT_GUIContainer_MaintenanceHatch; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; @@ -28,13 +33,12 @@ import ic2.core.item.ItemToolbox; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.FakePlayer; -public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch { +public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch implements IAddUIWidgets { private static ItemStack[] sAutoMaintenanceInputs; public boolean mWrench = false, mScrewdriver = false, @@ -173,27 +177,15 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch if (--tStack.stackSize == 0) { aPlayer.inventory.mainInventory[aPlayer.inventory.currentItem] = null; } - } else aBaseMetaTileEntity.openGUI(aPlayer); + } else GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); } else { - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); } return true; } return false; } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - if (mAuto) return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - return new GT_Container_MaintenanceHatch(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - if (mAuto) return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - return new GT_GUIContainer_MaintenanceHatch(aPlayerInventory, aBaseMetaTileEntity); - } - public void updateSlots() { for (int i = 0; i < mInventory.length; i++) if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; @@ -311,8 +303,8 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch } private void applyToolbox(ItemStack aStack, EntityPlayer aPlayer) { - ItemToolbox aToolbox = (ItemToolbox) aStack.getItem(); - IHasGui aToolboxGUI = aToolbox.getInventory(aPlayer, aStack); + final ItemToolbox aToolbox = (ItemToolbox) aStack.getItem(); + final IHasGui aToolboxGUI = aToolbox.getInventory(aPlayer, aStack); for (int i = 0; i < aToolboxGUI.getSizeInventory(); i++) { if (aToolboxGUI.getStackInSlot(i) != null) { onToolClick(aToolboxGUI.getStackInSlot(i), aPlayer, aToolboxGUI); @@ -341,4 +333,43 @@ public class GT_MetaTileEntity_Hatch_Maintenance extends GT_MetaTileEntity_Hatch } return false; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + if (mAuto) { + getBaseMetaTileEntity().add2by2Slots(builder); + } else { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.SLOT_MAINTENANCE) + .setPos(78, 33) + .setSize(20, 20)) + .widget( + new SlotWidget(BaseSlot.empty()) { + @Override + public boolean handleDragAndDrop(ItemStack draggedStack, int button) { + return false; + } + + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + if (cursorStack == null) return; + onToolClick(cursorStack, getContext().getPlayer()); + if (cursorStack.stackSize < 1) { + getContext().getPlayer().inventory.setItemStack(null); + } + if (getContext().getPlayer() instanceof EntityPlayerMP) { + ((EntityPlayerMP) getContext().getPlayer()).updateHeldItem(); + } + } + }.setBackground(GT_UITextures.TRANSPARENT).setPos(79, 34)) + .widget(new TextWidget("Click with Tool to repair.") + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(8, 12)); + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java index d65370901b..3e1b39c1fd 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java @@ -38,12 +38,28 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch { super(aID, aName, aNameRegional, aTier, 0, ""); } + public GT_MetaTileEntity_Hatch_Muffler( + int aID, + String aName, + String aNameRegional, + int aTier, + int aInvSlotCount, + String[] aDescription, + ITexture... aTextures) { + super(aID, aName, aNameRegional, aTier, aInvSlotCount, aDescription, aTextures); + } + public GT_MetaTileEntity_Hatch_Muffler(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { this(aName, aTier, new String[] {aDescription}, aTextures); } public GT_MetaTileEntity_Hatch_Muffler(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 0, aDescription, aTextures); + this(aName, aTier, 0, aDescription, aTextures); + } + + public GT_MetaTileEntity_Hatch_Muffler( + String aName, int aTier, int aInvSlotCount, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aInvSlotCount, aDescription, aTextures); setInValidFacings(ForgeDirection.DOWN); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_MultiInput.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_MultiInput.java index 3d4b24ef93..66c5401bd7 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_MultiInput.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_MultiInput.java @@ -2,21 +2,27 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_INPUT_HATCH_2x2; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import gregtech.api.enums.ItemList; -import gregtech.api.gui.GT_Container_2by2_Fluid; -import gregtech.api.gui.GT_GUIContainer_2by2_Fluid; +import gregtech.api.interfaces.IFluidAccess; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; +import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; -public class GT_MetaTileEntity_Hatch_MultiInput extends GT_MetaTileEntity_Hatch_Input { +public class GT_MetaTileEntity_Hatch_MultiInput extends GT_MetaTileEntity_Hatch_Input implements IAddUIWidgets { public FluidStack[] mStoredFluid; public int mCapacityPer; @@ -62,6 +68,11 @@ public class GT_MetaTileEntity_Hatch_MultiInput extends GT_MetaTileEntity_Hatch_ } } + @Override + public boolean displaysStackSize() { + return true; + } + public FluidStack[] getStoredFluid() { return mStoredFluid; } @@ -245,16 +256,6 @@ public class GT_MetaTileEntity_Hatch_MultiInput extends GT_MetaTileEntity_Hatch_ } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_2by2_Fluid(aPlayerInventory, aBaseMetaTileEntity, "Quadruple Input Hatch"); - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_2by2_Fluid(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide() && mStoredFluid != null) { for (int i = 0; i < getMaxType(); i++) { @@ -274,11 +275,89 @@ public class GT_MetaTileEntity_Hatch_MultiInput extends GT_MetaTileEntity_Hatch_ @Override public void updateFluidDisplayItem() { for (int i = 0; i < 4; i++) { - if (getFluid(i) == null || getFluid(i).amount <= 0) { - if (ItemList.Display_Fluid.isStackEqual(mInventory[i], true, true)) mInventory[i] = null; - } else { - mInventory[i] = GT_Utility.getFluidDisplayStack(getFluid(i), true, !displaysStackSize()); - } + updateFluidDisplayItem(i); + } + } + + public void updateFluidDisplayItem(int index) { + if (getFluid(index) == null || getFluid(index).amount <= 0) { + if (ItemList.Display_Fluid.isStackEqual(mInventory[index], true, true)) mInventory[index] = null; + } else { + mInventory[index] = GT_Utility.getFluidDisplayStack(getFluid(index), true, !displaysStackSize()); + } + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + final int SLOT_NUMBER = 4; + final Pos2d[] positions = new Pos2d[] { + new Pos2d(70, 25), new Pos2d(88, 25), new Pos2d(70, 43), new Pos2d(88, 43), + }; + + for (int i = 0; i < SLOT_NUMBER; i++) { + final int slotId = i; + builder.widget(new FluidDisplaySlotWidget(inventoryHandler, slotId) + .setFluidAccessConstructor(() -> constructFluidAccess(slotId)) + .setIHasFluidDisplay(this) + .setCanDrain(true) + .setCanFill(!isDrainableStackSeparate()) + .setActionRealClick(FluidDisplaySlotWidget.Action.TRANSFER) + .setBeforeRealClick((clickData, widget) -> { + if (NetworkUtils.isClient()) { + // propagate display item content to actual fluid stored in this tank + setFluid( + GT_Utility.getFluidFromDisplayStack( + widget.getMcSlot().getStack()), + slotId); + } + ItemStack tStackHeld = + widget.getContext().getPlayer().inventory.getItemStack(); + FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackHeld, true); + return constructFluidAccess(slotId).isMatch(tFluidHeld, slotId); + }) + .setUpdateFluidDisplayItem(() -> updateFluidDisplayItem(slotId)) + .setBackground(ModularUITextures.FLUID_SLOT) + .setPos(positions[slotId])); + } + } + + protected MultiFluidAccess constructFluidAccess(int aSlot) { + return new MultiFluidAccess(this, aSlot); + } + + protected static class MultiFluidAccess implements IFluidAccess { + private final GT_MetaTileEntity_Hatch_MultiInput mTank; + private final int mSlot; + + public MultiFluidAccess(GT_MetaTileEntity_Hatch_MultiInput aTank, int aSlot) { + this.mTank = aTank; + this.mSlot = aSlot; + } + + public boolean isMatch(FluidStack stack, int slot) { + if (!mTank.hasFluid(stack)) return true; + if (stack == null) return true; + return stack.equals(mTank.getFluid(slot)); + } + + @Override + public void set(FluidStack stack) { + mTank.setFluid(stack, mSlot); + } + + @Override + public FluidStack get() { + return mTank.getFluid(mSlot); + } + + @Override + public int getCapacity() { + return mTank.getCapacity(); } } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java index dabdd7dbb8..11ffa6e802 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java @@ -3,19 +3,27 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.Textures.BlockIcons.FLUID_OUT_SIGN; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.GT_Mod; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IFluidLockable; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_OutputHatch; -import gregtech.common.gui.GT_GUIContainer_OutputHatch; +import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget; import java.lang.ref.WeakReference; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -23,7 +31,7 @@ import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; -public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch implements IFluidLockable { +public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch implements IFluidLockable, IAddUIWidgets { private String lockedFluidName = null; private WeakReference<EntityPlayer> playerThatLockedfluid = null; public byte mMode = 0; @@ -97,8 +105,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch impl @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -181,17 +188,21 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch impl return false; } + public int getLockedDisplaySlot() { + return 3; + } + @Override public void updateFluidDisplayItem() { super.updateFluidDisplayItem(); - if (lockedFluidName == null || mMode < 8) mInventory[3] = null; + if (lockedFluidName == null || mMode < 8) mInventory[getLockedDisplaySlot()] = null; else { FluidStack tLockedFluid = FluidRegistry.getFluidStack(lockedFluidName, 1); // Because getStackDisplaySlot() only allow return one int, this place I only can manually set. if (tLockedFluid != null) { - mInventory[3] = GT_Utility.getFluidDisplayStack(tLockedFluid, false, true); + mInventory[getLockedDisplaySlot()] = GT_Utility.getFluidDisplayStack(tLockedFluid, false, true); } else { - mInventory[3] = null; + mInventory[getLockedDisplaySlot()] = null; } } } @@ -199,17 +210,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch impl @Override public boolean isValidSlot(int aIndex) { // Because getStackDisplaySlot() only allow return one int, this place I only can manually set. - return aIndex != getStackDisplaySlot() && aIndex != 3; - } - - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_OutputHatch(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_OutputHatch(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); + return aIndex != getStackDisplaySlot() && aIndex != getLockedDisplaySlot(); } @Override @@ -464,4 +465,48 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch impl .getUnlocalizedName())) }; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + super.addUIWidgets(builder, buildContext); + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(98, 16) + .setSize(71, 45)) + .widget(new FluidDisplaySlotWidget(inventoryHandler, getLockedDisplaySlot()) + .setIHasFluidDisplay(this) + .setActionRealClick(FluidDisplaySlotWidget.Action.LOCK) + .setActionDragAndDrop(FluidDisplaySlotWidget.Action.LOCK) + .setBeforeClick((clickData, widget) -> { + if (NetworkUtils.isClient()) { + // propagate display item content to actual fluid stored in this tank + setDrainableStack( + GT_Utility.getFluidFromDisplayStack(mInventory[getStackDisplaySlot()])); + } + return true; + }) + .setBackground(GT_UITextures.TRANSPARENT) + .setPos(149, 41)) + .widget(new TextWidget("Locked Fluid") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(101, 20)) + .widget(TextWidget.dynamicString(() -> { + ItemStack lockedDisplayStack = mInventory[getLockedDisplaySlot()]; + return lockedDisplayStack == null ? "None" : lockedDisplayStack.getDisplayName(); + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setTextAlignment(Alignment.CenterLeft) + .setMaxWidth(65) + .setPos(101, 30)) + // #updateFluidDisplayItem invalidates locked fluid slot + // if lockedFluidName == null or mMode is incorrect + .widget(new FakeSyncWidget.StringSyncer(() -> lockedFluidName, val -> lockedFluidName = val)) + .widget(new FakeSyncWidget.ByteSyncer(() -> mMode, val -> mMode = val)); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java index 5b08f7ae69..ad1c799708 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java @@ -4,20 +4,22 @@ import static gregtech.api.enums.Textures.BlockIcons.ITEM_OUT_SIGN; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.GT_Mod; -import gregtech.api.gui.*; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; import gregtech.api.util.extensions.ArrayExt; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { +public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch implements IAddUIWidgets { public GT_MetaTileEntity_Hatch_OutputBus(int aID, String aName, String aNameRegional, int aTier) { this(aID, aName, aNameRegional, aTier, getSlots(aTier)); } @@ -101,39 +103,10 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 0: - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - case 1: - return new GT_Container_2by2(aPlayerInventory, aBaseMetaTileEntity); - case 2: - return new GT_Container_3by3(aPlayerInventory, aBaseMetaTileEntity); - default: - return new GT_Container_4by4(aPlayerInventory, aBaseMetaTileEntity); - } - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - switch (mTier) { - case 0: - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, "Output Bus"); - case 1: - return new GT_GUIContainer_2by2(aPlayerInventory, aBaseMetaTileEntity, "Output Bus"); - case 2: - return new GT_GUIContainer_3by3(aPlayerInventory, aBaseMetaTileEntity, "Output Bus"); - default: - return new GT_GUIContainer_4by4(aPlayerInventory, aBaseMetaTileEntity, "Output Bus"); - } - } - /** * Attempt to store as many items as possible into the internal inventory of this output bus. * If you need atomicity you should use {@link gregtech.api.interfaces.tileentity.IHasInventory#addStackToSlot(int, ItemStack)} @@ -185,7 +158,8 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.isAllowedToWork() && (aTick & 0x7) == 0) { - IInventory tTileEntity = aBaseMetaTileEntity.getIInventoryAtSide(aBaseMetaTileEntity.getFrontFacing()); + final IInventory tTileEntity = + aBaseMetaTileEntity.getIInventoryAtSide(aBaseMetaTileEntity.getFrontFacing()); if (tTileEntity != null) { moveMultipleItemStacks( aBaseMetaTileEntity, @@ -208,4 +182,27 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch { } } } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + switch (mTier) { + case 0: + getBaseMetaTileEntity().add1by1Slot(builder); + break; + case 1: + getBaseMetaTileEntity().add2by2Slots(builder); + break; + case 2: + getBaseMetaTileEntity().add3by3Slots(builder); + break; + default: + getBaseMetaTileEntity().add4by4Slots(builder); + break; + } + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java index bf0ccd5001..c67785664c 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java @@ -5,12 +5,21 @@ import static mcp.mobius.waila.api.SpecialChars.GREEN; import static mcp.mobius.waila.api.SpecialChars.RED; import static mcp.mobius.waila.api.SpecialChars.RESET; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.DynamicPositionedColumn; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; -import gregtech.api.gui.GT_Container_MultiMachine; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.MetaTileEntity; @@ -19,13 +28,14 @@ import gregtech.api.util.*; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.common.GT_Pollution; import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_DrillerBase; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_LargeTurbine; import java.util.ArrayList; import java.util.List; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -36,7 +46,8 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; -public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { +public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity + implements IAddGregtechLogo, IAddUIWidgets { public static boolean disableMaintenance; public boolean mMachine = false, @@ -241,23 +252,11 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiblockDisplay.png"); - } - - @Override public byte getTileEntityBaseType() { return 2; } @@ -1261,7 +1260,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { tag.setInteger("maxProgress", mMaxProgresstime); tag.setBoolean("incompleteStructure", (getBaseMetaTileEntity().getErrorDisplayID() & 64) != 0); - IGregTechTileEntity tileEntity = getBaseMetaTileEntity(); + final IGregTechTileEntity tileEntity = getBaseMetaTileEntity(); if (tileEntity != null) { tag.setBoolean("isActive", tileEntity.isActive()); } @@ -1269,7 +1268,7 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { protected void setMufflers(boolean state) { for (GT_MetaTileEntity_Hatch_Muffler aMuffler : mMufflerHatches) { - IGregTechTileEntity iGTTileEntity = aMuffler.getBaseMetaTileEntity(); + final IGregTechTileEntity iGTTileEntity = aMuffler.getBaseMetaTileEntity(); if (iGTTileEntity != null && !iGTTileEntity.isDead()) { iGTTileEntity.setActive(state); } @@ -1286,4 +1285,121 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity { public List<GT_MetaTileEntity_Hatch> getExoticEnergyHatches() { return mExoticEnergyHatches; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 4) + .setSize(143, 75)); + final SlotWidget inventorySlot = new SlotWidget(inventoryHandler, 1); + builder.widget(inventorySlot.setPos(151, 4)); + + final DynamicPositionedColumn screenElements = new DynamicPositionedColumn(); + drawTexts(screenElements, inventorySlot); + builder.widget(screenElements); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) {} + + protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inventorySlot) { + screenElements.setSynced(false).setSpace(0).setPos(10, 7); + + screenElements + .widget(new TextWidget(GT_Utility.trans("132", "Pipe is loose.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mWrench)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mWrench, val -> mWrench = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("133", "Screws are loose.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mScrewdriver)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mScrewdriver, val -> mScrewdriver = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("134", "Something is stuck.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mSoftHammer)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSoftHammer, val -> mSoftHammer = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("135", "Platings are dented.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mHardHammer)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mHardHammer, val -> mHardHammer = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("136", "Circuitry burned out.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mSolderingTool)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mSolderingTool, val -> mSolderingTool = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("137", "That doesn't belong there.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mCrowbar)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mCrowbar, val -> mCrowbar = val)); + screenElements + .widget(new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mMachine)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)); + screenElements.widget(new TextWidget("Too Uncertain.") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> (getBaseMetaTileEntity().getErrorDisplayID() & 128) != 0)); + screenElements.widget(new TextWidget("Invalid Parameters.") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> (getBaseMetaTileEntity().getErrorDisplayID() & 256) != 0)); + + screenElements + .widget(new TextWidget(GT_Utility.trans("139", "Hit with Soft Mallet")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && !getBaseMetaTileEntity().isActive())) + .widget(new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val))) + .widget(new FakeSyncWidget.BooleanSyncer( + () -> getBaseMetaTileEntity().isActive(), + val -> getBaseMetaTileEntity().setActive(val))); + screenElements.widget(new TextWidget(GT_Utility.trans("140", "to (re-)start the Machine")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && !getBaseMetaTileEntity().isActive())); + screenElements.widget(new TextWidget(GT_Utility.trans("141", "if it doesn't start.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && !getBaseMetaTileEntity().isActive())); + screenElements.widget(new TextWidget(GT_Utility.trans("142", "Running perfectly.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && getBaseMetaTileEntity().isActive())); + + screenElements.widget(new TextWidget(GT_Utility.trans("143", "Missing Mining Pipe")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> { + if (getBaseMetaTileEntity().getErrorDisplayID() == 0 + && this instanceof GT_MetaTileEntity_DrillerBase) { + final ItemStack tItem = inventorySlot.getMcSlot().getStack(); + return tItem == null + || !GT_Utility.areStacksEqual(tItem, GT_ModHandler.getIC2Item("miningPipe", 1L)); + } + return false; + })); + screenElements.widget(new TextWidget(GT_Utility.trans("144", "Missing Turbine Rotor")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> { + if (getBaseMetaTileEntity().getErrorDisplayID() == 0 + && this instanceof GT_MetaTileEntity_LargeTurbine) { + final ItemStack tItem = inventorySlot.getMcSlot().getStack(); + return tItem == null + || !(tItem.getItem() == GT_MetaGenerated_Tool_01.INSTANCE + && tItem.getItemDamage() >= 170 + && tItem.getItemDamage() <= 177); + } + return false; + })); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java index 44d40e5a67..f146b39635 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_SpecialFilter.java @@ -1,14 +1,24 @@ package gregtech.api.metatileentity.implementations; -import gregtech.api.gui.GT_Container_SpecialFilter; -import gregtech.api.gui.GT_GUIContainer_SpecialFilter; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; +import gregtech.api.util.GT_Utility; +import java.util.Collections; +import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_Buffer { +public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_Buffer implements IAddUIWidgets { public static final int BUFFER_SLOT_COUNT = 9; public static final int SPECIAL_SLOT_INDEX = 9; public boolean bNBTAllowed = false; @@ -35,16 +45,6 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_ return aIndex < 9; } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_SpecialFilter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_SpecialFilter(aPlayerInventory, aBaseMetaTileEntity); - } - public abstract void clickTypeIcon(boolean aRightClick, ItemStack aHandStack); @Override @@ -69,4 +69,87 @@ public abstract class GT_MetaTileEntity_SpecialFilter extends GT_MetaTileEntity_ } protected abstract boolean isStackAllowed(ItemStack aStack); + + protected List<Text> getEmptySlotTooltip() { + return null; + } + + protected List<String> getItemExtraTooltip() { + return null; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + addEmitEnergyButton(builder); + addEmitRedstoneButton(builder); + addInvertRedstoneButton(builder); + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bInvertFilter = !bInvertFilter; + if (bInvertFilter) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("124", "Invert Filter")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), + GT_Utility.trans("125", "Don't invert Filter")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_FILTER) + .setPos(61, 62) + .setSize(18, 18)) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bNBTAllowed = !bNBTAllowed; + if (bNBTAllowed) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("126", "Ignore NBT")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("127", "NBT has to match")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_NBT) + .setPos(79, 62) + .setSize(18, 18)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(27, false)) + .setPos(6, 19) + .setSize(27, 24)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_BLUE.apply(42, true)) + .setPos(53, 19) + .setSize(42, 24)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_RED.apply(19, true)) + .setPos(152, 19) + .setSize(19, 24)) + .widget( + new SlotWidget(BaseSlot.phantom(inventoryHandler, 9)) { + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + clickTypeIcon(clickData.mouseButton != 0, cursorStack); + } + + @Override + public void buildTooltip(List<Text> tooltip) { + if (getEmptySlotTooltip() != null) { + tooltip.addAll(getEmptySlotTooltip()); + } + super.buildTooltip(tooltip); + } + + @Override + public List<String> getExtraTooltip() { + if (getItemExtraTooltip() != null) { + return getItemExtraTooltip(); + } + return Collections.emptyList(); + } + }.disableShiftInsert().setPos(34, 22).setBackground(GT_UITextures.BUTTON_STANDARD)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .endAtSlot(8) + .build() + .setPos(97, 4)); + } } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_TieredMachineBlock.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_TieredMachineBlock.java index a4d6fc0e6b..4b01454a02 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_TieredMachineBlock.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_TieredMachineBlock.java @@ -1,7 +1,13 @@ package gregtech.api.metatileentity.implementations; import static gregtech.api.enums.GT_Values.GT; +import static gregtech.api.metatileentity.BaseTileEntity.BATTERY_SLOT_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.BATTERY_SLOT_TOOLTIP_ALT; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom; @@ -111,4 +117,36 @@ public abstract class GT_MetaTileEntity_TieredMachineBlock extends MetaTileEntit * @param aTextures is the optional Array you can give to the Constructor. */ public abstract ITexture[][][] getTextureSet(ITexture[] aTextures); + + protected SlotWidget createChargerSlot(int x, int y) { + final String batterySlotTooltipKey; + final Object[] batterySlotTooltipArgs; + final String pTier1 = powerTierName(mTier); + if (mTier == GT_Values.VN.length - 1) { + batterySlotTooltipKey = BATTERY_SLOT_TOOLTIP_ALT; + batterySlotTooltipArgs = new String[] {pTier1}; + } else { + batterySlotTooltipKey = BATTERY_SLOT_TOOLTIP; + batterySlotTooltipArgs = new String[] {pTier1, powerTierName((byte) (mTier + 1))}; + } + return createChargerSlot(x, y, batterySlotTooltipKey, batterySlotTooltipArgs); + } + + protected SlotWidget createChargerSlot(int x, int y, String tooltipKey, Object[] tooltipArgs) { + return (SlotWidget) new SlotWidget(inventoryHandler, rechargerSlotStartIndex()) + .disableShiftInsert() + .setGTTooltip(() -> mTooltipCache.getData(tooltipKey, tooltipArgs)) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_CHARGER) + .setPos(x, y); + } + + /** + * Apply proper coloration to a machine's power tier short name + * @param machineTier + * @return colored power tier short name + */ + private String powerTierName(byte machineTier) { + return GT_Values.TIER_COLORS[machineTier] + GT_Values.VN[machineTier]; + } } diff --git a/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java b/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java index 385ae310f1..8161680b1e 100644 --- a/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java +++ b/src/main/java/gregtech/api/multitileentity/base/BaseMultiTileEntity.java @@ -251,6 +251,11 @@ public abstract class BaseMultiTileEntity extends CoverableTileEntity } @Override + public boolean useModularUI() { + return true; + } + + @Override public long getTimer() { return 0; } @@ -1373,4 +1378,9 @@ public abstract class BaseMultiTileEntity extends CoverableTileEntity return getCoverBehaviorAtSideNew(aSide) .letsItemsOut(aSide, getCoverIDAtSide(aSide), getComplexCoverDataAtSide(aSide), aSlot, this); } + + @Override + public ItemStack getStackForm(long aAmount) { + return new ItemStack(Item.getItemById(getMultiTileEntityRegistryID()), (int) aAmount, getMultiTileEntityID()); + } } diff --git a/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java index 9f32ad4bae..62ff6bd7e9 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java +++ b/src/main/java/gregtech/api/net/GT_Packet_GtTileEntityGuiRequest.java @@ -2,6 +2,7 @@ package gregtech.api.net; import com.google.common.io.ByteArrayDataInput; import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.common.GT_Proxy; import io.netty.buffer.ByteBuf; @@ -103,7 +104,11 @@ public class GT_Packet_GtTileEntityGuiRequest extends GT_Packet_New { parentGuiId); GT_Values.NW.sendToPlayer(packet, player); } else if (guiId == 0) { - gtTile.openGUI(player); + if (gtTile.getMetaTileEntity() != null && gtTile.getMetaTileEntity().useModularUI()) { + GT_UIInfos.openGTTileEntityUI(gtTile, player); + } else { + gtTile.openGUI(player); + } } } } diff --git a/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java b/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java index 0561b18ac1..eff095b0fc 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java +++ b/src/main/java/gregtech/api/net/GT_Packet_SetConfigurationCircuit.java @@ -2,9 +2,10 @@ package gregtech.api.net; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.ByteBufUtils; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; -import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IHasInventory; +import gregtech.api.metatileentity.BaseTileEntity; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import io.netty.buffer.ByteBuf; @@ -35,6 +36,10 @@ public class GT_Packet_SetConfigurationCircuit extends GT_Packet_New { this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit); } + public GT_Packet_SetConfigurationCircuit(BaseTileEntity tile, ItemStack circuit) { + this(tile.getXCoord(), tile.getYCoord(), tile.getZCoord(), circuit); + } + public GT_Packet_SetConfigurationCircuit(int x, short y, int z, ItemStack circuit) { super(false); @@ -84,18 +89,18 @@ public class GT_Packet_SetConfigurationCircuit extends GT_Packet_New { @Override public void process(IBlockAccess aWorld) { - World world = DimensionManager.getWorld(dimId); + final World world = DimensionManager.getWorld(dimId); if (world == null) return; - TileEntity tile = world.getTileEntity(mX, mY, mZ); - if (!(tile instanceof IGregTechTileEntity) || ((IGregTechTileEntity) tile).isDead()) return; - IMetaTileEntity mte = ((IGregTechTileEntity) tile).getMetaTileEntity(); - if (!(mte instanceof IConfigurationCircuitSupport)) return; - IConfigurationCircuitSupport machine = (IConfigurationCircuitSupport) mte; + + final TileEntity tile = world.getTileEntity(mX, mY, mZ); + if (!(tile instanceof BaseTileEntity) || ((BaseTileEntity) tile).isDead()) return; + + final IConfigurationCircuitSupport machine = ((BaseTileEntity) tile).getConfigurationCircuitSupport(); + if (machine == null) return; if (!machine.allowSelectCircuit()) return; machine.getConfigurationCircuits().stream() .filter(stack -> GT_Utility.areStacksEqual(stack, circuit)) .findFirst() - .ifPresent(stack -> - ((IGregTechTileEntity) tile).setInventorySlotContents(machine.getCircuitSlot(), stack)); + .ifPresent(stack -> ((IHasInventory) tile).setInventorySlotContents(machine.getCircuitSlot(), stack)); } } diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java index e190648bef..65194a7390 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java +++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntityCoverGUI.java @@ -188,35 +188,23 @@ public class GT_Packet_TileEntityCoverGUI extends GT_Packet_New { IGregTechTileEntity gtTile = ((IGregTechTileEntity) tile); gtTile.setCoverDataAtSide(side, coverData); // Set it client side to read later. - GuiScreen gui = (GuiScreen) getCoverGUI(side, thePlayer, thePlayer.worldObj, gtTile); - // If it's one of this mod's covers, tell it to exit to the GUI with the specified ID (-1 is ignored) - if (gui instanceof GT_GUICover) { - ((GT_GUICover) gui).setParentGuiId(parentGuiId); + GT_CoverBehaviorBase<?> cover = gtTile.getCoverBehaviorAtSideNew(side); + if (cover.hasCoverGUI()) { + GuiScreen gui = (GuiScreen) cover.getClientGUI( + side, + gtTile.getCoverIDAtSide(side), + gtTile.getComplexCoverDataAtSide(side), + gtTile, + thePlayer, + thePlayer.worldObj); + // If it's one of this mod's covers, tell it to exit to the GUI with the specified ID (-1 is + // ignored) + if (gui instanceof GT_GUICover) { + ((GT_GUICover) gui).setParentGuiId(parentGuiId); + } + Minecraft.getMinecraft().displayGuiScreen(gui); } - Minecraft.getMinecraft().displayGuiScreen(gui); } } } - - /** - * Gets the specified cover's GUI object, if one exists - * @param aSide Block side (0 through 5) - * @param aPlayer Current player - * @param aWorld Current world - * @param aGtTile IGregTechTileEntity instance - * @return The specified cover's GUI, if one exists - */ - private Object getCoverGUI(byte aSide, EntityPlayer aPlayer, World aWorld, IGregTechTileEntity aGtTile) { - GT_CoverBehaviorBase<?> cover = aGtTile.getCoverBehaviorAtSideNew(aSide); - if (cover.hasCoverGUI()) { - return cover.getClientGUI( - aSide, - aGtTile.getCoverIDAtSide(aSide), - aGtTile.getComplexCoverDataAtSide(aSide), - aGtTile, - aPlayer, - aWorld); - } - return null; - } } diff --git a/src/main/java/gregtech/api/objects/GT_Cover_None.java b/src/main/java/gregtech/api/objects/GT_Cover_None.java index dac48449d1..e0cd5aa061 100644 --- a/src/main/java/gregtech/api/objects/GT_Cover_None.java +++ b/src/main/java/gregtech/api/objects/GT_Cover_None.java @@ -7,7 +7,6 @@ import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.ISerializableObject; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; public class GT_Cover_None extends GT_CoverBehavior { @@ -161,17 +160,6 @@ public class GT_Cover_None extends GT_CoverBehavior { } @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - ISerializableObject.LegacyCoverData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return null; - } - - @Override protected boolean onCoverRemovalImpl( byte aSide, int aCoverID, diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java index 3bbb4f9ae5..f3b8f7a9fb 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -3,6 +3,7 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.E; import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCoverGUI; @@ -28,7 +29,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl super(ISerializableObject.LegacyCoverData.class, coverTexture); } - private static int convert(ISerializableObject.LegacyCoverData data) { + protected static int convert(ISerializableObject.LegacyCoverData data) { return data == null ? 0 : data.get(); } @@ -106,6 +107,7 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl return onCoverShiftRightclick(aSide, aCoverID, convert(aCoverVariable), aTileEntity, aPlayer); } + @Deprecated @Override protected Object getClientGUIImpl( byte aSide, @@ -318,15 +320,20 @@ public abstract class GT_CoverBehavior extends GT_CoverBehaviorBase<ISerializabl if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { lastPlayer = aPlayer; mPlayerNotified = false; - GT_Values.NW.sendToPlayer( - new GT_Packet_TileEntityCoverGUI( - aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), - (EntityPlayerMP) aPlayer); + if (useModularUI()) { + GT_UIInfos.openCoverUI(aTileEntity, aPlayer, aSide); + } else { + GT_Values.NW.sendToPlayer( + new GT_Packet_TileEntityCoverGUI( + aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), + (EntityPlayerMP) aPlayer); + } return true; } return false; } + @Deprecated public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { return null; } diff --git a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java index 1092a24307..b793a9b489 100644 --- a/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java +++ b/src/main/java/gregtech/api/util/GT_CoverBehaviorBase.java @@ -2,11 +2,22 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.E; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; +import gregtech.api.gui.GT_GUIColorOverride; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.net.GT_Packet_TileEntityCoverGUI; import gregtech.api.objects.GT_ItemStack; +import java.util.function.Supplier; +import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -34,6 +45,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { protected GT_CoverBehaviorBase(Class<T> typeToken, ITexture coverTexture) { this.typeToken = typeToken; this.coverFGTexture = coverTexture; + this.colorOverride = new GT_GUIColorOverride(guiTexturePath); } public abstract T createDataObject(int aLegacyData); @@ -216,6 +228,7 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { return onCoverShiftRightClickImpl(aSide, aCoverID, forceCast(aCoverVariable), aTileEntity, aPlayer); } + @Deprecated public final Object getClientGUI( byte aSide, int aCoverID, @@ -404,6 +417,136 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { } // endregion + // region UI stuff + + protected GT_TooltipDataCache mTooltipCache = new GT_TooltipDataCache(); + protected GT_GUIColorOverride colorOverride; + private static final String guiTexturePath = "gregtech:textures/gui/GuiCover.png"; + + /** + * For back compatibility, you need to override this if this cover uses ModularUI. + */ + public boolean useModularUI() { + return false; + } + + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new UIFactory(buildContext).createWindow(); + } + + /** + * Creates {@link ModularWindow} for this cover. + * This is separated from base class, as attaching the same covers in different sides of the same tile + * needs different UI with different context. + */ + protected class UIFactory { + + private final GT_CoverUIBuildContext uiBuildContext; + + public UIFactory(GT_CoverUIBuildContext buildContext) { + this.uiBuildContext = buildContext; + } + + public ModularWindow createWindow() { + ModularWindow.Builder builder = ModularWindow.builder(getGUIWidth(), getGUIHeight()); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + builder.setGuiTint(getUIBuildContext().getGuiColorization()); + if (doesBindPlayerInventory() && !getUIBuildContext().isAnotherWindow()) { + builder.bindPlayerInventory(getUIBuildContext().getPlayer()); + } + addTitleToUI(builder); + addUIWidgets(builder); + if (getUIBuildContext().isAnotherWindow()) { + builder.widget(ButtonWidget.closeWindowButton(true).setPos(getGUIWidth() - 15, 3)); + } + return builder.build(); + } + + /** + * Override this to add widgets for your UI. + */ + protected void addUIWidgets(ModularWindow.Builder builder) {} + + public GT_CoverUIBuildContext getUIBuildContext() { + return uiBuildContext; + } + + /** + * Can return null when cover data is invalid e.g. tile is broken or cover is removed + */ + @Nullable + public T getCoverData() { + if (isCoverValid()) { + return forceCast(getUIBuildContext() + .getTile() + .getComplexCoverDataAtSide(getUIBuildContext().getCoverSide())); + } else { + return null; + } + } + + public boolean setCoverData(T data) { + if (isCoverValid()) { + getUIBuildContext() + .getTile() + .receiveCoverData( + getUIBuildContext().getCoverSide(), + getUIBuildContext().getCoverID(), + data, + getUIBuildContext().getPlayer() instanceof EntityPlayerMP + ? (EntityPlayerMP) getUIBuildContext().getPlayer() + : null); + return true; + } else { + return false; + } + } + + public boolean isCoverValid() { + return !getUIBuildContext().getTile().isDead() + && getUIBuildContext() + .getTile() + .getCoverBehaviorAtSideNew( + getUIBuildContext().getCoverSide()) + != GregTech_API.sNoBehavior; + } + + protected void addTitleToUI(ModularWindow.Builder builder) { + ItemStack coverItem = GT_Utility.intToStack(getUIBuildContext().getCoverID()); + if (coverItem != null) { + builder.widget(new ItemDrawable(coverItem) + .asWidget() + .setPos(5, 5) + .setSize(16, 16)) + .widget(new TextWidget(coverItem.getDisplayName()) + .setDefaultColor(COLOR_TITLE.get()) + .setPos(25, 9)); + } + } + + protected int getGUIWidth() { + return 176; + } + + protected int getGUIHeight() { + return 107; + } + + protected boolean doesBindPlayerInventory() { + return false; + } + + protected int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); + } + + protected Supplier<Integer> COLOR_TITLE = () -> getTextColorOrDefault("title", 0x222222); + protected Supplier<Integer> COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x555555); + protected Supplier<Integer> COLOR_TEXT_WARN = () -> getTextColorOrDefault("text_warn", 0xff0000); + } + + // endregion + // region impl protected Block getFacadeBlockImpl(byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity) { @@ -494,15 +637,20 @@ public abstract class GT_CoverBehaviorBase<T extends ISerializableObject> { byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer) { if (hasCoverGUI() && aPlayer instanceof EntityPlayerMP) { lastPlayer = aPlayer; - GT_Values.NW.sendToPlayer( - new GT_Packet_TileEntityCoverGUI( - aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), - (EntityPlayerMP) aPlayer); + if (useModularUI()) { + GT_UIInfos.openCoverUI(aTileEntity, aPlayer, aSide); + } else { + GT_Values.NW.sendToPlayer( + new GT_Packet_TileEntityCoverGUI( + aSide, aCoverID, aCoverVariable, aTileEntity, (EntityPlayerMP) aPlayer), + (EntityPlayerMP) aPlayer); + } return true; } return false; } + @Deprecated protected Object getClientGUIImpl( byte aSide, int aCoverID, T aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, World aWorld) { return null; diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index a498754451..40ba7fe60f 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -3,11 +3,26 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.*; import codechicken.nei.PositionedStack; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; +import gnu.trove.map.TByteObjectMap; +import gnu.trove.map.hash.TByteObjectHashMap; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.*; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.SteamTexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; import gregtech.api.objects.GT_FluidStack; @@ -15,11 +30,15 @@ import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; import gregtech.api.util.extensions.ArrayExt; +import gregtech.common.gui.modularui.UIHelper; import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Replicator; -import gregtech.nei.GT_NEI_DefaultHandler.FixedPositionedStack; import ic2.core.Ic2Items; +import java.awt.*; import java.util.*; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Supplier; +import javax.annotation.Nullable; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -30,6 +49,8 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -721,7 +742,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } /** - * Use {@link GT_Recipe_Map#getInputPositionedStacks(GT_Recipe)} instead + * Use {@link GT_Recipe_Map#getItemInputPositions} or {@link GT_Recipe_Map#getSpecialItemPosition} or {@link GT_Recipe_Map#getFluidInputPositions} instead */ @SuppressWarnings("DeprecatedIsStillUsed") @Deprecated @@ -730,7 +751,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } /** - * Use {@link GT_Recipe_Map#getOutputPositionedStacks(GT_Recipe)} instead + * Use {@link GT_Recipe_Map#getItemOutputPositions} or {@link GT_Recipe_Map#getFluidOutputPositions} instead */ @SuppressWarnings("DeprecatedIsStillUsed") @Deprecated @@ -974,6 +995,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } } + @SuppressWarnings("StaticInitializerReferencesSubClass") public static class GT_Recipe_Map { /** * Contains all Recipe Maps @@ -985,117 +1007,139 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public static final Map<String, GT_Recipe_Map> sIndexedMappings = new HashMap<>(); public static final GT_Recipe_Map sOreWasherRecipes = new GT_Recipe_Map( - new HashSet<>(500), - "gt.recipe.orewasher", - "Ore Washing Plant", - null, - RES_PATH_GUI + "basicmachines/OreWasher", - 1, - 3, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(500), + "gt.recipe.orewasher", + "Ore Washing Plant", + null, + RES_PATH_GUI + "basicmachines/OreWasher", + 1, + 3, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_BATH, ProgressBar.Direction.CIRCULAR_CW); public static final GT_Recipe_Map sThermalCentrifugeRecipes = new GT_Recipe_Map( - new HashSet<>(1000), - "gt.recipe.thermalcentrifuge", - "Thermal Centrifuge", - null, - RES_PATH_GUI + "basicmachines/ThermalCentrifuge", - 1, - 3, - 1, - 0, - 2, - E, - 1, - E, - true, - true); + new HashSet<>(1000), + "gt.recipe.thermalcentrifuge", + "Thermal Centrifuge", + null, + RES_PATH_GUI + "basicmachines/ThermalCentrifuge", + 1, + 3, + 1, + 0, + 2, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sCompressorRecipes = new GT_Recipe_Map( - new HashSet<>(750), - "gt.recipe.compressor", - "Compressor", - null, - RES_PATH_GUI + "basicmachines/Compressor", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(750), + "gt.recipe.compressor", + "Compressor", + null, + RES_PATH_GUI + "basicmachines/Compressor", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_COMPRESSOR) + .setProgressBar(GT_UITextures.PROGRESSBAR_COMPRESS, ProgressBar.Direction.RIGHT) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_COMPRESSOR_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_COMPRESS_STEAM); public static final GT_Recipe_Map sExtractorRecipes = new GT_Recipe_Map( - new HashSet<>(250), - "gt.recipe.extractor", - "Extractor", - null, - RES_PATH_GUI + "basicmachines/Extractor", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(250), + "gt.recipe.extractor", + "Extractor", + null, + RES_PATH_GUI + "basicmachines/Extractor", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_EXTRACT_STEAM); public static final GT_Recipe_Map sRecyclerRecipes = new GT_Recipe_Map_Recycler( - new HashSet<>(0), - "ic.recipe.recycler", - "Recycler", - "ic2.recycler", - RES_PATH_GUI + "basicmachines/Recycler", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false); + new HashSet<>(0), + "ic.recipe.recycler", + "Recycler", + "ic2.recycler", + RES_PATH_GUI + "basicmachines/Recycler", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + false) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_RECYCLE) + .setProgressBar(GT_UITextures.PROGRESSBAR_RECYCLE, ProgressBar.Direction.CIRCULAR_CW); public static final GT_Recipe_Map sFurnaceRecipes = new GT_Recipe_Map_Furnace( - new HashSet<>(0), - "mc.recipe.furnace", - "Furnace", - "smelting", - RES_PATH_GUI + "basicmachines/E_Furnace", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false); + new HashSet<>(0), + "mc.recipe.furnace", + "Furnace", + "smelting", + RES_PATH_GUI + "basicmachines/E_Furnace", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + false) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_FURNACE) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_FURNACE_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_ARROW_STEAM); public static final GT_Recipe_Map sMicrowaveRecipes = new GT_Recipe_Map_Microwave( - new HashSet<>(0), - "gt.recipe.microwave", - "Microwave", - "smelting", - RES_PATH_GUI + "basicmachines/E_Furnace", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false); + new HashSet<>(0), + "gt.recipe.microwave", + "Microwave", + "smelting", + RES_PATH_GUI + "basicmachines/E_Furnace", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + false) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_FURNACE) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); /** Set {@code aSpecialValue = -100} to bypass the disassembler tier check and default recipe duration. */ public static final GT_Recipe_Map sDisassemblerRecipes = new GT_Recipe_Map( @@ -1113,590 +1157,712 @@ public class GT_Recipe implements Comparable<GT_Recipe> { 1, E, true, - false); + false) { + @Override + public IDrawable getOverlayForSlot(boolean isFluid, boolean isOutput, int index, boolean isSpecial) { + if (isOutput) { + switch (index) { + case 0: + case 2: + case 6: + case 8: + return GT_UITextures.OVERLAY_SLOT_CIRCUIT; + case 4: + return GT_UITextures.OVERLAY_SLOT_WRENCH; + } + } + return super.getOverlayForSlot(isFluid, isOutput, index, isSpecial); + } + }.setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_WRENCH) + .setProgressBar(GT_UITextures.PROGRESSBAR_ASSEMBLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sScannerFakeRecipes = new GT_Recipe_Map( - new HashSet<>(300), - "gt.recipe.scanner", - "Scanner", - null, - RES_PATH_GUI + "basicmachines/Scanner", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(300), + "gt.recipe.scanner", + "Scanner", + null, + RES_PATH_GUI + "basicmachines/Scanner", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_MICROSCOPE) + .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map( - new HashSet<>(200), - "gt.recipe.rockbreaker", - "Rock Breaker", - null, - RES_PATH_GUI + "basicmachines/RockBreaker", - 1, - 1, - 0, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(200), + "gt.recipe.rockbreaker", + "Rock Breaker", + null, + RES_PATH_GUI + "basicmachines/RockBreaker", + 2, + 1, + 0, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) + .setProgressBar(GT_UITextures.PROGRESSBAR_MACERATE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sByProductList = new GT_Recipe_Map( - new HashSet<>(1000), - "gt.recipe.byproductlist", - "Ore Byproduct List", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 6, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(1000), + "gt.recipe.byproductlist", + "Ore Byproduct List", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 6, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sReplicatorFakeRecipes = new ReplicatorFakeMap( - new HashSet<>(100), - "gt.recipe.replicator", - "Replicator", - null, - RES_PATH_GUI + "basicmachines/Replicator", - 0, - 1, - 0, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(100), + "gt.recipe.replicator", + "Replicator", + null, + RES_PATH_GUI + "basicmachines/Replicator", + 0, + 1, + 0, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_UUM) + .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); // public static final GT_Recipe_Map sAssemblylineFakeRecipes = new GT_Recipe_Map(new HashSet<>(30), // "gt.recipe.scanner", "Scanner", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 1, 0, 1, E, 1, E, true, // true); - public static final GT_Recipe_Map sAssemblylineVisualRecipes = new GT_Recipe_Map( - new HashSet<>(110), - "gt.recipe.fakeAssemblylineProcess", - "Assemblyline Process", - null, - RES_PATH_GUI + "FakeAssemblyline", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - false); + public static final GT_Recipe_Map sAssemblylineVisualRecipes = new GT_Recipe_Map_AssemblyLineFake( + new HashSet<>(110), + "gt.recipe.fakeAssemblylineProcess", + "Assemblyline Process", + null, + RES_PATH_GUI + "FakeAssemblyline", + 16, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_ORB) + .setUsualFluidInputCount(4); public static final GT_Recipe_Map sPlasmaArcFurnaceRecipes = new GT_Recipe_Map( - new HashSet<>(20000), - "gt.recipe.plasmaarcfurnace", - "Plasma Arc Furnace", - null, - RES_PATH_GUI + "basicmachines/PlasmaArcFurnace", - 1, - 4, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(20000), + "gt.recipe.plasmaarcfurnace", + "Plasma Arc Furnace", + null, + RES_PATH_GUI + "basicmachines/PlasmaArcFurnace", + 1, + 4, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sArcFurnaceRecipes = new GT_Recipe_Map( - new HashSet<>(20000), - "gt.recipe.arcfurnace", - "Arc Furnace", - null, - RES_PATH_GUI + "basicmachines/ArcFurnace", - 1, - 4, - 1, - 1, - 3, - E, - 1, - E, - true, - true); + new HashSet<>(20000), + "gt.recipe.arcfurnace", + "Arc Furnace", + null, + RES_PATH_GUI + "basicmachines/ArcFurnace", + 1, + 4, + 1, + 1, + 3, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sPrinterRecipes = new GT_Recipe_Map_Printer( - new HashSet<>(5), - "gt.recipe.printer", - "Printer", - null, - RES_PATH_GUI + "basicmachines/Printer", - 1, - 1, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(5), + "gt.recipe.printer", + "Printer", + null, + RES_PATH_GUI + "basicmachines/Printer", + 1, + 1, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_PAGE_BLANK) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_PAGE_PRINTED) + .setSlotOverlay(false, false, true, true, GT_UITextures.OVERLAY_SLOT_DATA_STICK) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sSifterRecipes = new GT_Recipe_Map( - new HashSet<>(105), - "gt.recipe.sifter", - "Sifter", - null, - RES_PATH_GUI + "basicmachines/Sifter", - 1, - 9, - 0, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(105), + "gt.recipe.sifter", + "Sifter", + null, + RES_PATH_GUI + "basicmachines/Sifter", + 1, + 9, + 0, + 0, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_SIFT, ProgressBar.Direction.DOWN); public static final GT_Recipe_Map sPressRecipes = new GT_Recipe_Map_FormingPress( - new HashSet<>(300), - "gt.recipe.press", - "Forming Press", - null, - RES_PATH_GUI + "basicmachines/Press", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(300), + "gt.recipe.press", + "Forming Press", + null, + RES_PATH_GUI + "basicmachines/Press", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_PRESS_1) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_PRESS_2) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_PRESS_3) + .setProgressBar(GT_UITextures.PROGRESSBAR_COMPRESS, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sLaserEngraverRecipes = new GT_Recipe_Map( - new HashSet<>(810), - "gt.recipe.laserengraver", - "Precision Laser Engraver", - null, - RES_PATH_GUI + "basicmachines/LaserEngraverNEI", - 2, - 1, - 0, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(810), + "gt.recipe.laserengraver", + "Precision Laser Engraver", + null, + RES_PATH_GUI + "basicmachines/LaserEngraverNEI", + 2, + 1, + 0, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_LENS) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(2) + .setUsualFluidOutputCount(2); public static final GT_Recipe_Map sMixerRecipes = new GT_Recipe_Map( - new HashSet<>(900), - "gt.recipe.mixer", - "Mixer", - null, - RES_PATH_GUI + "basicmachines/Mixer6", - 9, - 4, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(900), + "gt.recipe.mixer", + "Mixer", + null, + RES_PATH_GUI + "basicmachines/Mixer6", + 9, + 4, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_MIXER, ProgressBar.Direction.CIRCULAR_CW); public static final GT_Recipe_Map sAutoclaveRecipes = new GT_Recipe_Map( - new HashSet<>(300), - "gt.recipe.autoclave", - "Autoclave", - null, - RES_PATH_GUI + "basicmachines/Autoclave4", - 2, - 4, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(300), + "gt.recipe.autoclave", + "Autoclave", + null, + RES_PATH_GUI + "basicmachines/Autoclave4", + 2, + 4, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setSlotOverlay(false, true, true, GT_UITextures.OVERLAY_SLOT_GEM) + .setSlotOverlay(false, true, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sElectroMagneticSeparatorRecipes = new GT_Recipe_Map( - new HashSet<>(50), - "gt.recipe.electromagneticseparator", - "Electromagnetic Separator", - null, - RES_PATH_GUI + "basicmachines/ElectromagneticSeparator", - 1, - 3, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(50), + "gt.recipe.electromagneticseparator", + "Electromagnetic Separator", + null, + RES_PATH_GUI + "basicmachines/ElectromagneticSeparator", + 1, + 3, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_MAGNET, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sPolarizerRecipes = new GT_Recipe_Map( - new HashSet<>(300), - "gt.recipe.polarizer", - "Electromagnetic Polarizer", - null, - RES_PATH_GUI + "basicmachines/Polarizer", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(300), + "gt.recipe.polarizer", + "Electromagnetic Polarizer", + null, + RES_PATH_GUI + "basicmachines/Polarizer", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_MAGNET, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sMaceratorRecipes = new GT_Recipe_Map_Macerator( - new HashSet<>(16600), - "gt.recipe.macerator", - "Pulverization", - null, - RES_PATH_GUI + "basicmachines/Macerator4", - 1, - 4, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(16600), + "gt.recipe.macerator", + "Pulverization", + null, + RES_PATH_GUI + "basicmachines/Macerator4", + 1, + 4, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_MACERATE, ProgressBar.Direction.RIGHT) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_CRUSHED_ORE_STEAM) + .setSlotOverlaySteam(true, GT_UITextures.OVERLAY_SLOT_DUST_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_MACERATE_STEAM); public static final GT_Recipe_Map sChemicalBathRecipes = new GT_Recipe_Map( - new HashSet<>(2550), - "gt.recipe.chemicalbath", - "Chemical Bath", - null, - RES_PATH_GUI + "basicmachines/ChemicalBath", - 1, - 3, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(2550), + "gt.recipe.chemicalbath", + "Chemical Bath", + null, + RES_PATH_GUI + "basicmachines/ChemicalBath", + 1, + 3, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_BATH, ProgressBar.Direction.CIRCULAR_CW); public static final GT_Recipe_Map sFluidCannerRecipes = new GT_Recipe_Map_FluidCanner( - new HashSet<>(2100), - "gt.recipe.fluidcanner", - "Fluid Canning Machine", - null, - RES_PATH_GUI + "basicmachines/FluidCanner", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(2100), + "gt.recipe.fluidcanner", + "Fluid Canning Machine", + null, + RES_PATH_GUI + "basicmachines/FluidCanner", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setProgressBar(GT_UITextures.PROGRESSBAR_CANNER, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sBrewingRecipes = new GT_Recipe_Map( - new HashSet<>(450), - "gt.recipe.brewer", - "Brewing Machine", - null, - RES_PATH_GUI + "basicmachines/PotionBrewer", - 1, - 0, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(450), + "gt.recipe.brewer", + "Brewing Machine", + null, + RES_PATH_GUI + "basicmachines/PotionBrewer", + 1, + 0, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CAULDRON) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sFluidHeaterRecipes = new GT_Recipe_Map( - new HashSet<>(10), - "gt.recipe.fluidheater", - "Fluid Heater", - null, - RES_PATH_GUI + "basicmachines/FluidHeater", - 1, - 0, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(10), + "gt.recipe.fluidheater", + "Fluid Heater", + null, + RES_PATH_GUI + "basicmachines/FluidHeater", + 1, + 0, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_HEATER_1) + .setSlotOverlay(true, true, GT_UITextures.OVERLAY_SLOT_HEATER_2) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sDistilleryRecipes = new GT_Recipe_Map( - new HashSet<>(400), - "gt.recipe.distillery", - "Distillery", - null, - RES_PATH_GUI + "basicmachines/Distillery", - 1, - 1, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(400), + "gt.recipe.distillery", + "Distillery", + null, + RES_PATH_GUI + "basicmachines/Distillery", + 1, + 1, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_BEAKER_1) + .setSlotOverlay(true, true, GT_UITextures.OVERLAY_SLOT_BEAKER_2) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sFermentingRecipes = new GT_Recipe_Map( - new HashSet<>(50), - "gt.recipe.fermenter", - "Fermenter", - null, - RES_PATH_GUI + "basicmachines/Fermenter", - 0, - 0, - 0, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(50), + "gt.recipe.fermenter", + "Fermenter", + null, + RES_PATH_GUI + "basicmachines/Fermenter", + 0, + 0, + 0, + 1, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sFluidSolidficationRecipes = new GT_Recipe_Map( - new HashSet<>(35000), - "gt.recipe.fluidsolidifier", - "Fluid Solidifier", - null, - RES_PATH_GUI + "basicmachines/FluidSolidifier", - 1, - 1, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(35000), + "gt.recipe.fluidsolidifier", + "Fluid Solidifier", + null, + RES_PATH_GUI + "basicmachines/FluidSolidifier", + 1, + 1, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_MOLD) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sFluidExtractionRecipes = new GT_Recipe_Map( - new HashSet<>(15000), - "gt.recipe.fluidextractor", - "Fluid Extractor", - null, - RES_PATH_GUI + "basicmachines/FluidExtractor", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(15000), + "gt.recipe.fluidextractor", + "Fluid Extractor", + null, + RES_PATH_GUI + "basicmachines/FluidExtractor", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sBoxinatorRecipes = new GT_Recipe_Map( - new HashSet<>(2500), - "gt.recipe.packager", - "Packager", - null, - RES_PATH_GUI + "basicmachines/Packager", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(2500), + "gt.recipe.packager", + "Packager", + null, + RES_PATH_GUI + "basicmachines/Packager", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_BOX) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_BOXED) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sUnboxinatorRecipes = new GT_Recipe_Map_Unboxinator( - new HashSet<>(2500), - "gt.recipe.unpackager", - "Unpackager", - null, - RES_PATH_GUI + "basicmachines/Unpackager", - 1, - 2, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(2500), + "gt.recipe.unpackager", + "Unpackager", + null, + RES_PATH_GUI + "basicmachines/Unpackager", + 1, + 2, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_BOXED) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sFusionRecipes = new GT_Recipe_Map( - new HashSet<>(50), - "gt.recipe.fusionreactor", - "Fusion Reactor", - null, - RES_PATH_GUI + "basicmachines/FusionReactor", - 0, - 0, - 0, - 2, - 1, - "Start: ", - 1, - " EU", - true, - true); + new HashSet<>(50), + "gt.recipe.fusionreactor", + "Fusion Reactor", + null, + RES_PATH_GUI + "basicmachines/FusionReactor", + 0, + 0, + 0, + 2, + 1, + "Start: ", + 1, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(2); public static final GT_Recipe_Map sComplexFusionRecipes = new GT_Recipe_Map_ComplexFusion( - new HashSet<>(50), - "gt.recipe.complexfusionreactor", - "Complex Fusion Reactor", - null, - RES_PATH_GUI + "basicmachines/ComplexFusionReactor", - 3, - 0, - 0, - 2, - 1, - "Start: ", - 1, - " EU", - true, - true); + new HashSet<>(50), + "gt.recipe.complexfusionreactor", + "Complex Fusion Reactor", + null, + RES_PATH_GUI + "basicmachines/ComplexFusionReactor", + 3, + 0, + 0, + 2, + 1, + "Start: ", + 1, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(16) + .setUsualFluidOutputCount(16) + .setNEITransferRect(new Rectangle(79, 34, 18, 18)) + .setNEIGregTechLogoPos(80, 61); public static final GT_Recipe_Map sCentrifugeRecipes = new GT_Recipe_Map( - new HashSet<>(1200), - "gt.recipe.centrifuge", - "Centrifuge", - null, - RES_PATH_GUI + "basicmachines/Centrifuge", - 2, - 6, - 0, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(1200), + "gt.recipe.centrifuge", + "Centrifuge", + null, + RES_PATH_GUI + "basicmachines/Centrifuge", + 2, + 6, + 0, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE_FLUID) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sElectrolyzerRecipes = new GT_Recipe_Map( - new HashSet<>(300), - "gt.recipe.electrolyzer", - "Electrolyzer", - null, - RES_PATH_GUI + "basicmachines/Electrolyzer", - 2, - 6, - 0, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(300), + "gt.recipe.electrolyzer", + "Electrolyzer", + null, + RES_PATH_GUI + "basicmachines/Electrolyzer", + 2, + 6, + 0, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_CHARGER) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_CHARGER_FLUID) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sBlastRecipes = new GT_Recipe_Map( - new HashSet<>(800), - "gt.recipe.blastfurnace", - "Blast Furnace", - null, - RES_PATH_GUI + "basicmachines/Default", - 6, - 6, - 1, - 0, - 1, - "Heat Capacity: ", - 1, - " K", - false, - true); - public static final GT_Recipe_Map sPlasmaForgeRecipes = new GT_Recipe_Map_PlasmaForge( - new HashSet<>(20), - "gt.recipe.plasmaforge", - "DTPF", - null, - RES_PATH_GUI + "basicmachines/PlasmaForge", - 1, - 1, - 0, - 0, - 1, - "Heat Capacity: ", - 1, - " K", - false, - true); + new HashSet<>(800), + "gt.recipe.blastfurnace", + "Blast Furnace", + null, + RES_PATH_GUI + "basicmachines/Default", + 6, + 6, + 1, + 0, + 1, + "Heat Capacity: ", + 1, + " K", + false, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map sPlasmaForgeRecipes = new GT_Recipe_Map_LargeNEI( + new HashSet<>(20), + "gt.recipe.plasmaforge", + "DTPF", + null, + RES_PATH_GUI + "basicmachines/PlasmaForge", + 9, + 9, + 0, + 0, + 1, + "Heat Capacity: ", + 1, + " K", + false, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(9) + .setUsualFluidOutputCount(9); public static final GT_Recipe_Map sPrimitiveBlastRecipes = new GT_Recipe_Map( - new HashSet<>(200), - "gt.recipe.primitiveblastfurnace", - "Primitive Blast Furnace", - null, - RES_PATH_GUI + "basicmachines/Default", - 3, - 3, - 1, - 0, - 1, - E, - 1, - E, - false, - true); + new HashSet<>(200), + "gt.recipe.primitiveblastfurnace", + "Primitive Blast Furnace", + null, + RES_PATH_GUI + "basicmachines/Default", + 3, + 3, + 1, + 0, + 1, + E, + 1, + E, + false, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sImplosionRecipes = new GT_Recipe_Map( - new HashSet<>(900), - "gt.recipe.implosioncompressor", - "Implosion Compressor", - null, - RES_PATH_GUI + "basicmachines/Default", - 2, - 2, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(900), + "gt.recipe.implosioncompressor", + "Implosion Compressor", + null, + RES_PATH_GUI + "basicmachines/Default", + 2, + 2, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_IMPLOSION) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_EXPLOSIVE) + .setProgressBar(GT_UITextures.PROGRESSBAR_COMPRESS, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map( - new HashSet<>(305), - "gt.recipe.vacuumfreezer", - "Vacuum Freezer", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - E, - 1, - E, - false, - true); + new HashSet<>(305), + "gt.recipe.vacuumfreezer", + "Vacuum Freezer", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + E, + 1, + E, + false, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map( - new HashSet<>(1170), - "gt.recipe.chemicalreactor", - "Chemical Reactor", - null, - RES_PATH_GUI + "basicmachines/ChemicalReactor", - 2, - 2, - 1, - 0, - 1, - E, - 1, - E, - true, - true); - public static final GT_Recipe_Map sMultiblockChemicalRecipes = new GT_Recipe_Map_LargeChemicalReactor(); - public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map_DistillationTower(); - public static final GT_Recipe_Map_OilCracker sCrackingRecipes = new GT_Recipe_Map_OilCracker(); + new HashSet<>(1170), + "gt.recipe.chemicalreactor", + "Chemical Reactor", + null, + RES_PATH_GUI + "basicmachines/ChemicalReactor", + 2, + 2, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_MOLECULAR_1) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_MOLECULAR_2) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_MOLECULAR_3) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_VIAL_1) + .setSlotOverlay(true, true, GT_UITextures.OVERLAY_SLOT_VIAL_2) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map sMultiblockChemicalRecipes = new GT_Recipe_Map_LargeChemicalReactor() + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(6) + .setUsualFluidOutputCount(6); + public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map_DistillationTower() + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT) + .setUsualFluidOutputCount(11); + public static final GT_Recipe_Map_OilCracker sCrackingRecipes = + (GT_Recipe_Map_OilCracker) new GT_Recipe_Map_OilCracker() + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW_MULTIPLE, ProgressBar.Direction.RIGHT) + .setUsualFluidInputCount(2); /** * Use sCrackingRecipes instead */ @@ -1704,294 +1870,341 @@ public class GT_Recipe implements Comparable<GT_Recipe> { public static final GT_Recipe_Map sCrakingRecipes = sCrackingRecipes; public static final GT_Recipe_Map sPyrolyseRecipes = new GT_Recipe_Map( - new HashSet<>(150), - "gt.recipe.pyro", - "Pyrolyse Oven", - null, - RES_PATH_GUI + "basicmachines/Default", - 2, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(150), + "gt.recipe.pyro", + "Pyrolyse Oven", + null, + RES_PATH_GUI + "basicmachines/Default", + 2, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sWiremillRecipes = new GT_Recipe_Map( - new HashSet<>(450), - "gt.recipe.wiremill", - "Wiremill", - null, - RES_PATH_GUI + "basicmachines/Wiremill", - 2, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(450), + "gt.recipe.wiremill", + "Wiremill", + null, + RES_PATH_GUI + "basicmachines/Wiremill", + 2, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_WIREMILL) + .setProgressBar(GT_UITextures.PROGRESSBAR_WIREMILL, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sBenderRecipes = new GT_Recipe_Map( - new HashSet<>(5000), - "gt.recipe.metalbender", - "Bending Machine", - null, - RES_PATH_GUI + "basicmachines/Bender", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(5000), + "gt.recipe.metalbender", + "Bending Machine", + null, + RES_PATH_GUI + "basicmachines/Bender", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_BENDER) + .setProgressBar(GT_UITextures.PROGRESSBAR_BENDING, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sAlloySmelterRecipes = new GT_Recipe_Map( - new HashSet<>(12000), - "gt.recipe.alloysmelter", - "Alloy Smelter", - null, - RES_PATH_GUI + "basicmachines/AlloySmelter", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(12000), + "gt.recipe.alloysmelter", + "Alloy Smelter", + null, + RES_PATH_GUI + "basicmachines/AlloySmelter", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_FURNACE) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_FURNACE_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_ARROW_STEAM); public static final GT_Recipe_Map sAssemblerRecipes = new GT_Recipe_Map_Assembler( - new HashSet<>(8200), - "gt.recipe.assembler", - "Assembler", - null, - RES_PATH_GUI + "basicmachines/Assembler2", - 9, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(8200), + "gt.recipe.assembler", + "Assembler", + null, + RES_PATH_GUI + "basicmachines/Assembler2", + 9, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CIRCUIT) + .setProgressBar(GT_UITextures.PROGRESSBAR_ASSEMBLE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sCircuitAssemblerRecipes = new GT_Recipe_Map_Assembler( - new HashSet<>(605), - "gt.recipe.circuitassembler", - "Circuit Assembler", - null, - RES_PATH_GUI + "basicmachines/CircuitAssembler", - 6, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true, - !Loader.isModLoaded("neicustomdiagram")); + new HashSet<>(605), + "gt.recipe.circuitassembler", + "Circuit Assembler", + null, + RES_PATH_GUI + "basicmachines/CircuitAssembler", + 6, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setNEIUnificateOutput(!Loader.isModLoaded("neicustomdiagram")) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CIRCUIT) + .setProgressBar(GT_UITextures.PROGRESSBAR_CIRCUIT_ASSEMBLER, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sCannerRecipes = new GT_Recipe_Map( - new HashSet<>(900), - "gt.recipe.canner", - "Canning Machine", - null, - RES_PATH_GUI + "basicmachines/Canner", - 2, - 2, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(900), + "gt.recipe.canner", + "Canning Machine", + null, + RES_PATH_GUI + "basicmachines/Canner", + 2, + 2, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_CANNER) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_CANISTER) + .setProgressBar(GT_UITextures.PROGRESSBAR_CANNER, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sCNCRecipes = new GT_Recipe_Map( - new HashSet<>(100), - "gt.recipe.cncmachine", - "CNC Machine", - null, - RES_PATH_GUI + "basicmachines/Default", - 2, - 1, - 2, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(100), + "gt.recipe.cncmachine", + "CNC Machine", + null, + RES_PATH_GUI + "basicmachines/Default", + 2, + 1, + 2, + 1, + 1, + E, + 1, + E, + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sLatheRecipes = new GT_Recipe_Map( - new HashSet<>(1150), - "gt.recipe.lathe", - "Lathe", - null, - RES_PATH_GUI + "basicmachines/Lathe", - 1, - 2, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(1150), + "gt.recipe.lathe", + "Lathe", + null, + RES_PATH_GUI + "basicmachines/Lathe", + 1, + 2, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_ROD_1) + .setSlotOverlay(false, true, true, GT_UITextures.OVERLAY_SLOT_ROD_2) + .setSlotOverlay(false, true, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_LATHE, ProgressBar.Direction.RIGHT) + .addSpecialTexture(5, 18, 98, 24, GT_UITextures.PROGRESSBAR_LATHE_BASE); public static final GT_Recipe_Map sCutterRecipes = new GT_Recipe_Map( - new HashSet<>(5125), - "gt.recipe.cuttingsaw", - "Cutting Machine", - null, - RES_PATH_GUI + "basicmachines/Cutter4", - 2, - 4, - 1, - 1, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(5125), + "gt.recipe.cuttingsaw", + "Cutting Machine", + null, + RES_PATH_GUI + "basicmachines/Cutter4", + 2, + 4, + 1, + 1, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_BOX) + .setSlotOverlay(false, true, true, GT_UITextures.OVERLAY_SLOT_CUTTER_SLICED) + .setSlotOverlay(false, true, false, GT_UITextures.OVERLAY_SLOT_DUST) + .setProgressBar(GT_UITextures.PROGRESSBAR_CUT, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sSlicerRecipes = new GT_Recipe_Map( - new HashSet<>(20), - "gt.recipe.slicer", - "Slicing Machine", - null, - RES_PATH_GUI + "basicmachines/Slicer", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(20), + "gt.recipe.slicer", + "Slicing Machine", + null, + RES_PATH_GUI + "basicmachines/Slicer", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, true, GT_UITextures.OVERLAY_SLOT_SQUARE) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_SLICE_SHAPE) + .setSlotOverlay(false, true, GT_UITextures.OVERLAY_SLOT_SLICER_SLICED) + .setProgressBar(GT_UITextures.PROGRESSBAR_SLICE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sExtruderRecipes = new GT_Recipe_Map( - new HashSet<>(13000), - "gt.recipe.extruder", - "Extruder", - null, - RES_PATH_GUI + "basicmachines/Extruder", - 2, - 1, - 2, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(13000), + "gt.recipe.extruder", + "Extruder", + null, + RES_PATH_GUI + "basicmachines/Extruder", + 2, + 1, + 2, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, false, GT_UITextures.OVERLAY_SLOT_EXTRUDER_SHAPE) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRUDE, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sHammerRecipes = new GT_Recipe_Map( - new HashSet<>(3800), - "gt.recipe.hammer", - "Forge Hammer", - null, - RES_PATH_GUI + "basicmachines/Hammer", - 1, - 1, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(3800), + "gt.recipe.hammer", + "Forge Hammer", + null, + RES_PATH_GUI + "basicmachines/Hammer", + 1, + 1, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_HAMMER) + .setProgressBar(GT_UITextures.PROGRESSBAR_HAMMER, ProgressBar.Direction.DOWN) + .addSpecialTexture(20, 6, 78, 42, GT_UITextures.PROGRESSBAR_HAMMER_BASE) + .setSlotOverlaySteam(false, GT_UITextures.OVERLAY_SLOT_HAMMER_STEAM) + .setProgressBarSteam(GT_UITextures.PROGRESSBAR_HAMMER_STEAM) + .addSpecialTextureSteam(20, 6, 78, 42, GT_UITextures.PROGRESSBAR_HAMMER_BASE_STEAM); public static final GT_Recipe_Map sAmplifiers = new GT_Recipe_Map( - new HashSet<>(2), - "gt.recipe.uuamplifier", - "Amplifabricator", - null, - RES_PATH_GUI + "basicmachines/Amplifabricator", - 1, - 0, - 1, - 0, - 1, - E, - 1, - E, - true, - true); + new HashSet<>(2), + "gt.recipe.uuamplifier", + "Amplifabricator", + null, + RES_PATH_GUI + "basicmachines/Amplifabricator", + 1, + 0, + 1, + 0, + 1, + E, + 1, + E, + true, + true) + .setSlotOverlay(false, false, GT_UITextures.OVERLAY_SLOT_CENTRIFUGE) + .setSlotOverlay(true, true, GT_UITextures.OVERLAY_SLOT_UUA) + .setProgressBar(GT_UITextures.PROGRESSBAR_EXTRACT, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sMassFabFakeRecipes = new GT_Recipe_Map( - new HashSet<>(2), - "gt.recipe.massfab", - "Mass Fabrication", - null, - RES_PATH_GUI + "basicmachines/Massfabricator", - 1, - 0, - 1, - 0, - 8, - E, - 1, - E, - true, - true); - public static final GT_Recipe_Map_Fuel sDieselFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(20), - "gt.recipe.dieselgeneratorfuel", - "Combustion Generator Fuels", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sExtremeDieselFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(20), - "gt.recipe.extremedieselgeneratorfuel", - "Extreme Diesel Engine Fuel", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sTurbineFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(25), - "gt.recipe.gasturbinefuel", - "Gas Turbine Fuel", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); + new HashSet<>(2), + "gt.recipe.massfab", + "Mass Fabrication", + null, + RES_PATH_GUI + "basicmachines/Massfabricator", + 1, + 0, + 1, + 0, + 8, + E, + 1, + E, + true, + true) + .setSlotOverlay(true, false, GT_UITextures.OVERLAY_SLOT_UUA) + .setSlotOverlay(true, true, GT_UITextures.OVERLAY_SLOT_UUM) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sDieselFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(20), + "gt.recipe.dieselgeneratorfuel", + "Combustion Generator Fuels", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sExtremeDieselFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(20), + "gt.recipe.extremedieselgeneratorfuel", + "Extreme Diesel Engine Fuel", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sTurbineFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(25), + "gt.recipe.gasturbinefuel", + "Gas Turbine Fuel", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map_Fuel sHotFuels = new GT_Recipe_Map_Fuel( new HashSet<>(10), "gt.recipe.thermalgeneratorfuel", @@ -2008,150 +2221,161 @@ public class GT_Recipe implements Comparable<GT_Recipe> { " EU", true, false); - public static final GT_Recipe_Map_Fuel sDenseLiquidFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(15), - "gt.recipe.semifluidboilerfuels", - "Semifluid Boiler Fuels", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sPlasmaFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(100), - "gt.recipe.plasmageneratorfuels", - "Plasma Generator Fuels", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sMagicFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(100), - "gt.recipe.magicfuels", - "Magic Energy Absorber Fuels", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sSmallNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.smallnaquadahreactor", - "Naquadah Reactor MkI", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sLargeNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.largenaquadahreactor", - "Naquadah Reactor MkII", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sHugeNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.fluidnaquadahreactor", - "Naquadah Reactor MkIII", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sExtremeNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.hugenaquadahreactor", - "Naquadah Reactor MkIV", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sUltraHugeNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.extrahugenaquadahreactor", - "Naquadah Reactor MkV", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); - public static final GT_Recipe_Map_Fuel sFluidNaquadahReactorFuels = new GT_Recipe_Map_Fuel( - new HashSet<>(1), - "gt.recipe.fluidfuelnaquadahreactor", - "Fluid Naquadah Reactor", - null, - RES_PATH_GUI + "basicmachines/Default", - 1, - 1, - 0, - 0, - 1, - "Fuel Value: ", - 1000, - " EU", - true, - true); + public static final GT_Recipe_Map_Fuel sDenseLiquidFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(15), + "gt.recipe.semifluidboilerfuels", + "Semifluid Boiler Fuels", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sPlasmaFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(100), + "gt.recipe.plasmageneratorfuels", + "Plasma Generator Fuels", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sMagicFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(100), + "gt.recipe.magicfuels", + "Magic Energy Absorber Fuels", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sSmallNaquadahReactorFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.smallnaquadahreactor", + "Naquadah Reactor MkI", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sLargeNaquadahReactorFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.largenaquadahreactor", + "Naquadah Reactor MkII", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sHugeNaquadahReactorFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.fluidnaquadahreactor", + "Naquadah Reactor MkIII", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sExtremeNaquadahReactorFuels = + (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.hugenaquadahreactor", + "Naquadah Reactor MkIV", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sUltraHugeNaquadahReactorFuels = + (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.extrahugenaquadahreactor", + "Naquadah Reactor MkV", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); + public static final GT_Recipe_Map_Fuel sFluidNaquadahReactorFuels = (GT_Recipe_Map_Fuel) new GT_Recipe_Map_Fuel( + new HashSet<>(1), + "gt.recipe.fluidfuelnaquadahreactor", + "Fluid Naquadah Reactor", + null, + RES_PATH_GUI + "basicmachines/Default", + 1, + 1, + 0, + 0, + 1, + "Fuel Value: ", + 1000, + " EU", + true, + true) + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); public static final GT_Recipe_Map sMultiblockElectrolyzerRecipes = new GT_Recipe_Map( new HashSet<>(300), "gt.recipe.largeelectrolyzer", @@ -2201,7 +2425,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { true, false); public static final GT_Recipe_Map_LargeBoilerFakeFuels sLargeBoilerFakeFuels = - new GT_Recipe_Map_LargeBoilerFakeFuels(); + (GT_Recipe_Map_LargeBoilerFakeFuels) new GT_Recipe_Map_LargeBoilerFakeFuels() + .setProgressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT); /** * HashMap of Recipes based on their Items @@ -2237,7 +2462,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> { mMinimalInputItems, mMinimalInputFluids, mAmperage; - public final boolean mNEIAllowed, mShowVoltageAmperageInNEI, mNEIUnificateOutput; + public final boolean mNEIAllowed, mShowVoltageAmperageInNEI; + + /** + * Whether to show oredict equivalent outputs when NEI is queried to show recipe + */ + public boolean mNEIUnificateOutput = true; /** * Unique identifier for this recipe map. Generated from aUnlocalizedName and a few other parameters. @@ -2256,6 +2486,87 @@ public class GT_Recipe implements Comparable<GT_Recipe> { private boolean mUsesSpecialSlot = false; /** + * How many fluid inputs does this recipemap has at most. Currently used only for NEI slot placements + * and does not actually restrict number of fluids used in the recipe. + */ + private int usualFluidInputCount; + + /** + * How many fluid outputs does this recipemap has at most. Currently used only for NEI slot placements + * and does not actually restrict number of fluids used in the recipe. + */ + private int usualFluidOutputCount; + + /** + * Whether to use ModularUI for slot placements. + */ + public boolean useModularUI = false; + + /** + * Overlays used for GUI. + * 1 = If it's fluid slot. + * 2 = If it's output slot. + * 4 = If it's first slot in the same section, e.g. first slot in the item output slots + * 8 = If it's special item slot. + */ + private final TByteObjectMap<IDrawable> slotOverlays = new TByteObjectHashMap<>(); + + /** + * Overlays used for GUI on steam machine. + * 1 = If it's fluid slot. + * 2 = If it's output slot. + * 4 = If it's first slot in the same section, e.g. first slot in the item output slots + * 8 = If it's special item slot. + */ + private final TByteObjectMap<SteamTexture> slotOverlaysSteam = new TByteObjectHashMap<>(); + + /** + * Progressbar used for BasicMachine GUI and/or NEI. + * Unless specified, size should be (20, 36), consisting of two parts; + * First is (20, 18) size of "empty" image at the top, + * Second is (20, 18) size of "filled" image at the bottom. + */ + public UITexture progressBarTexture = GT_UITextures.PROGRESSBAR_ARROW; + + /** + * Progressbar used for steam machine GUI and/or NEI. + * Unless specified, size should be (20, 36), consisting of two parts; + * First is (20, 18) size of "empty" image at the top, + * Second is (20, 18) size of "filled" image at the bottom. + */ + public SteamTexture progressBarTextureSteam; + + public ProgressBar.Direction progressBarDirection = ProgressBar.Direction.RIGHT; + + public Size progressBarSize = new Size(20, 18); + + public Pos2d progressBarPos = new Pos2d(78, 24); + + public Rectangle neiTransferRect = new Rectangle( + progressBarPos.x - (16 / 2), progressBarPos.y, progressBarSize.width + 16, progressBarSize.height); + + /** + * Image size in direction of progress. Used for non-smooth rendering. + */ + private int progressBarImageSize; + + /** + * Additional textures shown on GUI. + */ + public final List<Pair<IDrawable, Pair<Size, Pos2d>>> specialTextures = new ArrayList<>(); + + /** + * Additional textures shown on steam machine GUI. + */ + public final List<Pair<SteamTexture, Pair<Size, Pos2d>>> specialTexturesSteam = new ArrayList<>(); + + public Pos2d neiGregTechLogoPos = new Pos2d(152, 63); + + public Pos2d neiBackgroundOffset = new Pos2d(2, 3); + + public Size neiBackgroundSize = new Size(172, 82); + + /** * Initialises a new type of Recipe Handler. * * @param aRecipeList a List you specify as Recipe List. Usually just an ArrayList with a pre-initialised Size. @@ -2268,7 +2579,6 @@ public class GT_Recipe implements Comparable<GT_Recipe> { * @param aNEISpecialValueMultiplier the Value the Special Value is getting Multiplied with before displaying * @param aNEISpecialValuePost the String after the Special Value. Usually for a Unit or something. * @param aNEIAllowed if NEI is allowed to display this Recipe Handler in general. - * @param aNEIUnificateOutput if NEI generate oredict equivalents */ public GT_Recipe_Map( Collection<GT_Recipe> aRecipeList, @@ -2285,12 +2595,10 @@ public class GT_Recipe implements Comparable<GT_Recipe> { int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, - boolean aNEIAllowed, - boolean aNEIUnificateOutput) { + boolean aNEIAllowed) { sMappings.add(this); mNEIAllowed = aNEIAllowed; mShowVoltageAmperageInNEI = aShowVoltageAmperageInNEI; - mNEIUnificateOutput = aNEIUnificateOutput; mRecipeList = aRecipeList; mNEIName = aNEIName == null ? aUnlocalizedName : aNEIName; mNEIGUIPath = aNEIGUIPath.endsWith(".png") ? aNEIGUIPath : aNEIGUIPath + ".png"; @@ -2317,6 +2625,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { throw new IllegalArgumentException("Duplicate recipe map registered: " + mUniqueIdentifier); } + @Deprecated public GT_Recipe_Map( Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, @@ -2332,7 +2641,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, - boolean aNEIAllowed) { + boolean aNEIAllowed, + boolean aNEIUnificateOutput) { this( aRecipeList, aUnlocalizedName, @@ -2348,8 +2658,138 @@ public class GT_Recipe implements Comparable<GT_Recipe> { aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, - aNEIAllowed, - true); + aNEIAllowed); + setNEIUnificateOutput(aNEIUnificateOutput); + } + + public GT_Recipe_Map setNEIUnificateOutput(boolean mNEIUnificateOutput) { + this.mNEIUnificateOutput = mNEIUnificateOutput; + return this; + } + + public GT_Recipe_Map useModularUI(boolean use) { + this.useModularUI = use; + return this; + } + + public GT_Recipe_Map setSlotOverlay( + boolean isFluid, boolean isOutput, boolean isFirst, boolean isSpecial, IDrawable slotOverlay) { + useModularUI(true); + this.slotOverlays.put( + (byte) ((isFluid ? 1 : 0) + (isOutput ? 2 : 0) + (isFirst ? 4 : 0) + (isSpecial ? 8 : 0)), + slotOverlay); + return this; + } + + public GT_Recipe_Map setSlotOverlay(boolean isFluid, boolean isOutput, boolean isFirst, IDrawable slotOverlay) { + return setSlotOverlay(isFluid, isOutput, isFirst, false, slotOverlay); + } + + public GT_Recipe_Map setSlotOverlay(boolean isFluid, boolean isOutput, IDrawable slotOverlay) { + return setSlotOverlay(isFluid, isOutput, true, slotOverlay) + .setSlotOverlay(isFluid, isOutput, false, slotOverlay); + } + + public GT_Recipe_Map setSlotOverlaySteam( + boolean isFluid, boolean isOutput, boolean isFirst, boolean isSpecial, SteamTexture slotOverlay) { + useModularUI(true); + this.slotOverlaysSteam.put( + (byte) ((isFluid ? 1 : 0) + (isOutput ? 2 : 0) + (isFirst ? 4 : 0) + (isSpecial ? 8 : 0)), + slotOverlay); + return this; + } + + public GT_Recipe_Map setSlotOverlaySteam(boolean isOutput, boolean isFirst, SteamTexture slotOverlay) { + return setSlotOverlaySteam(false, isOutput, isFirst, false, slotOverlay); + } + + public GT_Recipe_Map setSlotOverlaySteam(boolean isOutput, SteamTexture slotOverlay) { + return setSlotOverlaySteam(false, isOutput, true, false, slotOverlay) + .setSlotOverlaySteam(false, isOutput, false, false, slotOverlay); + } + + public GT_Recipe_Map setProgressBar(UITexture progressBarTexture, ProgressBar.Direction progressBarDirection) { + useModularUI(true); + this.progressBarTexture = progressBarTexture; + this.progressBarDirection = progressBarDirection; + return this; + } + + public GT_Recipe_Map setProgressBar(UITexture progressBarTexture) { + return setProgressBar(progressBarTexture, ProgressBar.Direction.RIGHT); + } + + public GT_Recipe_Map setProgressBarSteam(SteamTexture progressBarTexture) { + this.progressBarTextureSteam = progressBarTexture; + return this; + } + + public GT_Recipe_Map setProgressBarSize(int x, int y) { + useModularUI(true); + this.progressBarSize = new Size(x, y); + return this; + } + + public GT_Recipe_Map setProgressBarPos(int x, int y) { + useModularUI(true); + this.progressBarPos = new Pos2d(x, y); + return this; + } + + public GT_Recipe_Map setProgressBarImageSize(int progressBarImageSize) { + useModularUI(true); + this.progressBarImageSize = progressBarImageSize; + return this; + } + + public GT_Recipe_Map setNEITransferRect(Rectangle neiTransferRect) { + useModularUI(true); + this.neiTransferRect = neiTransferRect; + return this; + } + + public GT_Recipe_Map addSpecialTexture(int width, int height, int x, int y, IDrawable texture) { + useModularUI(true); + specialTextures.add( + new ImmutablePair<>(texture, new ImmutablePair<>(new Size(width, height), new Pos2d(x, y)))); + return this; + } + + public GT_Recipe_Map addSpecialTextureSteam(int width, int height, int x, int y, SteamTexture texture) { + useModularUI(true); + specialTexturesSteam.add( + new ImmutablePair<>(texture, new ImmutablePair<>(new Size(width, height), new Pos2d(x, y)))); + return this; + } + + public GT_Recipe_Map setUsualFluidInputCount(int usualFluidInputCount) { + useModularUI(true); + this.usualFluidInputCount = usualFluidInputCount; + return this; + } + + public GT_Recipe_Map setUsualFluidOutputCount(int usualFluidOutputCount) { + useModularUI(true); + this.usualFluidOutputCount = usualFluidOutputCount; + return this; + } + + public GT_Recipe_Map setNEIGregTechLogoPos(int x, int y) { + useModularUI(true); + this.neiGregTechLogoPos = new Pos2d(x, y); + return this; + } + + public GT_Recipe_Map setNEIBackgroundOffset(int x, int y) { + useModularUI(true); + this.neiBackgroundOffset = new Pos2d(x, y); + return this; + } + + public GT_Recipe_Map setNEIBackgroundSize(int width, int height) { + useModularUI(true); + this.neiBackgroundSize = new Size(width, height); + return this; } public GT_Recipe addRecipe( @@ -2786,18 +3226,184 @@ public class GT_Recipe implements Comparable<GT_Recipe> { return mUsesSpecialSlot; } + public int getUsualFluidInputCount() { + return Math.max(usualFluidInputCount, hasFluidInputs() ? 1 : 0); + } + + public int getUsualFluidOutputCount() { + return Math.max(usualFluidOutputCount, hasFluidOutputs() ? 1 : 0); + } + + @Nullable + public IDrawable getOverlayForSlot(boolean isFluid, boolean isOutput, int index, boolean isSpecial) { + byte overlayKey = + (byte) ((isFluid ? 1 : 0) + (isOutput ? 2 : 0) + (index == 0 ? 4 : 0) + (isSpecial ? 8 : 0)); + if (slotOverlays.containsKey(overlayKey)) { + return slotOverlays.get(overlayKey); + } + return null; + } + + @Nullable + public SteamTexture getOverlayForSlotSteam(boolean isFluid, boolean isOutput, int index, boolean isSpecial) { + byte overlayKey = + (byte) ((isFluid ? 1 : 0) + (isOutput ? 2 : 0) + (index == 0 ? 4 : 0) + (isSpecial ? 8 : 0)); + if (slotOverlaysSteam.containsKey(overlayKey)) { + return slotOverlaysSteam.get(overlayKey); + } + return null; + } + + @Nullable + public SteamTexture getOverlayForSlotSteam(boolean isOutput, boolean isFirst) { + byte overlayKey = (byte) ((isOutput ? 2 : 0) + (isFirst ? 4 : 0)); + if (slotOverlaysSteam.containsKey(overlayKey)) { + return slotOverlaysSteam.get(overlayKey); + } + return null; + } + + public int getProgressBarImageSize() { + if (progressBarImageSize != 0) { + return progressBarImageSize; + } + switch (progressBarDirection) { + case UP: + case DOWN: + return progressBarSize.height; + case CIRCULAR_CW: + return Math.max(progressBarSize.width, progressBarSize.height); + default: + return progressBarSize.width; + } + } + /** - * Overriding this method and getOutputPositionedStacks allows custom NEI stack placement - * @return A list of input stacks + * Adds slot backgrounds, progressBar, etc. */ + public ModularWindow.Builder createNEITemplate( + IItemHandlerModifiable itemInputsInventory, + IItemHandlerModifiable itemOutputsInventory, + IItemHandlerModifiable specialSlotInventory, + IItemHandlerModifiable fluidInputsInventory, + IItemHandlerModifiable fluidOutputsInventory, + Supplier<Float> progressSupplier, + Pos2d windowOffset) { + ModularWindow.Builder builder = + ModularWindow.builder(neiBackgroundSize).setBackground(ModularUITextures.VANILLA_BACKGROUND); + + UIHelper.forEachSlots( + (i, backgrounds, pos) -> builder.widget(SlotWidget.phantom(itemInputsInventory, i) + .setBackground(backgrounds) + .setPos(pos) + .setSize(18, 18)), + (i, backgrounds, pos) -> builder.widget(SlotWidget.phantom(itemOutputsInventory, i) + .setBackground(backgrounds) + .setPos(pos) + .setSize(18, 18)), + (i, backgrounds, pos) -> { + if (usesSpecialSlot()) + builder.widget(SlotWidget.phantom(specialSlotInventory, 0) + .setBackground(backgrounds) + .setPos(pos) + .setSize(18, 18)); + }, + (i, backgrounds, pos) -> builder.widget(SlotWidget.phantom(fluidInputsInventory, i) + .setBackground(backgrounds) + .setPos(pos) + .setSize(18, 18)), + (i, backgrounds, pos) -> builder.widget(SlotWidget.phantom(fluidOutputsInventory, i) + .setBackground(backgrounds) + .setPos(pos) + .setSize(18, 18)), + ModularUITextures.ITEM_SLOT, + ModularUITextures.FLUID_SLOT, + this, + mUsualInputCount, + mUsualOutputCount, + getUsualFluidInputCount(), + getUsualFluidOutputCount(), + SteamVariant.NONE, + windowOffset); + + addProgressBarUI(builder, progressSupplier, windowOffset); + addGregTechLogoUI(builder, windowOffset); + + for (Pair<IDrawable, Pair<Size, Pos2d>> specialTexture : specialTextures) { + builder.widget(new DrawableWidget() + .setDrawable(specialTexture.getLeft()) + .setSize(specialTexture.getRight().getLeft()) + .setPos(specialTexture.getRight().getRight().add(windowOffset))); + } + + return builder; + } + + protected void addProgressBarUI( + ModularWindow.Builder builder, Supplier<Float> progressSupplier, Pos2d windowOffset) { + builder.widget(new ProgressBar() + .setTexture(progressBarTexture, 20) + .setDirection(progressBarDirection) + .setProgress(progressSupplier) + .setSynced(false, false) + .setPos(progressBarPos.add(windowOffset)) + .setSize(progressBarSize)); + } + + protected void addGregTechLogoUI(ModularWindow.Builder builder, Pos2d windowOffset) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT) + .setSize(17, 17) + .setPos(neiGregTechLogoPos.add(windowOffset))); + } + + /** + * Overriding this method allows custom NEI stack placement + */ + public List<Pos2d> getItemInputPositions(int itemInputCount) { + return UIHelper.getItemInputPositions(itemInputCount); + } + + /** + * Overriding this method allows custom NEI stack placement + */ + public List<Pos2d> getItemOutputPositions(int itemOutputCount) { + return UIHelper.getItemOutputPositions(itemOutputCount); + } + + /** + * Overriding this method allows custom NEI stack placement + */ + public Pos2d getSpecialItemPosition() { + return UIHelper.getSpecialItemPosition(); + } + + /** + * Overriding this method allows custom NEI stack placement + */ + public List<Pos2d> getFluidInputPositions(int fluidInputCount) { + return UIHelper.getFluidInputPositions(fluidInputCount); + } + + /** + * Overriding this method allows custom NEI stack placement + */ + public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + return UIHelper.getFluidOutputPositions(fluidOutputCount); + } + + /** + * Use {@link #getItemInputPositions} or {@link #getSpecialItemPosition} or {@link #getFluidInputPositions} instead + */ + @Deprecated public ArrayList<PositionedStack> getInputPositionedStacks(GT_Recipe recipe) { return null; } /** - * Overriding this method and getInputPositionedStacks allows custom NEI stack placement - * @return A list of output stacks + * Use {@link #getItemOutputPositions} or {@link #getFluidOutputPositions} instead */ + @Deprecated public ArrayList<PositionedStack> getOutputPositionedStacks(GT_Recipe recipe) { return null; } @@ -2810,6 +3416,155 @@ public class GT_Recipe implements Comparable<GT_Recipe> { // ----------------------------------------------------------------------------------------------------------------- /** + * Nicely display NEI with many items and fluids. + * Remember to call {@link GT_Recipe_Map#setUsualFluidInputCount} and {@link GT_Recipe_Map#setUsualFluidOutputCount}. + * If row count >= 6, it doesn't fit in 2 recipes per page, so change it via IMC. + */ + public static class GT_Recipe_Map_LargeNEI extends GT_Recipe_Map { + + private static final int xDirMaxCount = 3; + private static final int yOrigin = 8; + + public GT_Recipe_Map_LargeNEI( + Collection<GT_Recipe> aRecipeList, + String aUnlocalizedName, + String aLocalName, + String aNEIName, + String aNEIGUIPath, + int aUsualInputCount, + int aUsualOutputCount, + int aMinimalInputItems, + int aMinimalInputFluids, + int aAmperage, + String aNEISpecialValuePre, + int aNEISpecialValueMultiplier, + String aNEISpecialValuePost, + boolean aShowVoltageAmperageInNEI, + boolean aNEIAllowed) { + super( + aRecipeList, + aUnlocalizedName, + aLocalName, + aNEIName, + aNEIGUIPath, + aUsualInputCount, + aUsualOutputCount, + aMinimalInputItems, + aMinimalInputFluids, + aAmperage, + aNEISpecialValuePre, + aNEISpecialValueMultiplier, + aNEISpecialValuePost, + aShowVoltageAmperageInNEI, + aNEIAllowed); + useModularUI(true); + setNEIGregTechLogoPos(80, 62); + } + + @Override + public List<Pos2d> getItemInputPositions(int itemInputCount) { + return UIHelper.getItemGridPositions(itemInputCount, 16, yOrigin, xDirMaxCount, 3); + } + + @Override + public List<Pos2d> getItemOutputPositions(int itemOutputCount) { + return UIHelper.getItemGridPositions(itemOutputCount, 106, yOrigin, xDirMaxCount, 3); + } + + @Override + public List<Pos2d> getFluidInputPositions(int fluidInputCount) { + return UIHelper.getItemGridPositions( + fluidInputCount, 16, yOrigin + getItemRowCount() * 18, xDirMaxCount, 3); + } + + @Override + public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + return UIHelper.getItemGridPositions( + fluidOutputCount, 106, yOrigin + getItemRowCount() * 18, xDirMaxCount, 3); + } + + @Override + public ModularWindow.Builder createNEITemplate( + IItemHandlerModifiable itemInputsInventory, + IItemHandlerModifiable itemOutputsInventory, + IItemHandlerModifiable specialSlotInventory, + IItemHandlerModifiable fluidInputsInventory, + IItemHandlerModifiable fluidOutputsInventory, + Supplier<Float> progressSupplier, + Pos2d windowOffset) { + // Delay setter so that calls to #setUsualFluidInputCount and #setUsualFluidOutputCount are considered + setNEIBackgroundSize(172, 82 + (Math.max(getItemRowCount() + getFluidRowCount() - 4, 0)) * 18); + return super.createNEITemplate( + itemInputsInventory, + itemOutputsInventory, + specialSlotInventory, + fluidInputsInventory, + fluidOutputsInventory, + progressSupplier, + windowOffset); + } + + private int getItemRowCount() { + return (Math.max(mUsualInputCount, mUsualOutputCount) - 1) / xDirMaxCount + 1; + } + + private int getFluidRowCount() { + return (Math.max(getUsualFluidInputCount(), getUsualFluidOutputCount()) - 1) / xDirMaxCount + 1; + } + } + + /** + * Display fluids where normally items are placed on NEI. + */ + public static class GT_Recipe_Map_FluidOnly extends GT_Recipe_Map { + + public GT_Recipe_Map_FluidOnly( + Collection<GT_Recipe> aRecipeList, + String aUnlocalizedName, + String aLocalName, + String aNEIName, + String aNEIGUIPath, + int aUsualInputCount, + int aUsualOutputCount, + int aMinimalInputItems, + int aMinimalInputFluids, + int aAmperage, + String aNEISpecialValuePre, + int aNEISpecialValueMultiplier, + String aNEISpecialValuePost, + boolean aShowVoltageAmperageInNEI, + boolean aNEIAllowed) { + super( + aRecipeList, + aUnlocalizedName, + aLocalName, + aNEIName, + aNEIGUIPath, + aUsualInputCount, + aUsualOutputCount, + aMinimalInputItems, + aMinimalInputFluids, + aAmperage, + aNEISpecialValuePre, + aNEISpecialValueMultiplier, + aNEISpecialValuePost, + aShowVoltageAmperageInNEI, + aNEIAllowed); + useModularUI(true); + } + + @Override + public List<Pos2d> getFluidInputPositions(int fluidInputCount) { + return UIHelper.getItemInputPositions(fluidInputCount); + } + + @Override + public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + return UIHelper.getItemOutputPositions(fluidOutputCount); + } + } + + /** * Abstract Class for general Recipe Handling of non GT Recipes */ public abstract static class GT_Recipe_Map_NonGTRecipes extends GT_Recipe_Map { @@ -4060,44 +4815,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> { int aNEISpecialValueMultiplier, String aNEISpecialValuePost, boolean aShowVoltageAmperageInNEI, - boolean aNEIAllowed, - boolean aNEIUnificateOutput) { - super( - aRecipeList, - aUnlocalizedName, - aLocalName, - aNEIName, - aNEIGUIPath, - aUsualInputCount, - aUsualOutputCount, - aMinimalInputItems, - aMinimalInputFluids, - aAmperage, - aNEISpecialValuePre, - aNEISpecialValueMultiplier, - aNEISpecialValuePost, - aShowVoltageAmperageInNEI, - aNEIAllowed, - aNEIUnificateOutput); - } - - public GT_Recipe_Map_Assembler( - Collection<GT_Recipe> aRecipeList, - String aUnlocalizedName, - String aLocalName, - String aNEIName, - String aNEIGUIPath, - int aUsualInputCount, - int aUsualOutputCount, - int aMinimalInputItems, - int aMinimalInputFluids, - int aAmperage, - String aNEISpecialValuePre, - int aNEISpecialValueMultiplier, - String aNEISpecialValuePost, - boolean aShowVoltageAmperageInNEI, boolean aNEIAllowed) { - this( + super( aRecipeList, aUnlocalizedName, aLocalName, @@ -4112,8 +4831,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, - aNEIAllowed, - true); + aNEIAllowed); } @Override @@ -4614,10 +5332,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } } - public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map { + public static class GT_Recipe_Map_LargeChemicalReactor extends GT_Recipe_Map_LargeNEI { private static final int TOTAL_INPUT_COUNT = 6; private static final int OUTPUT_COUNT = 6; - private static final int FLUID_OUTPUT_COUNT = 6; public GT_Recipe_Map_LargeChemicalReactor() { super( @@ -4626,7 +5343,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { "Large Chemical Reactor", null, RES_PATH_GUI + "basicmachines/LCRNEI", - 2, + TOTAL_INPUT_COUNT, OUTPUT_COUNT, 0, 0, @@ -4742,83 +5459,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> { aEUt, aSpecialValue); } - - @Override - public ArrayList<PositionedStack> getInputPositionedStacks(GT_Recipe recipe) { - int itemLimit = Math.min(recipe.mInputs.length, TOTAL_INPUT_COUNT); - int fluidLimit = Math.min(recipe.mFluidInputs.length, TOTAL_INPUT_COUNT - itemLimit); - int inputlimit = itemLimit + fluidLimit; - int j = 0; - - ArrayList<PositionedStack> inputStacks = new ArrayList<>(inputlimit); - - for (int i = 0; i < itemLimit; i++, j++) { - if (recipe.mInputs == null || (recipe.mInputs[i] == null && (i == 0 && itemLimit == 1))) { - if (recipe.mOutputs != null && recipe.mOutputs.length > 0 && recipe.mOutputs[0] != null) - GT_Log.out.println("recipe " + recipe + " Output 0:" + recipe.mOutputs[0].getDisplayName() - + " has errored!"); - else GT_Log.out.println("recipe " + recipe + " has errored!"); - - new Exception("Recipe Fixme").printStackTrace(GT_Log.out); - } - - if ((recipe.mInputs != null && recipe.mInputs[i] != null) || !GT_Values.allow_broken_recipemap) - inputStacks.add( - new FixedPositionedStack(recipe.mInputs[i].copy(), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - else - inputStacks.add(new FixedPositionedStack( - new ItemStack(Items.command_block_minecart), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - } - - for (int i = 0; i < fluidLimit; i++, j++) { - if (recipe.mFluidInputs == null || recipe.mFluidInputs[i] == null) { - if (recipe.mOutputs != null && recipe.mOutputs.length > 0 && recipe.mOutputs[0] != null) - GT_Log.out.println("recipe " + recipe + " Output 0:" + recipe.mOutputs[0].getDisplayName() - + " has errored!"); - else GT_Log.out.println("recipe " + recipe + " has errored!"); - - new Exception("Recipe Fixme").printStackTrace(GT_Log.out); - } - - if ((recipe.mFluidInputs != null && recipe.mFluidInputs[i] != null) - || !GT_Values.allow_broken_recipemap) - inputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidInputs[i], true), - 48 - j % 3 * 18, - (j >= 3 ? 5 : 23))); - } - - return inputStacks; - } - - @Override - public ArrayList<PositionedStack> getOutputPositionedStacks(GT_Recipe recipe) { - int itemLimit = Math.min(recipe.mOutputs.length, OUTPUT_COUNT); - int fluidLimit = Math.min(recipe.mFluidOutputs.length, FLUID_OUTPUT_COUNT); - ArrayList<PositionedStack> outputStacks = new ArrayList<>(itemLimit + fluidLimit); - - int j = 0; - - for (int i = 0; i < itemLimit; i++, j++) { - outputStacks.add( - new FixedPositionedStack(recipe.mOutputs[i].copy(), 102 + j % 3 * 18, (j >= 3 ? 5 : 23))); - } - - for (int i = 0; i < fluidLimit; i++, j++) { - outputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidOutputs[i], true), - 102 + j % 3 * 18, - (j >= 3 ? 5 : 23))); - } - - return outputStacks; - } } public static class GT_Recipe_Map_DistillationTower extends GT_Recipe_Map { - private static final int TOTAL_INPUT_COUNT = 6; - private static final int FLUID_OUTPUT_COUNT = 11; - private static final int ROW_SIZE = 3; public GT_Recipe_Map_DistillationTower() { super( @@ -4828,7 +5471,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> { null, RES_PATH_GUI + "basicmachines/DistillationTower", 2, - 4, + 1, 0, 0, 1, @@ -4837,70 +5480,33 @@ public class GT_Recipe implements Comparable<GT_Recipe> { E, true, true); + setNEIGregTechLogoPos(80, 62); } @Override - public ArrayList<PositionedStack> getInputPositionedStacks(GT_Recipe recipe) { - int itemLimit = Math.min(recipe.mInputs.length, TOTAL_INPUT_COUNT); - int fluidLimit = Math.min(recipe.mFluidInputs.length, TOTAL_INPUT_COUNT - itemLimit); - int inputlimit = itemLimit + fluidLimit; - int j = 0; - - ArrayList<PositionedStack> inputStacks = new ArrayList<>(inputlimit); - - for (int i = 0; i < itemLimit; i++, j++) { - if (recipe.mInputs == null || (recipe.mInputs[i] == null && (i == 0 && itemLimit == 1))) { - if (recipe.mOutputs != null && recipe.mOutputs.length > 0 && recipe.mOutputs[0] != null) - GT_Log.out.println("recipe " + recipe + " Output 0:" + recipe.mOutputs[0].getDisplayName() - + " has errored!"); - else GT_Log.out.println("recipe " + recipe + " has errored!"); - new Exception("Recipe Fixme").printStackTrace(GT_Log.out); - } - - if ((recipe.mInputs != null && recipe.mInputs[i] != null) || !GT_Values.allow_broken_recipemap) - inputStacks.add( - new FixedPositionedStack(recipe.mInputs[i].copy(), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - else - inputStacks.add(new FixedPositionedStack( - new ItemStack(Items.command_block_minecart), 48 - j % 3 * 18, (j >= 3 ? 5 : 23))); - } - - for (int i = 0; i < fluidLimit; i++, j++) { - if (recipe.mFluidInputs == null || recipe.mFluidInputs[i] == null) { - if (recipe.mOutputs != null && recipe.mOutputs.length > 0 && recipe.mOutputs[0] != null) - GT_Log.out.println("recipe " + recipe + " Output 0:" + recipe.mOutputs[0].getDisplayName() - + " has errored!"); - else GT_Log.out.println("recipe " + recipe + " has errored!"); - new Exception("Recipe Fixme").printStackTrace(GT_Log.out); + public IDrawable getOverlayForSlot(boolean isFluid, boolean isOutput, int index, boolean isSpecial) { + if (isOutput) { + if (isFluid) { + return GT_UITextures.OVERLAY_SLOTS_NUMBER[index + 1]; + } else { + return GT_UITextures.OVERLAY_SLOTS_NUMBER[0]; } - - if ((recipe.mFluidInputs != null && recipe.mFluidInputs[i] != null) - || !GT_Values.allow_broken_recipemap) - inputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidInputs[i], true), - 48 - j % 3 * 18, - (j >= 3 ? 5 : 23))); } - - return inputStacks; + return super.getOverlayForSlot(isFluid, false, index, isSpecial); } @Override - public ArrayList<PositionedStack> getOutputPositionedStacks(GT_Recipe recipe) { - int fluidLimit = Math.min(recipe.mFluidOutputs.length, FLUID_OUTPUT_COUNT); - ArrayList<PositionedStack> outputStacks = new ArrayList<>(1 + fluidLimit); - - if (recipe.mOutputs.length > 0 && recipe.mOutputs[0] != null) { - outputStacks.add(new FixedPositionedStack(recipe.getOutput(0), 102, 52)); - } + public List<Pos2d> getItemOutputPositions(int itemOutputCount) { + return Collections.singletonList(new Pos2d(106, 62)); + } - for (int i = 0; i < fluidLimit; i++) { - int x = 102 + ((i + 1) % ROW_SIZE) * 18; - int y = 52 - ((i + 1) / ROW_SIZE) * 18; - outputStacks.add( - new FixedPositionedStack(GT_Utility.getFluidDisplayStack(recipe.mFluidOutputs[i], true), x, y)); + @Override + public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + List<Pos2d> results = new ArrayList<>(); + for (int i = 1; i < fluidOutputCount + 1; i++) { + results.add(new Pos2d(106 + (i % 3) * 18, 62 - (i / 3) * 18)); } - return outputStacks; + return results; } } @@ -5059,9 +5665,9 @@ public class GT_Recipe implements Comparable<GT_Recipe> { } } - public static class GT_Recipe_Map_PlasmaForge extends GT_Recipe_Map { + public static class GT_Recipe_Map_ComplexFusion extends GT_Recipe_Map { - public GT_Recipe_Map_PlasmaForge( + public GT_Recipe_Map_ComplexFusion( Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, @@ -5092,60 +5698,56 @@ public class GT_Recipe implements Comparable<GT_Recipe> { aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, - aNEIAllowed, - true); + aNEIAllowed); } @Override - public ArrayList<PositionedStack> getInputPositionedStacks(GT_Recipe recipe) { - ArrayList<PositionedStack> inputStacks = new ArrayList<>(); - int i = 0; - if (recipe.mInputs != null) { - for (int j = 0; j < recipe.mInputs.length; j++, i++) { - if (recipe.mInputs[j] == NI) continue; - inputStacks.add( - new FixedPositionedStack(recipe.mInputs[j].copy(), 12 + 18 * (i % 3), 5 + 18 * (i / 3))); - } - } - if (recipe.mFluidInputs != null) { - for (int j = 0; j < recipe.mFluidInputs.length; j++, i++) { - if (recipe.mFluidInputs[j] == NF) continue; - inputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidInputs[j], true), - 12 + 18 * (i % 3), - 5 + 18 * (i / 3))); - } - } - return inputStacks; + public GT_Recipe addRecipe( + int[] aOutputChances, + FluidStack[] aFluidInputs, + FluidStack[] aFluidOutputs, + int aDuration, + int aEUt, + int aSpecialValue) { + return addRecipe( + new GT_Recipe( + false, + null, + null, + null, + aOutputChances, + aFluidInputs, + aFluidOutputs, + aDuration, + aEUt, + aSpecialValue), + false, + false, + false); } @Override - public ArrayList<PositionedStack> getOutputPositionedStacks(GT_Recipe recipe) { - ArrayList<PositionedStack> outputStacks = new ArrayList<>(); - int i = 0; - if (recipe.mOutputs != null) { - for (int j = 0; j < recipe.mOutputs.length; j++, i++) { - if (recipe.mOutputs[j] == NI) continue; - outputStacks.add( - new FixedPositionedStack(recipe.mOutputs[j].copy(), 102 + 18 * (i % 3), 5 + 18 * (i / 3))); - } + public List<Pos2d> getFluidInputPositions(int fluidInputCount) { + List<Pos2d> results = new ArrayList<>(); + for (int i = 0; i < fluidInputCount; i++) { + results.add(new Pos2d(7 + (i % 4) * 18, 9 + (i / 4) * 18)); } - if (recipe.mFluidOutputs != null) { - for (int j = 0; j < recipe.mFluidOutputs.length; j++, i++) { - if (recipe.mFluidOutputs[j] == NF) continue; - outputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidOutputs[j], true), - 102 + 18 * (i % 3), - 5 + 18 * (i / 3))); - } + return results; + } + + @Override + public List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + List<Pos2d> results = new ArrayList<>(); + for (int i = 0; i < fluidOutputCount; i++) { + results.add(new Pos2d(97 + (i % 4) * 18, 9 + (i / 4) * 18)); } - return outputStacks; + return results; } } - public static class GT_Recipe_Map_ComplexFusion extends GT_Recipe_Map { + public static class GT_Recipe_Map_AssemblyLineFake extends GT_Recipe_Map { - public GT_Recipe_Map_ComplexFusion( + public GT_Recipe_Map_AssemblyLineFake( Collection<GT_Recipe> aRecipeList, String aUnlocalizedName, String aLocalName, @@ -5176,65 +5778,65 @@ public class GT_Recipe implements Comparable<GT_Recipe> { aNEISpecialValueMultiplier, aNEISpecialValuePost, aShowVoltageAmperageInNEI, - aNEIAllowed, - true); + aNEIAllowed); + setNEITransferRect(new Rectangle(146, 26, 10, 18)); } @Override - public GT_Recipe addRecipe( - int[] aOutputChances, - FluidStack[] aFluidInputs, - FluidStack[] aFluidOutputs, - int aDuration, - int aEUt, - int aSpecialValue) { - return addRecipe( - new GT_Recipe( - false, - null, - null, - null, - aOutputChances, - aFluidInputs, - aFluidOutputs, - aDuration, - aEUt, - aSpecialValue), - false, - false, - false); + public List<Pos2d> getItemInputPositions(int itemInputCount) { + List<Pos2d> results = new ArrayList<>(); + for (int i = 0; i < itemInputCount; i++) { + results.add(new Pos2d(16 + (i % 4) * 18, 8 + (i / 4) * 18)); + } + return results; } @Override - public ArrayList<PositionedStack> getInputPositionedStacks(GT_Recipe recipe) { - ArrayList<PositionedStack> inputStacks = new ArrayList<>(); - int i = 0; - if (recipe.mFluidInputs != null) { - for (int j = 0; j < recipe.mFluidInputs.length; j++, i++) { - if (recipe.mFluidInputs[j] == NF) continue; - inputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidInputs[j], true), - 3 + 18 * (i % 4), - -1 + 18 * (i / 4))); - } - } - return inputStacks; + public List<Pos2d> getItemOutputPositions(int itemOutputCount) { + return Collections.singletonList(new Pos2d(142, 8)); } @Override - public ArrayList<PositionedStack> getOutputPositionedStacks(GT_Recipe recipe) { - ArrayList<PositionedStack> outputStacks = new ArrayList<>(); - int i = 0; - if (recipe.mFluidOutputs != null) { - for (int j = 0; j < recipe.mFluidOutputs.length; j++, i++) { - if (recipe.mFluidOutputs[j] == NF) continue; - outputStacks.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(recipe.mFluidOutputs[j], true), - 93 + 18 * (i % 4), - -1 + 18 * (i / 4))); - } + public Pos2d getSpecialItemPosition() { + return new Pos2d(142, 44); + } + + @Override + public List<Pos2d> getFluidInputPositions(int fluidInputCount) { + List<Pos2d> results = new ArrayList<>(); + for (int i = 0; i < fluidInputCount; i++) { + results.add(new Pos2d(106, 8 + i * 18)); } - return outputStacks; + return results; + } + + @Override + protected void addProgressBarUI( + ModularWindow.Builder builder, Supplier<Float> progressSupplier, Pos2d windowOffset) { + int bar1Width = 17; + int bar2Width = 18; + builder.widget(new ProgressBar() + .setTexture(GT_UITextures.PROGRESSBAR_ASSEMBLY_LINE_1, 17) + .setDirection(ProgressBar.Direction.RIGHT) + .setProgress(() -> progressSupplier.get() * ((float) (bar1Width + bar2Width) / bar1Width)) + .setSynced(false, false) + .setPos(new Pos2d(88, 8).add(windowOffset)) + .setSize(bar1Width, 72)); + builder.widget(new ProgressBar() + .setTexture(GT_UITextures.PROGRESSBAR_ASSEMBLY_LINE_2, 18) + .setDirection(ProgressBar.Direction.RIGHT) + .setProgress(() -> (progressSupplier.get() - ((float) bar1Width / (bar1Width + bar2Width))) + * ((float) (bar1Width + bar2Width) / bar2Width)) + .setSynced(false, false) + .setPos(new Pos2d(124, 8).add(windowOffset)) + .setSize(bar2Width, 72)); + builder.widget(new ProgressBar() + .setTexture(GT_UITextures.PROGRESSBAR_ASSEMBLY_LINE_3, 18) + .setDirection(ProgressBar.Direction.UP) + .setProgress(progressSupplier) + .setSynced(false, false) + .setPos(new Pos2d(146, 26).add(windowOffset)) + .setSize(10, 18)); } } } diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 8db4c21dde..37ad05530c 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -70,8 +70,6 @@ import gregtech.api.util.GT_Shapeless_Recipe; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder; import gregtech.common.entities.GT_Entity_Arrow; -import gregtech.common.gui.GT_ContainerVolumetricFlask; -import gregtech.common.gui.GT_GUIContainerVolumetricFlask; import gregtech.common.items.GT_MetaGenerated_Item_98; import gregtech.common.items.GT_MetaGenerated_Tool_01; import gregtech.common.misc.GlobalEnergyWorldSavedData; @@ -646,6 +644,11 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG public int mTooltipShiftVerbosity = 3; /** + * Which style to use for title tab on machine GUI? 0: text tab split-dark, 1: text tab unified, 2: item icon tab + */ + public int mTitleTabStyle = 0; + + /** * Whether to show seconds or ticks on NEI */ public boolean mNEIRecipeSecondMode = true; @@ -2241,10 +2244,6 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG @Override public Object getServerGuiElement(int aID, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) { if (aID >= 1000) { - int ID = aID - 1000; - if (ID == 10) { - return new GT_ContainerVolumetricFlask(aPlayer.inventory); - } return null; } TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); @@ -2253,7 +2252,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG return null; } IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity(); - if (tMetaTileEntity != null) { + if (tMetaTileEntity != null && !tMetaTileEntity.useModularUI()) { return tMetaTileEntity.getServerGUI(aID, aPlayer.inventory, (IGregTechTileEntity) tTileEntity); } } @@ -2263,10 +2262,6 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG @Override public Object getClientGuiElement(int aID, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ) { if (aID >= 1000) { - int ID = aID - 1000; - if (ID == 10) { - return new GT_GUIContainerVolumetricFlask(new GT_ContainerVolumetricFlask(aPlayer.inventory)); - } return null; } TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); @@ -2277,7 +2272,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG byte side = (byte) (aID - GT_Proxy.GUI_ID_COVER_SIDE_BASE); GT_CoverBehaviorBase<?> cover = tile.getCoverBehaviorAtSideNew(side); - if (cover.hasCoverGUI()) { + if (cover.hasCoverGUI() && !cover.useModularUI()) { return cover.getClientGUI( side, tile.getCoverIDAtSide(side), @@ -2289,7 +2284,7 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler, IG return null; } IMetaTileEntity tMetaTileEntity = tile.getMetaTileEntity(); - if (tMetaTileEntity != null) { + if (tMetaTileEntity != null && !tMetaTileEntity.useModularUI()) { return tMetaTileEntity.getClientGUI(aID, aPlayer.inventory, tile); } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java index fb556989c1..6a7711a242 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Arm.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Arm.java @@ -1,19 +1,22 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiFakeItemButton; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; -import net.minecraft.client.gui.GuiButton; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.tileentity.TileEntity; @@ -28,6 +31,10 @@ public class GT_Cover_Arm extends GT_CoverBehavior { protected static final int SLOT_ID_MIN = 0; protected static final int CONVERTED_BIT = 0x80000000; + // This used to be translatable, but now that cover GUI is synced with server, having conflicting texts + // among players doesn't make sense. + private static final String ANY_TEXT = "Any"; + /** * @deprecated use {@link #GT_Cover_Arm(int aTickRate, ITexture coverTexture)} instead */ @@ -264,223 +271,182 @@ public class GT_Cover_Arm extends GT_CoverBehavior { return this.mTickRate; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_Cover_Arm.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private GT_GuiIntegerTextBox intSlot, adjSlot; - private GT_GuiFakeItemButton intSlotIcon, adjSlotIcon; - private int coverVariable; + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ArmUIFactory(buildContext).createWindow(); + } + + private class ArmUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final String ANY_TEXT = GT_Utility.trans("ANY", "Any"); - - private boolean export; - private int internalSlotID, adjacentSlotID; - private final int maxIntSlot, maxAdjSlot; - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - export = (coverVariable & EXPORT_MASK) > 0; - internalSlotID = (coverVariable & SLOT_ID_MASK); - adjacentSlotID = (coverVariable >> 14) & SLOT_ID_MASK; - - new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.EXPORT) - .setTooltipText(GT_Utility.trans("006", "Export")); - new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.IMPORT) - .setTooltipText(GT_Utility.trans("007", "Import")); - - intSlot = - new GT_GuiIntegerTextBox(this, 2, startX + spaceX * 0, startY + spaceY * 1 + 2, spaceX * 2 + 5, 12); - setBoxText(intSlot, internalSlotID - 1); - intSlot.setMaxStringLength(6); - - adjSlot = - new GT_GuiIntegerTextBox(this, 3, startX + spaceX * 0, startY + spaceY * 2 + 2, spaceX * 2 + 5, 12); - setBoxText(adjSlot, adjacentSlotID - 1); - adjSlot.setMaxStringLength(6); - - // intSlotIcon = new GT_GuiFakeItemButton(this, startX + spaceX * 8-4, startY + spaceY * 1, - // GT_GuiIcon.SLOT_GRAY); - // adjSlotIcon = new GT_GuiFakeItemButton(this, startX + spaceX * 8-4, startY + spaceY * 2, - // GT_GuiIcon.SLOT_GRAY); - - if (super.tile instanceof TileEntity && !super.tile.isDead()) { - maxIntSlot = tile.getSizeInventory() - 1; - - TileEntity adj = super.tile.getTileEntityAtSide(side); - if (adj instanceof IInventory) maxAdjSlot = ((IInventory) adj).getSizeInventory() - 1; - else maxAdjSlot = -1; - } else { - maxIntSlot = -1; - maxAdjSlot = -1; - } - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - if (export) - this.getFontRenderer() - .drawString( - GT_Utility.trans("006", "Export"), - startX + spaceX * 3, - 4 + startY + spaceY * 0, - textColor); - else - this.getFontRenderer() - .drawString( - GT_Utility.trans("007", "Import"), - startX + spaceX * 3, - 4 + startY + spaceY * 0, - textColor); - - this.getFontRenderer() - .drawString( - GT_Utility.trans("254.1", "Internal slot#"), - startX + spaceX * 3, - 4 + startY + spaceY * 1, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("255", "Adjacent slot#"), - startX + spaceX * 3, - 4 + startY + spaceY * 2, - textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - intSlot.setFocused(true); - updateButtons(); - - // updateInventorySlots(); - } + private int maxSlot; - @Override - public void buttonClicked(GuiButton btn) { - if (buttonClickable(btn.id)) { - export = btn.id == 0; - coverVariable = getNewCoverVariable(); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = buttonClickable(b.id); - } + protected ArmUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void onMouseWheel(int x, int y, int delta) { - for (GT_GuiIntegerTextBox box : textBoxes) { - if (box.isFocused()) { - int step = Math.max(1, Math.abs(delta / 120)); - step = (isShiftKeyDown() ? 50 : isCtrlKeyDown() ? 5 : 1) * (delta > 0 ? step : -step); - int maxSlot = box.id == 3 ? maxAdjSlot : maxIntSlot; - int val = parseTextBox(box, maxSlot); - if (val < 0) val = -1; - val = val + step; - - if (maxSlot < val) - if (maxSlot < 0) val = -1; - else val = maxSlot; - else if (val < SLOT_ID_MIN) val = -1; - - setBoxText(box, val); - return; - } - } + protected void addUIWidgets(ModularWindow.Builder builder) { + maxSlot = getMaxSlot(); + builder.widget(new CoverDataControllerWidget<>(this::getCoverData, this::setCoverData, GT_Cover_Arm.this) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> getFlagExport(convert(coverData)) > 0, + (coverData, state) -> { + if (state) { + return new ISerializableObject.LegacyCoverData( + convert(coverData) | EXPORT_MASK | CONVERTED_BIT); + } else { + return new ISerializableObject.LegacyCoverData( + convert(coverData) & ~EXPORT_MASK | CONVERTED_BIT); + } + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EXPORT) + .addTooltip(GT_Utility.trans("006", "Export")) + .setPos(spaceX * 0, spaceY * 0)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> getFlagExport(convert(coverData)) == 0, + (coverData, state) -> { + if (state) { + return new ISerializableObject.LegacyCoverData( + convert(coverData) & ~EXPORT_MASK | CONVERTED_BIT); + } else { + return new ISerializableObject.LegacyCoverData( + convert(coverData) | EXPORT_MASK | CONVERTED_BIT); + } + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_IMPORT) + .addTooltip(GT_Utility.trans("007", "Import")) + .setPos(spaceX * 1, spaceY * 0)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> getTextFieldContent(getFlagInternalSlot(convert(coverData)) - 1), + (coverData, state) -> { + final int coverVariable = convert(coverData); + return new ISerializableObject.LegacyCoverData(getFlagExport(coverVariable) + | ((getIntFromText(state) + 1) & SLOT_ID_MASK) + | (getFlagAdjacentSlot(coverVariable) << 14) + | CONVERTED_BIT); + }, + widget -> widget.setOnScrollText() + .setValidator(val -> { + final int valSlot = getIntFromText(val); + if (valSlot > -1) { + return TextFieldWidget.format.format(Math.min(valSlot, maxSlot)); + } else { + return ANY_TEXT; + } + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setFocusOnGuiOpen(true) + .setPos(spaceX * 0, spaceY * 1 + 2) + .setSize(spaceX * 2 + 5, 12)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> getTextFieldContent(getFlagAdjacentSlot(convert(coverData)) - 1), + (coverData, state) -> { + final int coverVariable = convert(coverData); + return new ISerializableObject.LegacyCoverData(getFlagExport(coverVariable) + | getFlagInternalSlot(coverVariable) + | (((getIntFromText(state) + 1) & SLOT_ID_MASK) << 14) + | CONVERTED_BIT); + }, + widget -> widget.setValidator(val -> { + final int valSlot = getIntFromText(val); + final int adjacentMaxSlot; + final ICoverable tile = + getUIBuildContext().getTile(); + if (tile instanceof TileEntity && !tile.isDead()) { + TileEntity adj = tile.getTileEntityAtSide( + getUIBuildContext().getCoverSide()); + if (adj instanceof IInventory) + adjacentMaxSlot = ((IInventory) adj).getSizeInventory() - 1; + else adjacentMaxSlot = -1; + } else { + adjacentMaxSlot = -1; + } + if (valSlot > -1) { + return TextFieldWidget.format.format( + Math.min(valSlot, adjacentMaxSlot)); + } else { + return ANY_TEXT; + } + }) + .setOnScroll((text, direction) -> { + final int val = getIntFromText(text); + int step = (GuiScreen.isShiftKeyDown() + ? 50 + : GuiScreen.isCtrlKeyDown() ? 5 : 1) + * direction; + return TextFieldWidget.format.format(val + step); + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setPos(spaceX * 0, spaceY * 2 + 2) + .setSize(spaceX * 2 + 5, 12)) + .setPos(startX, startY)) + .widget(TextWidget.dynamicString(() -> (convert(getCoverData()) & EXPORT_MASK) > 0 + ? GT_Utility.trans("006", "Export") + : GT_Utility.trans("007", "Import")) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("254.1", "Internal slot#")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("255", "Adjacent slot#")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY * 2)); } - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - int val = -1; - - if (box.id == 2) { - val = parseTextBox(box, maxIntSlot); - internalSlotID = val + 1; - } else if (box.id == 3) { - val = parseTextBox(box, maxAdjSlot); - adjacentSlotID = val + 1; + private int getMaxSlot() { + final ICoverable tile = getUIBuildContext().getTile(); + if (tile instanceof TileEntity && !tile.isDead()) { + return tile.getSizeInventory() - 1; + } else { + return -1; } - - setBoxText(box, val); - coverVariable = getNewCoverVariable(); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - // updateInventorySlots(); } - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - int val = 0; - if (box.id == 2) val = internalSlotID - 1; - else if (box.id == 3) val = adjacentSlotID - 1; - setBoxText(box, val); + private String getTextFieldContent(int val) { + return val < 0 ? ANY_TEXT : String.valueOf(val); } - private void setBoxText(GT_GuiIntegerTextBox box, int val) { - box.setText(val < 0 ? ANY_TEXT : String.valueOf(val)); - } - - private int parseTextBox(GT_GuiIntegerTextBox box, int maxSlot) { - String text = box.getText(); - if (text == null) return -1; - text = text.trim(); - if (text.startsWith(ANY_TEXT)) text = text.substring(ANY_TEXT.length()); - - if (text.isEmpty()) return -1; - - int val; + private int getIntFromText(String text) { try { - val = Integer.parseInt(text); - } catch (NumberFormatException e) { + return (int) MathExpression.parseMathExpression(text, -1); + } catch (Exception e) { return -1; } + } - if (maxSlot < val) - if (maxSlot < 0) return -1; - else return maxSlot; - else if (val < SLOT_ID_MIN) return SLOT_ID_MIN; - return val; + private int getFlagExport(int coverVariable) { + return coverVariable & EXPORT_MASK; } - private int getNewCoverVariable() { - return (export ? EXPORT_MASK : 0) - | ((adjacentSlotID & SLOT_ID_MASK) << 14) - | (internalSlotID & SLOT_ID_MASK) - | CONVERTED_BIT; + private int getFlagInternalSlot(int coverVariable) { + return coverVariable & SLOT_ID_MASK; } - private boolean buttonClickable(int id) { - if (id == 0) return !export; - return export; + private int getFlagAdjacentSlot(int coverVariable) { + return (coverVariable >> 14) & SLOT_ID_MASK; } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java index d8f09619bc..ee0a740d68 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ControlsWork.java @@ -1,17 +1,17 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; @@ -171,113 +171,103 @@ public class GT_Cover_ControlsWork extends GT_CoverBehavior { return true; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_Cover_ControlsWork.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ControlsWorkUIFactory(buildContext).createWindow(); + } + + private class ControlsWorkUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.REDSTONE_ON); - new GT_GuiIconButton(this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.REDSTONE_OFF); - new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CROSS); - - new GT_GuiIconCheckButton( - this, 3, startX + spaceX * 0, startY + spaceY * 3, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS) - .setChecked(aCoverVariable > 2); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("243", "Enable with Redstone"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 0, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("244", "Disable with Redstone"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 1, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("245", "Disable machine"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 2, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("507", "Safe Mode"), 3 + startX + spaceX * 1, 4 + startY + spaceY * 3, textColor); + public ControlsWorkUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_ControlsWork.this, + (id, coverData) -> !getClickable(id, convert(coverData)), + (id, coverData) -> new ISerializableObject.LegacyCoverData( + getNewCoverVariable(id, convert(coverData)))) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_ON) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_OFF) + .setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CROSS) + .setPos(spaceX * 0, spaceY * 2)) + .setPos(startX, startY)) + .widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_ControlsWork.this) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofCheckAndCross(), + coverData -> convert(coverData) > 2, + (coverData, state) -> new ISerializableObject.LegacyCoverData( + adjustCoverVariable(state, convert(coverData))), + widget -> widget.setPos(spaceX * 0, spaceY * 3)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("243", "Enable with Redstone")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("244", "Disable with Redstone")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("245", "Disable machine")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 2)) + .widget(new TextWidget(GT_Utility.trans("507", "Safe Mode")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 3)); } - @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - int bID = btn.id; - if (bID == 3) { - ((GT_GuiIconCheckButton) btn).setChecked(!((GT_GuiIconCheckButton) btn).isChecked()); - } else { - coverVariable = getNewCoverVariable(bID); - } - adjustCoverVariable(); - // TODO: Set lastPlayer; - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = getClickable(b.id); + private int getNewCoverVariable(int id, int coverVariable) { + if (coverVariable > 2) { + return id + 3; + } else { + return id; } } - private int getNewCoverVariable(int id) { - return id; - } - - private boolean getClickable(int id) { + private boolean getClickable(int id, int coverVariable) { return ((id != coverVariable && id != coverVariable - 3) || id == 3); } - private void adjustCoverVariable() { - boolean safeMode = ((GT_GuiIconCheckButton) buttonList.get(3)).isChecked(); - if (safeMode && coverVariable < 2) { + private int adjustCoverVariable(boolean safeMode, int coverVariable) { + if (safeMode && coverVariable <= 2) { coverVariable += 3; } if (!safeMode && coverVariable > 2) { coverVariable -= 3; } + return coverVariable; } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java b/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java index ebd87e85ab..dc3bcc4f7b 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Conveyor.java @@ -2,17 +2,18 @@ package gregtech.common.covers; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.Fluid; @@ -184,88 +185,99 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { return this.mTickRate; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_Cover_Conveyor.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ConveyorUIFactory(buildContext).createWindow(); } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + private class ConveyorUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - GT_GuiIconButton b; - b = new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.EXPORT) - .setTooltipText(GT_Utility.trans("006", "Export")); - b = new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.IMPORT) - .setTooltipText(GT_Utility.trans("007", "Import")); - b = new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK) - .setTooltipText(GT_Utility.trans("224", "Always On")); - b = new GT_GuiIconButton(this, 3, startX + spaceX * 1, startY + spaceY * 1, GT_GuiIcon.REDSTONE_ON) - .setTooltipText(GT_Utility.trans("225", "Active with Redstone Signal")); - b = new GT_GuiIconButton(this, 4, startX + spaceX * 2, startY + spaceY * 1, GT_GuiIcon.REDSTONE_OFF) - .setTooltipText(GT_Utility.trans("226", "Inactive with Redstone Signal")); - b = new GT_GuiIconButton(this, 5, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.ALLOW_INPUT) - .setTooltipText(GT_Utility.trans("227", "Allow Input")); - b = new GT_GuiIconButton(this, 6, startX + spaceX * 1, startY + spaceY * 2, GT_GuiIcon.BLOCK_INPUT) - .setTooltipText(GT_Utility.trans("228", "Block Input")); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("229", "Import/Export"), startX + spaceX * 3, 3 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("230", "Conditional"), startX + spaceX * 3, 3 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("231", "Enable Input"), startX + spaceX * 3, 3 + startY + spaceY * 2, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); + public ConveyorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - coverVariable = getNewCoverVariable(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_Conveyor.this, + (id, coverData) -> !getClickable(id, convert(coverData)), + (id, coverData) -> new ISerializableObject.LegacyCoverData( + getNewCoverVariable(id, convert(coverData)))) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EXPORT) + .addTooltip(GT_Utility.trans("006", "Export")) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_IMPORT) + .addTooltip(GT_Utility.trans("007", "Import")) + .setPos(spaceX * 1, spaceY * 0)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK) + .addTooltip(GT_Utility.trans("224", "Always On")) + .setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_ON) + .addTooltip(GT_Utility.trans("225", "Active with Redstone Signal")) + .setPos(spaceX * 1, spaceY * 1)) + .addToggleButton( + 4, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_OFF) + .addTooltip(GT_Utility.trans("226", "Inactive with Redstone Signal")) + .setPos(spaceX * 2, spaceY * 1)) + .addToggleButton( + 5, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_ALLOW_INPUT) + .addTooltip(GT_Utility.trans("227", "Allow Input")) + .setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 6, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_BLOCK_INPUT) + .addTooltip(GT_Utility.trans("228", "Block Input")) + .setPos(spaceX * 1, spaceY * 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("229", "Import/Export")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("230", "Conditional")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("231", "Enable Input")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 2)); } - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = getClickable(b.id); - } - } - - private int getNewCoverVariable(int id) { + private int getNewCoverVariable(int id, int coverVariable) { switch (id) { case 0: return coverVariable & ~0x1; @@ -289,9 +301,8 @@ public class GT_Cover_Conveyor extends GT_CoverBehavior { return coverVariable; } - private boolean getClickable(int id) { + private boolean getClickable(int id, int coverVariable) { if (coverVariable < 0 | 11 < coverVariable) return false; - switch (id) { case 0: case 1: diff --git a/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java b/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java index c37e4b5cbb..d755a115c4 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_DoesWork.java @@ -1,17 +1,17 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.Fluid; @@ -135,108 +135,96 @@ public class GT_Cover_DoesWork extends GT_CoverBehavior { return 5; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_Cover_DoesWork.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new DoesWorkUIFactory(buildContext).createWindow(); } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + private class DoesWorkUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - GuiButton b; - b = new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.PROGRESS); - b = new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.CHECKMARK); - b = new GT_GuiIconCheckButton( - this, 2, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.REDSTONE_ON, GT_GuiIcon.REDSTONE_OFF); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - String s1, s2; - if ((coverVariable & 0x2) > 0) s1 = GT_Utility.trans("242", "Machine idle"); - else s1 = GT_Utility.trans("241", "Recipe progress"); - if ((coverVariable & 0x1) > 0) s2 = GT_Utility.trans("INVERTED", "Inverted"); - else s2 = GT_Utility.trans("NORMAL", "Normal"); - this.fontRendererObj.drawString(s1, startX + spaceX * 3, 4 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString(s2, startX + spaceX * 3, 4 + startY + spaceY * 1, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); + public DoesWorkUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - boolean state = false; - if (btn.id == 2) state = ((GT_GuiIconCheckButton) btn).isChecked(); - - coverVariable = getNewCoverVariable(btn.id, state); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_DoesWork.this, + (id, coverData) -> isEnabled(id, convert(coverData)), + (id, coverData) -> new ISerializableObject.LegacyCoverData( + getNewCoverVariable(id, convert(coverData)))) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_PROGRESS) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK) + .setPos(spaceX * 1, spaceY * 0)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + widget -> widget.setPos(spaceX * 0, spaceY * 1)) + .setPos(startX, startY)) + .widget(TextWidget.dynamicString(() -> ((convert(getCoverData()) & 0x2) > 0) + ? GT_Utility.trans("242", "Machine idle") + : GT_Utility.trans("241", "Recipe progress")) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY * 0)) + .widget(TextWidget.dynamicString(() -> ((convert(getCoverData()) & 0x1) > 0) + ? GT_Utility.trans("INVERTED", "Inverted") + : GT_Utility.trans("NORMAL", "Normal")) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY * 1)); } - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - if (b.id == 2) { - ((GT_GuiIconCheckButton) b).setChecked((coverVariable & 0x1) > 0); - } else { - b.enabled = getClickable(b.id); - } - } - } - - private int getNewCoverVariable(int id, boolean buttonState) { + private int getNewCoverVariable(int id, int coverVariable) { switch (id) { case 0: return coverVariable & ~0x2; case 1: return coverVariable | 0x2; case 2: - if (buttonState) return coverVariable & ~0x1; + if ((coverVariable & 0x1) > 0) return coverVariable & ~0x1; return coverVariable | 0x1; } return coverVariable; } - private boolean getClickable(int id) { + private boolean isEnabled(int id, int coverVariable) { switch (id) { case 0: - return (coverVariable & 0x2) > 0; - case 1: return (coverVariable & 0x2) == 0; + case 1: + return (coverVariable & 0x2) > 0; case 2: - return true; + return (coverVariable & 0x1) > 0; } - return false; + return true; } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java index c9e7ef363a..fbac598d19 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_EUMeter.java @@ -1,31 +1,31 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicBatteryBuffer; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_CycleButtonWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import java.util.function.Function; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; public class GT_Cover_EUMeter extends GT_CoverBehaviorBase<GT_Cover_EUMeter.EUMeterData> { @@ -208,15 +208,85 @@ public class GT_Cover_EUMeter extends GT_CoverBehaviorBase<GT_Cover_EUMeter.EUMe } @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - EUMeterData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new EUMeterUIFactory(buildContext).createWindow(); + } + + private class EUMeterUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + + public EUMeterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); + final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); + + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_EUMeter.this) + .addFollower( + new CoverDataFollower_CycleButtonWidget<>(), + coverData -> coverData.type.ordinal(), + (coverData, state) -> { + coverData.type = EnergyType.getEnergyType(state); + return coverData; + }, + widget -> widget.setLength(EnergyType.values().length) + .addTooltip(state -> EnergyType.getEnergyType(state) + .getTooltip()) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CYCLIC) + .setPos(spaceX * 0, spaceY * 0)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + coverData -> coverData.inverted, + (coverData, state) -> { + coverData.inverted = state; + return coverData; + }, + widget -> widget.addTooltip(0, NORMAL) + .addTooltip(1, INVERTED) + .setPos(spaceX * 0, spaceY * 1)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.threshold), + (coverData, state) -> { + coverData.threshold = (long) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbersLong(1000, 100, 100000) + .setNumbersLong(() -> 0L, () -> Long.MAX_VALUE) + .setFocusOnGuiOpen(true) + .setPos(spaceX * 0, spaceY * 2 + 2) + .setSize(spaceX * 8, 12)) + .setPos(startX, startY)) + .widget(TextWidget.dynamicString(() -> + getCoverData() != null ? getCoverData().type.getTitle() : "") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX, 4 + startY)) + .widget(TextWidget.dynamicString( + () -> getCoverData() != null ? getCoverData().inverted ? INVERTED : NORMAL : "") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX, 4 + startY + spaceY)) + .widget(new TextWidget(GT_Utility.trans("222.1", "Energy threshold")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX, startY + spaceY * 3 + 4)); + } } + // endregion public static class EUMeterData implements ISerializableObject { @@ -390,138 +460,4 @@ public class GT_Cover_EUMeter extends GT_CoverBehaviorBase<GT_Cover_EUMeter.EUMe return values()[ordinal]; } } - - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private final GT_GuiIconButton typeButton; - private final GT_GuiIconCheckButton invertedButton; - private final GT_GuiIntegerTextBox thresholdSlot; - private final EUMeterData coverVariable; - - private static final int startX = 10; - private static final int startY = 25; - private static final int spaceX = 18; - private static final int spaceY = 18; - - private final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); - private final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, EUMeterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - typeButton = new GT_GuiIconButton(this, 0, startX, startY, GT_GuiIcon.CYCLIC); - invertedButton = new GT_GuiIconCheckButton( - this, - 2, - startX, - startY + spaceY, - GT_GuiIcon.REDSTONE_ON, - GT_GuiIcon.REDSTONE_OFF, - INVERTED, - NORMAL); - thresholdSlot = new GT_GuiIntegerTextBox(this, 4, startX, startY + spaceY * 2 + 2, spaceX * 8, 12); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer().drawString(coverVariable.type.getTitle(), startX + spaceX, 4 + startY, textColor); - this.getFontRenderer() - .drawString( - coverVariable.inverted ? INVERTED : NORMAL, - startX + spaceX, - 4 + startY + spaceY, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("222.1", "Energy threshold"), startX, startY + spaceY * 3 + 4, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - update(); - thresholdSlot.setFocused(true); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (btn == typeButton) { - coverVariable.type = coverVariable.type.getNext(); - } - if (btn == invertedButton) { - coverVariable.inverted = !coverVariable.inverted; - } - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - if (thresholdSlot.isFocused()) { - long val = parseTextBox(thresholdSlot); - - long step = 1000; - if (isShiftKeyDown()) { - step *= 100; - } - if (isCtrlKeyDown()) { - step /= 10; - } - - try { - val = Math.addExact(val, delta * step); - } catch (ArithmeticException e) { - val = Long.MAX_VALUE; - } - val = Math.max(0, val); - thresholdSlot.setText(Long.toString(val)); - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - coverVariable.threshold = parseTextBox(thresholdSlot); - } - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - thresholdSlot.setText(Long.toString(coverVariable.threshold)); - } - } - - private void update() { - invertedButton.setChecked(coverVariable.inverted); - typeButton.setTooltipText(coverVariable.type.getTooltip()); - resetTextBox(thresholdSlot); - } - - private long parseTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - String text = box.getText(); - if (text == null) { - return 0; - } - long val; - try { - val = Long.parseLong(text.trim()); - } catch (NumberFormatException e) { - return 0; - } - return Math.max(0, val); - } - throw new UnsupportedOperationException("Unknown text box: " + box); - } - } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FacadeBase.java b/src/main/java/gregtech/common/covers/GT_Cover_FacadeBase.java index 8c52ade5d2..a2707043ef 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FacadeBase.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FacadeBase.java @@ -1,30 +1,29 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import cpw.mods.fml.common.network.ByteBufUtils; -import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_RenderingWorld; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; import net.minecraft.block.Block; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -301,94 +300,91 @@ public abstract class GT_Cover_FacadeBase extends GT_CoverBehaviorBase<GT_Cover_ } } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - FacadeData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GT_Cover_FacadeBase.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new FacadeBaseUIFactory(buildContext).createWindow(); } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private FacadeData coverVariable; + private class FacadeBaseUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, FacadeData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, aCoverVariable.mStack); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - new GT_GuiIconCheckButton( - this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS) - .setChecked((coverVariable.mFlags & 0x1) == 0); - new GT_GuiIconCheckButton( - this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS) - .setChecked((coverVariable.mFlags & 0x2) == 0); - new GT_GuiIconCheckButton( - this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS) - .setChecked((coverVariable.mFlags & 0x4) == 0); - new GT_GuiIconCheckButton( - this, 3, startX + spaceX * 0, startY + spaceY * 3, GT_GuiIcon.CHECKMARK, GT_GuiIcon.CROSS) - .setChecked((coverVariable.mFlags & 0x8) == 0); + public FacadeBaseUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("128", "Redstone"), 3 + startX + spaceX * 1, 4 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("129", "Energy"), 3 + startX + spaceX * 1, 4 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("130", "Fluids"), 3 + startX + spaceX * 1, 4 + startY + spaceY * 2, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("131", "Items"), 3 + startX + spaceX * 1, 4 + startY + spaceY * 3, textColor); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_FacadeBase.this, + this::isEnabled, + (id, coverData) -> { + coverData.mFlags = getNewCoverVariable(id, coverData); + return coverData; + }) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofCheckAndCross(), + widget -> widget.setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofCheckAndCross(), + widget -> widget.setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofCheckAndCross(), + widget -> widget.setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofCheckAndCross(), + widget -> widget.setPos(spaceX * 0, spaceY * 3)) + .setPos(startX, startY)) + .widget(new ItemDrawable(() -> getCoverData() != null ? getCoverData().mStack : null) + .asWidget() + .setPos(5, 5) + .setSize(16, 16)) + .widget(TextWidget.dynamicString(() -> getCoverData() != null + ? getCoverData().mStack.getDisplayName() + : "") + .setSynced(false) + .setDefaultColor(COLOR_TITLE.get()) + .setPos(25, 9)) + .widget(new TextWidget(GT_Utility.trans("128", "Redstone")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("129", "Energy")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("130", "Fluids")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 2)) + .widget(new TextWidget(GT_Utility.trans("131", "Items")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 3)); } @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } + protected void addTitleToUI(ModularWindow.Builder builder) {} - @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - coverVariable.mFlags = getNewCoverVariable(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - GT_GuiIconCheckButton b; - for (Object o : buttonList) { - b = (GT_GuiIconCheckButton) o; - b.enabled = getClickable(b.id); - b.setChecked((coverVariable.mFlags & (1 << b.id)) != 0); - } - } - - private int getNewCoverVariable(int id) { + private int getNewCoverVariable(int id, FacadeData coverVariable) { switch (id) { case 0: return coverVariable.mFlags ^ 0x1; @@ -402,8 +398,18 @@ public abstract class GT_Cover_FacadeBase extends GT_CoverBehaviorBase<GT_Cover_ return coverVariable.mFlags; } - private boolean getClickable(int id) { - return coverVariable.mFlags >= 0 && coverVariable.mFlags <= 15; + private boolean isEnabled(int id, FacadeData coverVariable) { + switch (id) { + case 0: + return (coverVariable.mFlags & 0x1) > 0; + case 1: + return (coverVariable.mFlags & 0x2) > 0; + case 2: + return (coverVariable.mFlags & 0x4) > 0; + case 3: + return (coverVariable.mFlags & 0x8) > 0; + } + return false; } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java index 0dffd08c5e..b8200aeac6 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidLimiter.java @@ -1,15 +1,17 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -17,7 +19,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidTankInfo; @@ -168,82 +169,52 @@ public class GT_Cover_FluidLimiter extends GT_CoverBehaviorBase<GT_Cover_FluidLi } } - /* - GUI - */ + // GUI stuff @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - FluidLimiterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public boolean hasCoverGUI() { + return true; } @Override - public boolean hasCoverGUI() { + public boolean useModularUI() { return true; } - private static class GUI extends GT_GUICover { + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new FluidLimiterUIFactory(buildContext).createWindow(); + } + + private class FluidLimiterUIFactory extends UIFactory { + private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final byte side; - private final int coverID; - private final FluidLimiterData coverVariable; - private final GT_GuiIntegerTextBox thresholdBox; - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, FluidLimiterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - thresholdBox = new GT_GuiIntegerTextBox(this, 2, startX, startY + spaceY * 2 - 24, spaceX * 4 - 3, 12) { - @Override - public boolean validChar(char c, int key) { - return super.validChar(c, key) || c == '-'; - } - }; - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer().drawString("Percent threshold", startX, startY + spaceY * 2 - 35, textColor); - } - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - thresholdBox.setFocused(true); - String text; - text = this.coverVariable != null ? String.valueOf(Math.round(this.coverVariable.threshold * 100)) : ""; - thresholdBox.setText(text); + public FluidLimiterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - int percent; - try { - percent = Integer.parseInt(box.getText().trim()); - } catch (NumberFormatException ignored) { - resetTextBox(thresholdBox); - return; - } - - if (percent > 100 || percent <= 0) return; - this.coverVariable.threshold = percent / 100F; - - box.setText(String.valueOf(percent)); - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_FluidLimiter.this) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(Math.round(coverData.threshold * 100)), + (coverData, val) -> { + coverData.threshold = (float) (MathExpression.parseMathExpression(val) / 100); + return coverData; + }, + widget -> widget.setNumbers(0, 100) + .setFocusOnGuiOpen(true) + .setPos(startX, startY + spaceY * 2 - 24) + .setSize(spaceX * 4 - 3, 12))) + .widget(new TextWidget("Percent threshold") + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX, startY + spaceY * 2 - 35)); } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java index 2d6fc685c3..ad8f5bb2de 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java @@ -1,27 +1,30 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; +import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -253,23 +256,171 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehaviorBase<GT_Cover_Fluid return aCoverVariable.tickRate; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - FluidRegulatorData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GT_Cover_FluidRegulator.GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new FluidRegulatorUIFactory(buildContext).createWindow(); + } + + private class FluidRegulatorUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + + public FluidRegulatorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + AtomicBoolean warn = new AtomicBoolean(false); + + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_FluidRegulator.this) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.speed >= 0, + (coverData, state) -> { + coverData.speed = Math.abs(coverData.speed); + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EXPORT) + .addTooltip(GT_Utility.trans("006", "Export")) + .setPos(spaceX * 0, spaceY * 0)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.speed <= 0, + (coverData, state) -> { + coverData.speed = -Math.abs(coverData.speed); + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_IMPORT) + .addTooltip(GT_Utility.trans("007", "Import")) + .setPos(spaceX * 1, spaceY * 0)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.condition == Conditional.Always, + (coverData, state) -> { + coverData.condition = Conditional.Always; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK) + .addTooltip(GT_Utility.trans("224", "Always On")) + .setPos(spaceX * 0, spaceY * 1)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.condition == Conditional.Conditional, + (coverData, state) -> { + coverData.condition = Conditional.Conditional; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_ON) + .addTooltip(GT_Utility.trans("225", "Active with Redstone Signal")) + .setPos(spaceX * 1, spaceY * 1)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.condition == Conditional.Inverted, + (coverData, state) -> { + coverData.condition = Conditional.Inverted; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_OFF) + .addTooltip(GT_Utility.trans("226", "Inactive with Redstone Signal")) + .setPos(spaceX * 2, spaceY * 1)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.speed), + (coverData, state) -> { + coverData.speed = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbersLong(1, 5, 50) + .setNumbersLong(val -> { + final int tickRate = + getCoverData() != null ? getCoverData().tickRate : 0; + final long maxFlow = (long) mTransferRate + * GT_Utility.clamp(tickRate, TICK_RATE_MIN, TICK_RATE_MAX); + warn.set(false); + if (val > maxFlow) { + val = maxFlow; + warn.set(true); + } else if (val < -maxFlow) { + val = -maxFlow; + warn.set(true); + } + return val; + }) + .setPattern(BaseTextFieldWidget.WHOLE_NUMS) + .setFocusOnGuiOpen(true) + .setPos(spaceX * 0, spaceY * 2 + 2) + .setSize(spaceX * 4 - 3, 12)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.tickRate), + (coverData, state) -> { + coverData.tickRate = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbersLong(1, 5, 50) + .setNumbersLong(val -> { + final int speed = getCoverData() != null ? getCoverData().speed : 0; + warn.set(false); + if (val > TICK_RATE_MAX) { + val = (long) TICK_RATE_MAX; + warn.set(true); + } else if (Math.abs(speed) > mTransferRate * val) { + val = (long) Math.min( + TICK_RATE_MAX, + (Math.abs(speed) + mTransferRate - 1) / mTransferRate); + warn.set(true); + } else if (val < TICK_RATE_MIN) { + val = 1L; + } + return val; + }) + .setPattern(BaseTextFieldWidget.WHOLE_NUMS) + .setPos(spaceX * 5, spaceY * 2 + 2) + .setSize(spaceX * 2 - 3, 12)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("229", "Import/Export")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 4, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("230", "Conditional")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 4, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("208", " L")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 4, 4 + startY + spaceY * 2)) + .widget(new TextWidget(GT_Utility.trans("209", " ticks")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 7, 4 + startY + spaceY * 2)) + .widget(TextWidget.dynamicText(() -> { + FluidRegulatorData coverVariable = getCoverData(); + if (coverVariable == null) return new Text(""); + return new Text(String.format( + GT_Utility.trans("210", "Average: %.2f L/sec"), + coverVariable.tickRate == 0 + ? 0 + : coverVariable.speed * 20d / coverVariable.tickRate)) + .color(warn.get() ? COLOR_TEXT_WARN.get() : COLOR_TEXT_GRAY.get()); + }) + .setSynced(false) + .setPos(startX + spaceX * 0, 4 + startY + spaceY * 3)); + } } public enum Conditional { @@ -397,214 +548,4 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehaviorBase<GT_Cover_Fluid this.condition = condition; } } - - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private GT_GuiIntegerTextBox tBox, lBox; - private FluidRegulatorData coverVariable; - - private static final int startX = 10; - private static final int startY = 25; - private static final int spaceX = 18; - private static final int spaceY = 18; - - private boolean warn = false; - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555), - textColorValue = this.getTextColorOrDefault("value", 0xFFFF0000); - - public GUI(byte aSide, int aCoverID, FluidRegulatorData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.EXPORT) - .setTooltipText(GT_Utility.trans("006", "Export")); - new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.IMPORT) - .setTooltipText(GT_Utility.trans("007", "Import")); - new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK) - .setTooltipText(GT_Utility.trans("224", "Always On")); - new GT_GuiIconButton(this, 3, startX + spaceX * 1, startY + spaceY * 1, GT_GuiIcon.REDSTONE_ON) - .setTooltipText(GT_Utility.trans("225", "Active with Redstone Signal")); - new GT_GuiIconButton(this, 4, startX + spaceX * 2, startY + spaceY * 1, GT_GuiIcon.REDSTONE_OFF) - .setTooltipText(GT_Utility.trans("226", "Inactive with Redstone Signal")); - - tBox = new GT_GuiIntegerTextBox(this, 2, startX + spaceX * 0, startY + spaceY * 2 + 2, spaceX * 4 - 3, 12) { - @Override - public boolean validChar(char c, int key) { - return super.validChar(c, key) || c == '-'; - } - }; - tBox.setText(String.valueOf(this.coverVariable.speed)); - tBox.setMaxStringLength(10); - - lBox = new GT_GuiIntegerTextBox(this, 3, startX + spaceX * 5, startY + spaceY * 2 + 2, spaceX * 2 - 3, 12) { - @Override - public boolean validChar(char c, int key) { - return super.validChar(c, key) || c == '-'; - } - }; - lBox.setText(String.valueOf(this.coverVariable.tickRate)); - lBox.setMaxStringLength(4); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - GT_Utility.trans("229", "Import/Export"), - startX + spaceX * 4, - 4 + startY + spaceY * 0, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("230", "Conditional"), - startX + spaceX * 4, - 4 + startY + spaceY * 1, - textColor); - this.getFontRenderer() - .drawString(GT_Utility.trans("208", " L"), startX + spaceX * 4, 4 + startY + spaceY * 2, textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("209", " ticks"), startX + spaceX * 7, 4 + startY + spaceY * 2, textColor); - this.getFontRenderer() - .drawString( - String.format( - GT_Utility.trans("210", "Average: %.2f L/sec"), - coverVariable.tickRate == 0 - ? 0 - : coverVariable.speed * 20d / coverVariable.tickRate), - startX + spaceX * 0, - 4 + startY + spaceY * 3, - warn ? textColorValue : textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - tBox.setFocused(true); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (!btn.enabled) return; - switch (btn.id) { - case 0: - case 1: - coverVariable.speed *= -1; - for (GT_GuiIntegerTextBox box : textBoxes) { - if (box.id == 2) { - box.setText(String.valueOf(coverVariable.speed)); - } - } - break; - case 2: - case 3: - case 4: - coverVariable.condition = Conditional.VALUES[btn.id - 2]; - break; - default: - // not right, but we carry on - return; - } - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - updateButtons(); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - for (GT_GuiIntegerTextBox box : textBoxes) { - if (box.isFocused()) { - int step = Math.max(1, Math.abs(delta / 120)); - step = (isShiftKeyDown() ? 50 : isCtrlKeyDown() ? 5 : 1) * (delta > 0 ? step : -step); - long i; - try { - i = Long.parseLong(box.getText()); - } catch (NumberFormatException e) { - return; - } - if (i > (Long.MAX_VALUE - 1000)) break; - - i = i + step; - if (i <= 0) i = 0; - box.setText(String.valueOf(i)); - break; - } - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - long i; - String s = box.getText().trim(); - try { - i = Long.parseLong(s); - } catch (NumberFormatException e) { - resetTextBox(box); - return; - } - - warn = false; - if (box.id == 2) { - long maxFlow = - (long) mTransferRate * GT_Utility.clamp(coverVariable.tickRate, TICK_RATE_MIN, TICK_RATE_MAX); - if (i > maxFlow) { - i = maxFlow; - warn = true; - } else if (i < -maxFlow) { - i = -maxFlow; - warn = true; - } - if (!warn && coverVariable.speed == i) return; - coverVariable.speed = (int) i; - } else if (box.id == 3) { - if (i > TICK_RATE_MAX) { - i = TICK_RATE_MAX; - warn = true; - } else if (Math.abs(coverVariable.speed) > mTransferRate * i) { - i = Math.min(TICK_RATE_MAX, (Math.abs(coverVariable.speed) + mTransferRate - 1) / mTransferRate); - warn = true; - } else if (i < TICK_RATE_MIN) { - i = 1; - } - if (!warn && coverVariable.tickRate == i) return; - coverVariable.tickRate = (int) i; - } - box.setText(String.valueOf(i)); - updateButtons(); - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - } - - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - if (box.id == 2) box.setText(String.valueOf(coverVariable.speed)); - else if (box.id == 3) box.setText(String.valueOf(coverVariable.tickRate)); - } - - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = getClickable(b.id); - } - } - - private boolean getClickable(int id) { - switch (id) { - case 0: - return coverVariable.speed < 0; - case 1: - return coverVariable.speed > 0; - case 2: - case 3: - case 4: - return coverVariable.condition != Conditional.VALUES[id - 2]; - } - return false; - } - } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java index 6c1a1ae165..54872f849a 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Fluidfilter.java @@ -3,26 +3,27 @@ package gregtech.common.covers; import static gregtech.api.enums.GT_Values.E; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiFakeItemButton; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_SlotWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; @@ -250,67 +251,136 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehaviorBase<GT_Cover_Fluidfil return 0; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - FluidFilterData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GT_FluidFilterGUICover(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new FluidFilterUIFactory(buildContext).createWindow(); } - private class GT_FluidFilterGUICover extends GT_GUICover { - private final byte side; - private final int coverID; - private final FluidFilterData coverVariable; - private final GT_GuiFakeItemButton fluidFilterButton; - protected String fluidFilterName; + private class FluidFilterUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555), - textColorTitle = this.getTextColorOrDefault("title", 0xFF222222); - - public GT_FluidFilterGUICover( - byte aSide, int aCoverID, FluidFilterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - GT_GuiIconButton b; - b = new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.IMPORT) - .setTooltipText(GT_Utility.trans("232", "Filter Input")); - b = new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.EXPORT) - .setTooltipText(GT_Utility.trans("233", "Filter Output")); - b = new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.BLOCK_INPUT) - .setTooltipText(GT_Utility.trans("234", "Block Output")); - b = new GT_GuiIconButton(this, 3, startX + spaceX * 1, startY + spaceY * 2, GT_GuiIcon.ALLOW_INPUT) - .setTooltipText(GT_Utility.trans("235", "Allow Output")); - b = new GT_GuiIconButton(this, 4, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.WHITELIST) - .setTooltipText(GT_Utility.trans("236", "Whitelist Fluid")); - b = new GT_GuiIconButton(this, 5, startX + spaceX * 1, startY + spaceY * 1, GT_GuiIcon.BLACKLIST) - .setTooltipText(GT_Utility.trans("237", "Blacklist Fluid")); - - fluidFilterButton = - new GT_GuiFakeItemButton(this, startX, startY + spaceY * 3 + 2, GT_GuiIcon.SLOT_DARKGRAY); - fluidFilterButton.setMimicSlot(true); + public FluidFilterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_Fluidfilter.this, + (id, coverData) -> !getClickable(id, coverData), + (id, coverData) -> { + coverData.mFilterMode = getNewFilterMode(id, coverData); + return coverData; + }) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_IMPORT) + .addTooltip(GT_Utility.trans("232", "Filter Input")) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EXPORT) + .addTooltip(GT_Utility.trans("233", "Filter Output")) + .setPos(spaceX * 1, spaceY * 0)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_BLOCK_INPUT) + .addTooltip(GT_Utility.trans("234", "Block Output")) + .setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_ALLOW_INPUT) + .addTooltip(GT_Utility.trans("235", "Allow Output")) + .setPos(spaceX * 1, spaceY * 2)) + .addToggleButton( + 4, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_WHITELIST) + .addTooltip(GT_Utility.trans("236", "Whitelist Fluid")) + .setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 5, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_BLACKLIST) + .addTooltip(GT_Utility.trans("237", "Blacklist Fluid")) + .setPos(spaceX * 1, spaceY * 1)) + .addFollower( + new CoverDataFollower_SlotWidget<FluidFilterData>(new ItemStackHandler(), 0, true) { + @Override + protected void putClickedStack(ItemStack stack, int mouseButton) { + if (stack != null + && GT_Utility.getFluidFromContainerOrFluidDisplay(stack) == null) + return; + super.putClickedStack( + GT_Utility.getFluidDisplayStack( + GT_Utility.getFluidFromContainerOrFluidDisplay(stack), + false), + mouseButton); + } + }, + this::getFluidDisplayItem, + (coverData, stack) -> { + if (stack == null) { + coverData.mFluidID = -1; + } else { + FluidStack fluid = GT_Utility.getFluidFromDisplayStack(stack); + if (fluid != null && fluid.getFluid() != null) { + coverData.mFluidID = + fluid.getFluid().getID(); + } + } + return coverData; + }, + widget -> widget.setBackground(ModularUITextures.FLUID_SLOT) + .setPos(0, spaceY * 3 + 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("238", "Filter Direction")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 2, 3 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("239", "Filter Type")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 2, 3 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("240", "Block Flow")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 2, 3 + startY + spaceY * 2)) + .widget(TextWidget.dynamicString(() -> { + if (getCoverData() != null) { + ItemStack fluidDisplay = getFluidDisplayItem(getCoverData()); + if (fluidDisplay != null) { + return fluidDisplay.getDisplayName(); + } + } + return GT_Utility.trans("315", "Filter Empty"); + }) + .setSynced(false) + .setDefaultColor(COLOR_TITLE.get()) + .setPos(startX + spaceX + 3, 4 + startY + spaceY * 3)); } - private int getNewFilterMode(int id) { + private int getNewFilterMode(int id, FluidFilterData coverVariable) { switch (id) { case 0: return (coverVariable.mFilterMode & 0x3); @@ -328,7 +398,7 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehaviorBase<GT_Cover_Fluidfil return coverVariable.mFilterMode; } - private boolean getClickable(int id) { + private boolean getClickable(int id, FluidFilterData coverVariable) { switch (id) { case 0: case 1: @@ -343,62 +413,9 @@ public class GT_Cover_Fluidfilter extends GT_CoverBehaviorBase<GT_Cover_Fluidfil return false; } - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("238", "Filter Direction"), - startX + spaceX * 2, - 3 + startY + spaceY * 0, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("239", "Filter Type"), startX + spaceX * 2, 3 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("240", "Block Flow"), startX + spaceX * 2, 3 + startY + spaceY * 2, textColor); - this.fontRendererObj.drawSplitString( - fluidFilterName, startX + spaceX + 3, 4 + startY + spaceY * 3, gui_width - 40, textColorTitle); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - coverVariable.mFilterMode = (byte) getNewFilterMode(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - GT_GuiIconButton b; - for (Object o : buttonList) { - if (o instanceof GT_GuiIconButton) { - b = (GT_GuiIconButton) o; - b.enabled = getClickable(b.id); - if (getClickable(1)) { // filtering input - if (b.id == 2) b.setTooltipText(GT_Utility.trans("311", "Block Output")); - else if (b.id == 3) b.setTooltipText(GT_Utility.trans("312", "Allow Output")); - } else { - if (b.id == 2) b.setTooltipText(GT_Utility.trans("313", "Block Input")); - else if (b.id == 3) b.setTooltipText(GT_Utility.trans("314", "Allow Input")); - } - } - } - Fluid f = FluidRegistry.getFluid(coverVariable.mFluidID); - if (f != null) { - ItemStack item = GT_Utility.getFluidDisplayStack(f); - if (item != null) { - fluidFilterButton.setItem(item); - fluidFilterName = item.getDisplayName(); - return; - } - } - fluidFilterButton.setItem(null); - fluidFilterName = GT_Utility.trans("315", "Filter Empty"); + private ItemStack getFluidDisplayItem(FluidFilterData coverData) { + Fluid fluid = FluidRegistry.getFluid(coverData.mFluidID); + return GT_Utility.getFluidDisplayStack(fluid); } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java index 2fa545d76d..1580ac6ce5 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemFilter.java @@ -4,30 +4,30 @@ import static gregtech.api.util.GT_Utility.intToStack; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; import com.google.common.io.ByteArrayDataInput; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import cpw.mods.fml.common.network.ByteBufUtils; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiFakeItemButton; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_SlotWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; import net.minecraftforge.fluids.Fluid; @@ -194,23 +194,80 @@ public class GT_Cover_ItemFilter extends GT_CoverBehaviorBase<GT_Cover_ItemFilte return 1; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - ItemFilterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GT_Cover_ItemFilter.GUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ItemFilterUIFactory(buildContext).createWindow(); + } + + private class ItemFilterUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + + public ItemFilterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + ItemStackHandler filterInvHandler = new ItemStackHandler(1); + if (getCoverData() != null) { + filterInvHandler.setStackInSlot(0, setStackSize1(getCoverData().mFilter)); + } + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_ItemFilter.this) + .addFollower( + new CoverDataFollower_ToggleButtonWidget<>(), + coverData -> coverData.mWhitelist, + (coverData, state) -> { + coverData.mWhitelist = state; + return coverData; + }, + widget -> widget.setToggleTexture( + GT_UITextures.OVERLAY_BUTTON_WHITELIST, + GT_UITextures.OVERLAY_BUTTON_BLACKLIST) + .addTooltip(0, GT_Utility.trans("124.1", "Blacklist Mode")) + .addTooltip(1, GT_Utility.trans("125.1", "Whitelist Mode")) + .setPos(spaceX * 0, spaceY * 0)) + .addFollower( + new CoverDataFollower_SlotWidget<>(filterInvHandler, 0, true), + coverData -> setStackSize1(coverData.mFilter), + (coverData, stack) -> { + coverData.mFilter = setStackSize1(stack); + return coverData; + }, + widget -> widget.setBackground(GT_UITextures.SLOT_DARK_GRAY) + .setPos(spaceX * 0, spaceY * 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("317", "Filter: ")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 0, 3 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("318", "Check Mode")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 2, 3 + startY + spaceY * 0)); + } + + private ItemStack setStackSize1(ItemStack stack) { + if (stack != null) { + stack.stackSize = 1; + } + return stack; + } } public static class ItemFilterData implements ISerializableObject { @@ -262,68 +319,4 @@ public class GT_Cover_ItemFilter extends GT_CoverBehaviorBase<GT_Cover_ItemFilte return this; } } - - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private final GT_GuiIconCheckButton btnMode; - private final ItemFilterData coverVariable; - private final GT_GuiFakeItemButton itemFilterButtons; - - private static final int startX = 10; - private static final int startY = 25; - private static final int spaceX = 18; - private static final int spaceY = 18; - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, ItemFilterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - btnMode = new GT_GuiIconCheckButton( - this, - 0, - startX + spaceX * 0, - startY + spaceY * 0, - GT_GuiIcon.WHITELIST, - GT_GuiIcon.BLACKLIST, - GT_Utility.trans("125.1", "Whitelist Mode"), - GT_Utility.trans("124.1", "Blacklist Mode")); - - itemFilterButtons = - new GT_GuiFakeItemButton(this, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.SLOT_GRAY); - itemFilterButtons.setMimicSlot(true); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("317", "Filter: "), startX + spaceX * 0, 3 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("318", "Check Mode"), startX + spaceX * 2, 3 + startY + spaceY * 0, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (btn == btnMode) { - coverVariable.mWhitelist = !coverVariable.mWhitelist; - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - btnMode.setChecked(coverVariable.mWhitelist); - itemFilterButtons.setItem(coverVariable.mFilter); - } - } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java index c894857b32..6724e36975 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_ItemMeter.java @@ -1,33 +1,34 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiFakeItemButton; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; +import gregtech.common.gui.modularui.widget.ItemWatcherSlotWidget; import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import io.netty.buffer.ByteBuf; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; public class GT_Cover_ItemMeter extends GT_CoverBehaviorBase<GT_Cover_ItemMeter.ItemMeterData> { @@ -195,23 +196,144 @@ public class GT_Cover_ItemMeter extends GT_CoverBehaviorBase<GT_Cover_ItemMeter. return 5; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - protected Object getClientGUIImpl( - byte aSide, - int aCoverID, - ItemMeterData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ItemMeterUIFactory(buildContext).createWindow(); + } + + private class ItemMeterUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + private static final String ALL_TEXT = "All"; + + private int maxSlot; + + public ItemMeterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); + final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); + + maxSlot = getMaxSlot(); + + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_ItemMeter.this) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + coverData -> coverData.inverted, + (coverData, state) -> { + coverData.inverted = state; + return coverData; + }, + widget -> widget.addTooltip(0, NORMAL) + .addTooltip(1, INVERTED) + .setPos(0, 0)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> getSlotTextFieldContent(coverData.slot), + (coverData, state) -> { + coverData.slot = getIntFromText(state); + return coverData; + }, + widget -> widget.setOnScrollText() + .setValidator(val -> { + final int valSlot = getIntFromText(val); + if (valSlot > -1) { + return TextFieldWidget.format.format(Math.min(valSlot, maxSlot)); + } else { + return ALL_TEXT; + } + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setFocusOnGuiOpen(true) + .setPos(0, spaceY + 2) + .setSize(spaceX * 2 + 5, 12)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.threshold), + (coverData, state) -> { + coverData.threshold = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbers(1, 10, 64) + .setNumbers(0, getUpperBound()) + .setPos(0, spaceY * 2 + 2) + .setSize(spaceX * 2 + 5, 12)) + .setPos(startX, startY)) + .widget(new ItemWatcherSlotWidget() + .setGetter(this::getTargetItem) + .setPos(startX + spaceX * 8 - 4, startY + spaceY)) + .widget(TextWidget.dynamicString( + () -> getCoverData() != null ? getCoverData().inverted ? INVERTED : NORMAL : "") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY)) + .widget(new TextWidget(GT_Utility.trans("254", "Detect slot#")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 4 + startY + spaceY)) + .widget(new TextWidget(GT_Utility.trans("221", "Item threshold")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, startY + spaceY * 2 + 4)); + } + + private int getMaxSlot() { + final ICoverable tile = getUIBuildContext().getTile(); + if (tile instanceof TileEntity + && !tile.isDead() + && tile instanceof IGregTechTileEntity + && !(((IGregTechTileEntity) tile).getMetaTileEntity() + instanceof GT_MetaTileEntity_DigitalChestBase)) + return Math.min(tile.getSizeInventory() - 1, SLOT_MASK - 1); + else return -1; + } + + private int getIntFromText(String text) { + try { + return (int) MathExpression.parseMathExpression(text, -1); + } catch (Exception e) { + return -1; + } + } + + private String getSlotTextFieldContent(int val) { + return val < 0 ? ALL_TEXT : String.valueOf(val); + } + + private int getUpperBound() { + return maxSlot > 0 ? maxSlot * 64 : 999_999; + } + + private ItemStack getTargetItem() { + ItemMeterData coverVariable = getCoverData(); + if (coverVariable == null || coverVariable.slot < 0) { + return null; + } + ICoverable tile = getUIBuildContext().getTile(); + if (tile instanceof TileEntity && !tile.isDead()) { + if (tile.getSizeInventory() >= coverVariable.slot) { + return tile.getStackInSlot(coverVariable.slot); + } + } + return null; + } } public static class ItemMeterData implements ISerializableObject { @@ -273,205 +395,4 @@ public class GT_Cover_ItemMeter extends GT_CoverBehaviorBase<GT_Cover_ItemMeter. return this; } } - - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private final GT_GuiIconCheckButton invertedButton; - private final GT_GuiIntegerTextBox intSlot; - private final GT_GuiFakeItemButton intSlotIcon; - private final GT_GuiIntegerTextBox thresholdSlot; - private final ItemMeterData coverVariable; - - private final int maxSlot; - - private static final int startX = 10; - private static final int startY = 25; - private static final int spaceX = 18; - private static final int spaceY = 18; - - private final String ALL = GT_Utility.trans("ALL", "All"); - private final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); - private final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, ItemMeterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - invertedButton = new GT_GuiIconCheckButton( - this, 0, startX, startY, GT_GuiIcon.REDSTONE_ON, GT_GuiIcon.REDSTONE_OFF, INVERTED, NORMAL); - - intSlot = new GT_GuiIntegerTextBox(this, 1, startX, startY + spaceY + 2, spaceX * 2 + 5, 12); - intSlot.setMaxStringLength(6); - - // only shows if opened gui of block sadly, should've used container. - intSlotIcon = - new GT_GuiFakeItemButton(this, startX + spaceX * 8 - 4, startY + spaceY, GT_GuiIcon.SLOT_GRAY); - intSlotIcon.setMimicSlot(true); - - if (tile instanceof TileEntity - && !super.tile.isDead() - && tile instanceof IGregTechTileEntity - && !(((IGregTechTileEntity) tile).getMetaTileEntity() - instanceof GT_MetaTileEntity_DigitalChestBase)) - maxSlot = Math.min(tile.getSizeInventory() - 1, SLOT_MASK - 1); - else maxSlot = -1; - - intSlot.setEnabled(maxSlot >= 0); - - thresholdSlot = new GT_GuiIntegerTextBox(this, 2, startX, startY + spaceY * 2 + 2, spaceX * 2 + 5, 12); - thresholdSlot.setMaxStringLength(6); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString(coverVariable.inverted ? INVERTED : NORMAL, startX + spaceX * 3, 4 + startY, textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("254", "Detect slot#"), - startX + spaceX * 3, - 4 + startY + spaceY, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("221", "Item threshold"), - startX + spaceX * 3, - startY + spaceY * 2 + 4, - textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - update(); - if (intSlot.isEnabled()) intSlot.setFocused(true); - } - - @Override - public void buttonClicked(GuiButton btn) { - coverVariable.inverted = !coverVariable.inverted; - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - if (intSlot.isFocused()) { - int step = Math.max(1, Math.abs(delta / 120)); - step = (isShiftKeyDown() ? 50 : isCtrlKeyDown() ? 5 : 1) * (delta > 0 ? step : -step); - int val = parseTextBox(intSlot); - - if (val < 0) val = -1; - - val = val + step; - - if (val < 0) val = -1; - else if (val > maxSlot) val = maxSlot; - - intSlot.setText(val < 0 ? ALL : Integer.toString(val)); - } else if (thresholdSlot.isFocused()) { - int val = parseTextBox(thresholdSlot); - - int step = 1; - if (isShiftKeyDown()) { - step *= 64; - } - if (isCtrlKeyDown()) { - step *= 10; - } - - val += step * Integer.signum(delta); - - val = GT_Utility.clamp(val, 0, getUpperBound()); - thresholdSlot.setText(Integer.toString(val)); - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == intSlot) { - coverVariable.slot = parseTextBox(box); - } else if (box == thresholdSlot) { - coverVariable.threshold = parseTextBox(thresholdSlot); - } - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - if (box == intSlot) { - intSlot.setText(coverVariable.slot < 0 ? ALL : Integer.toString(coverVariable.slot)); - } else if (box == thresholdSlot) { - thresholdSlot.setText(Integer.toString(coverVariable.threshold)); - } - } - - private void update() { - invertedButton.setChecked(coverVariable.inverted); - resetTextBox(intSlot); - resetTextBox(thresholdSlot); - - if (coverVariable.slot < 0) { - intSlotIcon.setItem(null); - return; - } - if (tile instanceof TileEntity && !super.tile.isDead()) { - if (tile.getSizeInventory() >= coverVariable.slot) { - ItemStack item = tile.getStackInSlot(coverVariable.slot); - intSlotIcon.setItem(item); - return; - } - } - intSlotIcon.setItem(null); - } - - private int parseTextBox(GT_GuiIntegerTextBox box) { - if (box == intSlot) { - String text = box.getText(); - if (text == null) return -1; - text = text.trim(); - if (text.startsWith(ALL)) text = text.substring(ALL.length()); - - if (text.isEmpty()) return -1; - - int val; - try { - val = Integer.parseInt(text); - } catch (NumberFormatException e) { - return -1; - } - - if (val < 0) return -1; - else if (maxSlot < val) return maxSlot; - return val; - } else if (box == thresholdSlot) { - String text = box.getText(); - if (text == null) { - return 0; - } - - int val; - try { - val = Integer.parseInt(text.trim()); - } catch (NumberFormatException e) { - return 0; - } - - return GT_Utility.clamp(val, 0, getUpperBound()); - } - - throw new UnsupportedOperationException("Unknown text box: " + box); - } - - private int getUpperBound() { - return maxSlot > 0 ? maxSlot * 64 : 999_999; - } - } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java b/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java index f475debce7..62e560487b 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_LiquidMeter.java @@ -1,28 +1,27 @@ package gregtech.common.covers; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.metatileentity.BaseMetaTileEntity; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalTankBase; import io.netty.buffer.ByteBuf; import java.util.Arrays; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -164,23 +163,85 @@ public class GT_Cover_LiquidMeter extends GT_CoverBehaviorBase<GT_Cover_LiquidMe protected int getTickRateImpl(byte aSide, int aCoverID, LiquidMeterData aCoverVariable, ICoverable aTileEntity) { return 5; } - /** - * GUI Stuff - */ + + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - LiquidMeterData coverData, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new LiquidMeterUIFactory(buildContext).createWindow(); + } + + private class LiquidMeterUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + + public LiquidMeterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); + final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); + final int maxCapacity; + + if (getUIBuildContext().getTile() instanceof IFluidHandler) { + FluidTankInfo[] tanks = + ((IFluidHandler) getUIBuildContext().getTile()).getTankInfo(ForgeDirection.UNKNOWN); + maxCapacity = + Arrays.stream(tanks).mapToInt(tank -> tank.capacity).sum(); + } else { + maxCapacity = -1; + } + + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_LiquidMeter.this) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + coverData -> coverData.inverted, + (coverData, state) -> { + coverData.inverted = state; + return coverData; + }, + widget -> widget.addTooltip(0, NORMAL) + .addTooltip(1, INVERTED) + .setPos(spaceX * 0, spaceY * 0)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.threshold), + (coverData, state) -> { + coverData.threshold = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbers(1000, 100, 100000) + .setNumbers(0, maxCapacity > 0 ? maxCapacity : Integer.MAX_VALUE) + .setFocusOnGuiOpen(true) + .setPos(spaceX * 0, spaceY * 1 + 2) + .setSize(spaceX * 4 + 5, 12)) + .setPos(startX, startY)) + .widget(TextWidget.dynamicString( + () -> getCoverData() != null ? getCoverData().inverted ? INVERTED : NORMAL : "") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("222", "Fluid threshold")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5 - 10, startY + spaceY * 1 + 4)); + } } public static class LiquidMeterData implements ISerializableObject { @@ -234,143 +295,4 @@ public class GT_Cover_LiquidMeter extends GT_CoverBehaviorBase<GT_Cover_LiquidMe return this; } } - - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private final GT_GuiIconCheckButton invertedButton; - private final GT_GuiIntegerTextBox thresholdSlot; - private final LiquidMeterData coverVariable; - - private final int maxCapacity; - - private static final int startX = 10; - private static final int startY = 25; - private static final int spaceX = 18; - private static final int spaceY = 18; - - private final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); - private final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, LiquidMeterData aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - invertedButton = new GT_GuiIconCheckButton( - this, - 0, - startX + spaceX * 0, - startY + spaceY * 0, - GT_GuiIcon.REDSTONE_ON, - GT_GuiIcon.REDSTONE_OFF, - INVERTED, - NORMAL); - thresholdSlot = - new GT_GuiIntegerTextBox(this, 2, startX + spaceX * 0, startY + spaceY * 1 + 2, spaceX * 4 + 5, 12); - - if (tile instanceof IFluidHandler) { - FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN); - maxCapacity = - Arrays.stream(tanks).mapToInt(tank -> tank.capacity).sum(); - } else { - maxCapacity = -1; - } - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - coverVariable.inverted ? INVERTED : NORMAL, - startX + spaceX * 1, - 4 + startY + spaceY * 0, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("222", "Fluid threshold"), - startX + spaceX * 5 - 10, - startY + spaceY * 1 + 4, - textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - update(); - thresholdSlot.setFocused(true); - } - - @Override - public void buttonClicked(GuiButton btn) { - coverVariable.inverted = !coverVariable.inverted; - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - if (thresholdSlot.isFocused()) { - int val = parseTextBox(thresholdSlot); - - int step = 1000; - if (isShiftKeyDown()) { - step *= 100; - } - if (isCtrlKeyDown()) { - step /= 10; - } - - val += step * Integer.signum(delta); - int upperBound = maxCapacity > 0 ? maxCapacity : Integer.MAX_VALUE; - val = GT_Utility.clamp(val, 0, upperBound); - thresholdSlot.setText(Integer.toString(val)); - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - coverVariable.threshold = parseTextBox(thresholdSlot); - } - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - thresholdSlot.setText(Integer.toString(coverVariable.threshold)); - } - } - - private void update() { - invertedButton.setChecked(coverVariable.inverted); - resetTextBox(thresholdSlot); - } - - private int parseTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdSlot) { - String text = box.getText(); - if (text == null) { - return 0; - } - - int val; - try { - val = Integer.parseInt(text.trim()); - } catch (NumberFormatException e) { - return 0; - } - - int upperBound = maxCapacity > 0 ? maxCapacity : Integer.MAX_VALUE; - return GT_Utility.clamp(val, 0, upperBound); - } - - throw new UnsupportedOperationException("Unknown text box: " + box); - } - } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java b/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java index 2ea5a2c951..5dfb837499 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_NeedMaintainance.java @@ -1,19 +1,19 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.Fluid; @@ -192,122 +192,130 @@ public class GT_Cover_NeedMaintainance extends GT_CoverBehavior { public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 60; } - /** - * GUI Stuff - */ + + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; - - private final String[] tooltiptext = { - GT_Utility.trans("056", "Emit if 1 Maintenance Needed"), - GT_Utility.trans("058", "Emit if 2 Maintenance Needed"), - GT_Utility.trans("060", "Emit if 3 Maintenance Needed"), - GT_Utility.trans("062", "Emit if 4 Maintenance Needed"), - GT_Utility.trans("064", "Emit if 5 Maintenance Needed"), - GT_Utility.trans("066", "Emit if rotor needs maintenance low accuracy mod"), - GT_Utility.trans("068", "Emit if rotor needs maintenance high accuracy mod"), - }; + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new NeedMaintainanceUIFactory(buildContext).createWindow(); + } - private final String[] buttontext = { - GT_Utility.trans("247", "1 Issue"), - GT_Utility.trans("248", "2 Issues"), - GT_Utility.trans("249", "3 Issues"), - GT_Utility.trans("250", "4 Issues"), - GT_Utility.trans("251", "5 Issues"), - GT_Utility.trans("252", "Rotor < 80%"), - GT_Utility.trans("253", "Rotor < 100%"), - GT_Utility.trans("INVERTED", "Inverted"), - GT_Utility.trans("NORMAL", "Normal"), - }; + private class NeedMaintainanceUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - GuiButton b; - b = new GT_GuiIconCheckButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[0]); - b = new GT_GuiIconCheckButton(this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[1]); - b = new GT_GuiIconCheckButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[2]); - b = new GT_GuiIconCheckButton(this, 3, startX + spaceX * 0, startY + spaceY * 3, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[3]); - b = new GT_GuiIconCheckButton( - this, 4, startX + spaceX * 4 + 4, startY + spaceY * 0, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[4]); - b = new GT_GuiIconCheckButton( - this, 5, startX + spaceX * 4 + 4, startY + spaceY * 1, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[5]); - b = new GT_GuiIconCheckButton( - this, 6, startX + spaceX * 4 + 4, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(tooltiptext[6]); - b = new GT_GuiIconCheckButton( - this, - 7, - startX + spaceX * 4 + 4, - startY + spaceY * 3, - GT_GuiIcon.REDSTONE_ON, - GT_GuiIcon.REDSTONE_OFF); + public NeedMaintainanceUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - - this.fontRendererObj.drawString(buttontext[0], startX + spaceX * 1, 4 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString(buttontext[1], startX + spaceX * 1, 4 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString(buttontext[2], startX + spaceX * 1, 4 + startY + spaceY * 2, textColor); - this.fontRendererObj.drawString(buttontext[3], startX + spaceX * 1, 4 + startY + spaceY * 3, textColor); - this.fontRendererObj.drawString(buttontext[4], startX + spaceX * 5 + 4, 4 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString(buttontext[5], startX + spaceX * 5 + 4, 4 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString(buttontext[6], startX + spaceX * 5 + 4, 4 + startY + spaceY * 2, textColor); - // inverted normal - String s2 = ((coverVariable & 0x1) > 0) ? buttontext[7] : buttontext[8]; - this.fontRendererObj.drawString(s2, startX + spaceX * 5 + 4, 4 + startY + spaceY * 3, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (btn.id == 7 || !isEnabled(btn.id)) { - coverVariable = getNewCoverVariable(btn.id, ((GT_GuiIconCheckButton) btn).isChecked()); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - for (Object o : buttonList) - ((GT_GuiIconCheckButton) o).setChecked(isEnabled(((GT_GuiIconCheckButton) o).id)); + protected void addUIWidgets(ModularWindow.Builder builder) { + final String[] tooltipText = { + GT_Utility.trans("056", "Emit if 1 Maintenance Needed"), + GT_Utility.trans("058", "Emit if 2 Maintenance Needed"), + GT_Utility.trans("060", "Emit if 3 Maintenance Needed"), + GT_Utility.trans("062", "Emit if 4 Maintenance Needed"), + GT_Utility.trans("064", "Emit if 5 Maintenance Needed"), + GT_Utility.trans("066", "Emit if rotor needs maintenance low accuracy mod"), + GT_Utility.trans("068", "Emit if rotor needs maintenance high accuracy mod"), + }; + + final String[] buttonText = { + GT_Utility.trans("247", "1 Issue"), + GT_Utility.trans("248", "2 Issues"), + GT_Utility.trans("249", "3 Issues"), + GT_Utility.trans("250", "4 Issues"), + GT_Utility.trans("251", "5 Issues"), + GT_Utility.trans("252", "Rotor < 80%"), + GT_Utility.trans("253", "Rotor < 100%"), + GT_Utility.trans("INVERTED", "Inverted"), + GT_Utility.trans("NORMAL", "Normal"), + }; + + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_NeedMaintainance.this, + (index, coverData) -> isEnabled(index, convert(coverData)), + (index, coverData) -> new ISerializableObject.LegacyCoverData( + getNewCoverVariable(index, convert(coverData)))) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[0]).setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[1]).setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[2]).setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[3]).setPos(spaceX * 0, spaceY * 3)) + .addToggleButton( + 4, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[4]).setPos(spaceX * 4 + 4, spaceY * 0)) + .addToggleButton( + 5, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[5]).setPos(spaceX * 4 + 4, spaceY * 1)) + .addToggleButton( + 6, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.addTooltip(tooltipText[6]).setPos(spaceX * 4 + 4, spaceY * 2)) + .addToggleButton( + 7, + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + widget -> widget.setPos(spaceX * 4 + 4, spaceY * 3)) + .setPos(startX, startY)) + .widget(new TextWidget(buttonText[0]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(buttonText[1]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 1)) + .widget(new TextWidget(buttonText[2]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 2)) + .widget(new TextWidget(buttonText[3]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 3)) + .widget(new TextWidget(buttonText[4]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5 + 4, 4 + startY + spaceY * 0)) + .widget(new TextWidget(buttonText[5]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5 + 4, 4 + startY + spaceY * 1)) + .widget(new TextWidget(buttonText[6]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5 + 4, 4 + startY + spaceY * 2)) + .widget(TextWidget.dynamicString( + () -> isEnabled(7, convert(getCoverData())) ? buttonText[7] : buttonText[8]) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5 + 4, 4 + startY + spaceY * 3)); } - private int getNewCoverVariable(int id, boolean checked) { + private int getNewCoverVariable(int id, int coverVariable) { + final boolean checked = (coverVariable & 0x1) > 0; if (id == 7) { if (checked) return coverVariable & ~0x1; else return coverVariable | 0x1; @@ -315,7 +323,7 @@ public class GT_Cover_NeedMaintainance extends GT_CoverBehavior { return (coverVariable & 0x1) | (id << 1); } - private boolean isEnabled(int id) { + private boolean isEnabled(int id, int coverVariable) { if (id == 7) return (coverVariable & 0x1) > 0; return (coverVariable >>> 1) == id; } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_PlayerDetector.java b/src/main/java/gregtech/common/covers/GT_Cover_PlayerDetector.java index a77119b413..7f9e2ae5b0 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_PlayerDetector.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_PlayerDetector.java @@ -1,16 +1,16 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraftforge.fluids.Fluid; @@ -149,81 +149,66 @@ public class GT_Cover_PlayerDetector extends GT_CoverBehavior { public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 20; } - /** - * GUI Stuff - */ + + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new PlayerDetectorUIFactory(buildContext).createWindow(); } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + private class PlayerDetectorUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - new GT_GuiIconCheckButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(GT_Utility.trans("068.1", "Emit if any Player is close")); - new GT_GuiIconCheckButton(this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(GT_Utility.trans("069.1", "Emit if other Player is close")); - new GT_GuiIconCheckButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null) - .setTooltipText(GT_Utility.trans("070", "Emit if you are close")); + public PlayerDetectorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("319", "Any player"), startX + spaceX * 1, 4 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("320", "Other players"), startX + spaceX * 1, 4 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("321", "Only owner"), startX + spaceX * 1, 4 + startY + spaceY * 2, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (!isEnabled(btn.id)) { - coverVariable = getNewCoverVariable(btn.id, ((GT_GuiIconCheckButton) btn).isChecked()); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - for (Object o : buttonList) - ((GT_GuiIconCheckButton) o).setChecked(isEnabled(((GT_GuiIconCheckButton) o).id)); - } - - private int getNewCoverVariable(int id, boolean checked) { - return id; - } - - private boolean isEnabled(int id) { - return coverVariable == id; + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_PlayerDetector.this, + (index, coverData) -> index == convert(coverData), + (index, coverData) -> new ISerializableObject.LegacyCoverData(index)) + .addToggleButton( + 0, CoverDataFollower_ToggleButtonWidget.ofCheck(), widget -> widget.addTooltip( + GT_Utility.trans("068.1", "Emit if any Player is close")) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, CoverDataFollower_ToggleButtonWidget.ofCheck(), widget -> widget.addTooltip( + GT_Utility.trans("069.1", "Emit if other Player is close")) + .setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 2, CoverDataFollower_ToggleButtonWidget.ofCheck(), widget -> widget.addTooltip( + GT_Utility.trans("070", "Emit if you are close")) + .setPos(spaceX * 0, spaceY * 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("319", "Any player")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("320", "Other players")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("321", "Only owner")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, 4 + startY + spaceY * 2)); } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Pump.java b/src/main/java/gregtech/common/covers/GT_Cover_Pump.java index db60cfa409..c15f7aec38 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Pump.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Pump.java @@ -1,16 +1,17 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; @@ -204,88 +205,99 @@ public class GT_Cover_Pump extends GT_CoverBehavior { return 1; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GT_PumpGUICover(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new PumpUIFactory(buildContext).createWindow(); } - private class GT_PumpGUICover extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + private class PumpUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GT_PumpGUICover(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - GT_GuiIconButton b; - b = new GT_GuiIconButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.EXPORT) - .setTooltipText(GT_Utility.trans("006", "Export")); - b = new GT_GuiIconButton(this, 1, startX + spaceX * 1, startY + spaceY * 0, GT_GuiIcon.IMPORT) - .setTooltipText(GT_Utility.trans("007", "Import")); - b = new GT_GuiIconButton(this, 2, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK) - .setTooltipText(GT_Utility.trans("224", "Always On")); - b = new GT_GuiIconButton(this, 3, startX + spaceX * 1, startY + spaceY * 1, GT_GuiIcon.REDSTONE_ON) - .setTooltipText(GT_Utility.trans("225", "Active with Redstone Signal")); - b = new GT_GuiIconButton(this, 4, startX + spaceX * 2, startY + spaceY * 1, GT_GuiIcon.REDSTONE_OFF) - .setTooltipText(GT_Utility.trans("226", "Inactive with Redstone Signal")); - b = new GT_GuiIconButton(this, 5, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.ALLOW_INPUT) - .setTooltipText(GT_Utility.trans("227", "Allow Input")); - b = new GT_GuiIconButton(this, 6, startX + spaceX * 1, startY + spaceY * 2, GT_GuiIcon.BLOCK_INPUT) - .setTooltipText(GT_Utility.trans("228", "Block Input")); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("229", "Import/Export"), startX + spaceX * 3, 3 + startY + spaceY * 0, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("230", "Conditional"), startX + spaceX * 3, 3 + startY + spaceY * 1, textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("231", "Enable Input"), startX + spaceX * 3, 3 + startY + spaceY * 2, textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); + public PumpUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void buttonClicked(GuiButton btn) { - if (getClickable(btn.id)) { - coverVariable = getNewCoverVariable(btn.id); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_Pump.this, + (id, coverData) -> !getClickable(id, convert(coverData)), + (id, coverData) -> new ISerializableObject.LegacyCoverData( + getNewCoverVariable(id, convert(coverData)))) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_EXPORT) + .addTooltip(GT_Utility.trans("006", "Export")) + .setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_IMPORT) + .addTooltip(GT_Utility.trans("007", "Import")) + .setPos(spaceX * 1, spaceY * 0)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK) + .addTooltip(GT_Utility.trans("224", "Always On")) + .setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_ON) + .addTooltip(GT_Utility.trans("225", "Active with Redstone Signal")) + .setPos(spaceX * 1, spaceY * 1)) + .addToggleButton( + 4, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_OFF) + .addTooltip(GT_Utility.trans("226", "Inactive with Redstone Signal")) + .setPos(spaceX * 2, spaceY * 1)) + .addToggleButton( + 5, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_ALLOW_INPUT) + .addTooltip(GT_Utility.trans("227", "Allow Input")) + .setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 6, + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_BLOCK_INPUT) + .addTooltip(GT_Utility.trans("228", "Block Input")) + .setPos(spaceX * 1, spaceY * 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("229", "Import/Export")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("230", "Conditional")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("231", "Enable Input")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 3, 3 + startY + spaceY * 2)); } - private void updateButtons() { - GuiButton b; - for (Object o : buttonList) { - b = (GuiButton) o; - b.enabled = getClickable(b.id); - } - } - - private int getNewCoverVariable(int id) { + private int getNewCoverVariable(int id, int coverVariable) { switch (id) { case 0: return coverVariable & ~0x1; @@ -309,9 +321,8 @@ public class GT_Cover_Pump extends GT_CoverBehavior { return coverVariable; } - private boolean getClickable(int id) { + private boolean getClickable(int id, int coverVariable) { if (coverVariable < 0 | 11 < coverVariable) return false; - switch (id) { case 0: case 1: diff --git a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java index f69050da14..f6e5381c74 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_RedstoneWirelessBase.java @@ -1,21 +1,19 @@ package gregtech.common.covers; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; -import gregtech.api.interfaces.IGuiScreen; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_WirelessRedstoneCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; -import net.minecraft.client.gui.GuiButton; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { @@ -175,174 +173,77 @@ public abstract class GT_Cover_RedstoneWirelessBase extends GT_CoverBehavior { public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return 1; } - /** - * GUI Stuff - */ + + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new RedstoneWirelessBaseUIFactory(buildContext).createWindow(); } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private GT_GuiIntegerTextBox fBox; - private int coverVariable; + private class RedstoneWirelessBaseUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private static final String guiTexturePath = "gregtech:textures/gui/GuiCoverLong.png"; - - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 250, 107, GT_Utility.intToStack(aCoverID)); - this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - fBox = new GT_GuiShortTextBox(this, 2, startX + spaceX * 0, startY + spaceY * 0 + 2, spaceX * 4 - 3, 12); - fBox.setText(String.valueOf(coverVariable & PUBLIC_MASK)); - fBox.setMaxStringLength(12); - - GuiButton b; - b = new GT_GuiIconCheckButton( - this, 0, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null); + public RedstoneWirelessBaseUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - GT_Utility.trans("246", "Frequency"), - startX + spaceX * 4, - 4 + startY + spaceY * 0, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("602", "Use Private Frequency"), - startX + spaceX * 1, - startY + spaceY * 2 + 4, - textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - fBox.setFocused(true); - ((GT_GuiIconCheckButton) buttonList.get(0)).setChecked((coverVariable & CHECKBOX_MASK) > 0); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - for (GT_GuiIntegerTextBox box : textBoxes) { - if (box.isFocused()) { - int step = Math.max(1, Math.abs(delta / 120)); - step = (isShiftKeyDown() ? 1000 : isCtrlKeyDown() ? 50 : 1) * (delta > 0 ? step : -step); - long tCoverVariable; - try { - tCoverVariable = Long.parseLong(box.getText()); - } catch (NumberFormatException e) { - return; - } - tCoverVariable = tCoverVariable + step; - if (tCoverVariable > MAX_CHANNEL) tCoverVariable = MAX_CHANNEL; - else if (tCoverVariable < 0) tCoverVariable = 0; - - box.setText(String.valueOf(tCoverVariable)); - return; - } - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - int tPublicChannel; - String s = box.getText().trim(); - try { - tPublicChannel = Integer.parseInt(s); - } catch (NumberFormatException e) { - resetTextBox(box); - return; - } - - if (tPublicChannel > MAX_CHANNEL) tPublicChannel = MAX_CHANNEL; - else if (tPublicChannel < 0) tPublicChannel = 0; - - int tCheckBoxValue = ((GT_GuiIconCheckButton) this.buttonList.get(0)).isChecked() ? CHECKBOX_MASK : 0; - - coverVariable = tCheckBoxValue | tPublicChannel; - - fBox.setText(Integer.toString(tPublicChannel)); - GT_Values.NW.sendToServer( - new GT_Packet_WirelessRedstoneCover(side, coverID, tile, tPublicChannel, tCheckBoxValue)); + protected int getGUIWidth() { + return 250; } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - box.setText(String.valueOf(coverVariable & PUBLIC_MASK)); + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_RedstoneWirelessBase.this) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(getFlagFrequency(convert(coverData))), + (coverData, text) -> new ISerializableObject.LegacyCoverData( + (int) MathExpression.parseMathExpression(text) + | getFlagCheckbox(convert(coverData))), + widget -> widget.setOnScrollNumbers() + .setNumbers(0, MAX_CHANNEL) + .setFocusOnGuiOpen(true) + .setPos(spaceX * 0, spaceY * 0 + 2) + .setSize(spaceX * 4 - 3, 12)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofCheck(), + coverData -> getFlagCheckbox(convert(coverData)) > 0, + (coverData, state) -> new ISerializableObject.LegacyCoverData( + getFlagFrequency(convert(coverData)) | (state ? CHECKBOX_MASK : 0)), + widget -> widget.setPos(spaceX * 0, spaceY * 2)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("246", "Frequency")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 4, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("602", "Use Private Frequency")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 1, startY + spaceY * 2 + 4)); } - @Override - public void buttonClicked(GuiButton btn) { - - final GT_GuiIconCheckButton tBtn = (GT_GuiIconCheckButton) btn; - - tBtn.setChecked(!tBtn.isChecked()); - - int tPublicChannel = 0; - String tText = fBox.getText().trim(); - - if (tText.length() > 0) { - tPublicChannel = Integer.parseInt(tText); - } - - int tCheckBoxValue = tBtn.isChecked() ? CHECKBOX_MASK : 0; - - coverVariable = tCheckBoxValue | tPublicChannel; - - GT_Values.NW.sendToServer( - new GT_Packet_WirelessRedstoneCover(side, coverID, tile, tPublicChannel, tCheckBoxValue)); + private int getFlagFrequency(int coverVariable) { + return coverVariable & PUBLIC_MASK; } - private class GT_GuiShortTextBox extends GT_GuiIntegerTextBox { - - public GT_GuiShortTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { - super(gui, id, x, y, width, height); - } - - @Override - public boolean textboxKeyTyped(char c, int key) { - int tValue = 0; - - if (!super.textboxKeyTyped(c, key)) return false; - - int cursorPos = this.getCursorPosition(); - - String tText = getText().trim(); - if (tText.length() > 0) { - try { - tValue = Integer.parseInt(tText); - } catch (NumberFormatException ignored) { - } - - if (tValue > MAX_CHANNEL) setText(String.valueOf(MAX_CHANNEL)); - else setText(String.valueOf(tValue)); - - setCursorPosition(cursorPos); - } - - return true; - } + private int getFlagCheckbox(int coverVariable) { + return coverVariable & CHECKBOX_MASK; } } } diff --git a/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java b/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java index 2b15359d64..6a3df96c5a 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_Shutter.java @@ -1,17 +1,17 @@ package gregtech.common.covers; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IMachineProgress; import gregtech.api.metatileentity.BaseMetaPipeEntity; -import gregtech.api.net.GT_Packet_TileEntityCover; import gregtech.api.util.GT_CoverBehavior; import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.GuiButton; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.fluids.Fluid; @@ -149,93 +149,72 @@ public class GT_Cover_Shutter extends GT_CoverBehavior { return 0; } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } @Override - public Object getClientGUI(byte aSide, int aCoverID, int coverData, ICoverable aTileEntity) { - return new GUI(aSide, aCoverID, coverData, aTileEntity); + public boolean useModularUI() { + return true; } - private class GUI extends GT_GUICover { - private final byte side; - private final int coverID; - private int coverVariable; + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new ShutterUIFactory(buildContext).createWindow(); + } + + private class ShutterUIFactory extends UIFactory { private static final int startX = 10; private static final int startY = 25; private static final int spaceX = 18; private static final int spaceY = 18; - private final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - public GUI(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { - super(aTileEntity, 176, 107, GT_Utility.intToStack(aCoverID)); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - - new GT_GuiIconCheckButton(this, 0, startX + spaceX * 0, startY + spaceY * 0, GT_GuiIcon.CHECKMARK, null); - new GT_GuiIconCheckButton(this, 1, startX + spaceX * 0, startY + spaceY * 1, GT_GuiIcon.CHECKMARK, null); - new GT_GuiIconCheckButton(this, 2, startX + spaceX * 0, startY + spaceY * 2, GT_GuiIcon.CHECKMARK, null); - new GT_GuiIconCheckButton(this, 3, startX + spaceX * 0, startY + spaceY * 3, GT_GuiIcon.CHECKMARK, null); + public ShutterUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } + @SuppressWarnings("PointlessArithmeticExpression") @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.fontRendererObj.drawString( - GT_Utility.trans("082", "Open if work enabled"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 0, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("083", "Open if work disabled"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 1, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("084", "Only Output allowed"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 2, - textColor); - this.fontRendererObj.drawString( - GT_Utility.trans("085", "Only Input allowed"), - 3 + startX + spaceX * 1, - 4 + startY + spaceY * 3, - textColor); - } - - @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - updateButtons(); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (!isEnabled(btn.id)) { - coverVariable = getNewCoverVariable(btn.id, ((GT_GuiIconCheckButton) btn).isChecked()); - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCover(side, coverID, coverVariable, tile)); - } - updateButtons(); - } - - private void updateButtons() { - for (Object o : buttonList) - ((GT_GuiIconCheckButton) o).setChecked(isEnabled(((GT_GuiIconCheckButton) o).id)); - } - - private int getNewCoverVariable(int id, boolean checked) { - return id; - } - - private boolean isEnabled(int id) { - return coverVariable == id; + protected void addUIWidgets(ModularWindow.Builder builder) { + builder.widget(new CoverDataControllerWidget.CoverDataIndexedControllerWidget_ToggleButtons<>( + this::getCoverData, + this::setCoverData, + GT_Cover_Shutter.this, + (index, coverData) -> index == convert(coverData), + (index, coverData) -> new ISerializableObject.LegacyCoverData(index)) + .addToggleButton( + 0, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.setPos(spaceX * 0, spaceY * 0)) + .addToggleButton( + 1, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.setPos(spaceX * 0, spaceY * 1)) + .addToggleButton( + 2, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.setPos(spaceX * 0, spaceY * 2)) + .addToggleButton( + 3, + CoverDataFollower_ToggleButtonWidget.ofCheck(), + widget -> widget.setPos(spaceX * 0, spaceY * 3)) + .setPos(startX, startY)) + .widget(new TextWidget(GT_Utility.trans("082", "Open if work enabled")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 0)) + .widget(new TextWidget(GT_Utility.trans("083", "Open if work disabled")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 1)) + .widget(new TextWidget(GT_Utility.trans("084", "Only Output allowed")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 2)) + .widget(new TextWidget(GT_Utility.trans("085", "Only Input allowed")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(3 + startX + spaceX * 1, 4 + startY + spaceY * 3)); } } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java index d3bf278a94..6b7c7f282e 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneReceiverBase.java @@ -1,21 +1,22 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; +import java.util.Arrays; import java.util.UUID; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; public abstract class GT_Cover_AdvancedRedstoneReceiverBase extends GT_Cover_AdvancedWirelessRedstoneBase<GT_Cover_AdvancedRedstoneReceiverBase.ReceiverData> { @@ -34,18 +35,101 @@ public abstract class GT_Cover_AdvancedRedstoneReceiverBase return createDataObject(); } - /** - * GUI Stuff - */ + // GUI stuff + @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - ReceiverData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new ReceiverGUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new AdvancedRedstoneReceiverBaseUIFactory(buildContext).createWindow(); + } + + private class AdvancedRedstoneReceiverBaseUIFactory extends AdvancedWirelessRedstoneBaseUIFactory { + + public AdvancedRedstoneReceiverBaseUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @Override + protected int getFrequencyRow() { + return 0; + } + + @Override + protected int getButtonRow() { + return 1; + } + + @Override + protected boolean isShiftPrivateLeft() { + return false; + } + + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + super.addUIWidgets(builder); + builder.widget(new TextWidget(GT_Utility.trans("335", "Gate Mode")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5, 4 + startY + spaceY * 2)); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIForDataController(CoverDataControllerWidget<ReceiverData> controller) { + super.addUIForDataController(controller); + controller + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == GateMode.AND, + (coverData, state) -> { + coverData.mode = GateMode.AND; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_GATE_AND) + .addTooltip(GT_Utility.trans("331", "AND Gate")) + .setPos(spaceX * 0, spaceY * 2)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == GateMode.NAND, + (coverData, state) -> { + coverData.mode = GateMode.NAND; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_GATE_NAND) + .addTooltip(GT_Utility.trans("332", "NAND Gate")) + .setPos(spaceX * 1, spaceY * 2)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == GateMode.OR, + (coverData, state) -> { + coverData.mode = GateMode.OR; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_GATE_OR) + .addTooltip(GT_Utility.trans("333", "OR Gate")) + .setPos(spaceX * 2, spaceY * 2)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == GateMode.NOR, + (coverData, state) -> { + coverData.mode = GateMode.NOR; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_GATE_NOR) + .addTooltip(GT_Utility.trans("334", "NOR Gate")) + .setPos(spaceX * 3, spaceY * 2)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == GateMode.SINGLE_SOURCE, + (coverData, state) -> { + coverData.mode = GateMode.SINGLE_SOURCE; + return coverData; + }, + widget -> widget.setStaticTexture(GT_UITextures.OVERLAY_BUTTON_ANALOG) + .addTooltips(Arrays.asList( + "ANALOG Mode", + "Only use this mode with ONE transmitter in total,", + "no logic involved")) + .setPos(spaceX * 4, spaceY * 2)); + } } public enum GateMode { @@ -110,84 +194,4 @@ public abstract class GT_Cover_AdvancedRedstoneReceiverBase return this; } } - - private static class ReceiverGUI extends WirelessGUI<ReceiverData> { - - private static final int gateModeButtonIdStart = 1; - - public ReceiverGUI(byte aSide, int aCoverID, ReceiverData aCoverVariable, ICoverable aTileEntity) { - super(aSide, aCoverID, aCoverVariable, aTileEntity); - - new GT_GuiIconButton( - this, - gateModeButtonIdStart + 0, - startX + spaceX * 0, - startY + spaceY * 2, - GT_GuiIcon.AND_GATE) - .setTooltipText(GT_Utility.trans("331", "AND Gate")); - new GT_GuiIconButton( - this, - gateModeButtonIdStart + 1, - startX + spaceX * 1, - startY + spaceY * 2, - GT_GuiIcon.NAND_GATE) - .setTooltipText(GT_Utility.trans("332", "NAND Gate")); - new GT_GuiIconButton( - this, - gateModeButtonIdStart + 2, - startX + spaceX * 2, - startY + spaceY * 2, - GT_GuiIcon.OR_GATE) - .setTooltipText(GT_Utility.trans("333", "OR Gate")); - new GT_GuiIconButton( - this, - gateModeButtonIdStart + 3, - startX + spaceX * 3, - startY + spaceY * 2, - GT_GuiIcon.NOR_GATE) - .setTooltipText(GT_Utility.trans("334", "NOR Gate")); - new GT_GuiIconButton( - this, - gateModeButtonIdStart + 4, - startX + spaceX * 4, - startY + spaceY * 2, - GT_GuiIcon.ANALOG_MODE) - .setTooltipText( - "ANALOG Mode", "Only use this mode with ONE transmitter in total,", "no logic involved"); - } - - @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - GT_Utility.trans("335", "Gate Mode"), - startX + spaceX * 5, - 4 + startY + spaceY * 2, - textColor); - } - - @Override - protected void update() { - super.update(); - updateButtons(); - } - - private void updateButtons() { - GuiButton button; - for (int i = gateModeButtonIdStart; i < gateModeButtonIdStart + 5; ++i) { - button = (GuiButton) this.buttonList.get(i); - button.enabled = (button.id - gateModeButtonIdStart) != coverVariable.mode.ordinal(); - } - } - - @Override - public void buttonClicked(GuiButton btn) { - if (btn.id >= gateModeButtonIdStart && btn.enabled) { - coverVariable.mode = GateMode.values()[btn.id - gateModeButtonIdStart]; - } - - super.buttonClicked(btn); - } - } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneTransmitterBase.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneTransmitterBase.java index 2af243861a..c065c085b2 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneTransmitterBase.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedRedstoneTransmitterBase.java @@ -1,22 +1,23 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import java.util.Objects; import java.util.UUID; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; public abstract class GT_Cover_AdvancedRedstoneTransmitterBase< T extends GT_Cover_AdvancedRedstoneTransmitterBase.TransmitterData> @@ -126,69 +127,65 @@ public abstract class GT_Cover_AdvancedRedstoneTransmitterBase< } } - /** - * GUI Stuff - */ + // GUI stuff + @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - TransmitterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new TransmitterGUI<>(aSide, aCoverID, aCoverVariable, aTileEntity); + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new AdvancedRedstoneTransmitterBaseUIFactory(buildContext).createWindow(); } - protected class TransmitterGUI<X extends TransmitterData> extends WirelessGUI<X> { - - private final GT_GuiIconCheckButton invertButton; - - private final String INVERTED = GT_Utility.trans("INVERTED", "Inverted"); - private final String NORMAL = GT_Utility.trans("NORMAL", "Normal"); - - public TransmitterGUI( - byte aSide, int aCoverID, X aCoverVariable, ICoverable aTileEntity, int frequencyRow, int buttonRow) { - super(aSide, aCoverID, aCoverVariable, aTileEntity, frequencyRow, buttonRow, true); - invertButton = new GT_GuiIconCheckButton( - this, - 1, - startX + spaceX * 9, - startY + spaceY * buttonRow, - GT_GuiIcon.REDSTONE_ON, - GT_GuiIcon.REDSTONE_OFF, - INVERTED, - NORMAL); + protected class AdvancedRedstoneTransmitterBaseUIFactory extends AdvancedWirelessRedstoneBaseUIFactory { + + public AdvancedRedstoneTransmitterBaseUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } - public TransmitterGUI(byte aSide, int aCoverID, X aCoverVariable, ICoverable aTileEntity) { - this(aSide, aCoverID, aCoverVariable, aTileEntity, 0, 1); + @Override + protected int getFrequencyRow() { + return 0; } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - coverVariable.invert ? INVERTED : NORMAL, - startX + spaceX * 10, - 4 + startY + spaceY * buttonRow, - textColor); + protected int getButtonRow() { + return 1; } @Override - protected void update() { - super.update(); - invertButton.setChecked(coverVariable.invert); + protected boolean isShiftPrivateLeft() { + return true; } @Override - public void buttonClicked(GuiButton btn) { - if (btn == invertButton) { - coverVariable.invert = !coverVariable.invert; - } + protected void addUIWidgets(ModularWindow.Builder builder) { + super.addUIWidgets(builder); + builder.widget(TextWidget.dynamicString(() -> { + T coverData = getCoverData(); + if (coverData != null) { + return getCoverData().invert + ? GT_Utility.trans("INVERTED", "Inverted") + : GT_Utility.trans("NORMAL", "Normal"); + } else { + return ""; + } + }) + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 10, 4 + startY + spaceY * getButtonRow())); + } - super.buttonClicked(btn); + @Override + protected void addUIForDataController(CoverDataControllerWidget<T> controller) { + super.addUIForDataController(controller); + controller.addFollower( + CoverDataFollower_ToggleButtonWidget.ofRedstone(), + coverData -> coverData.invert, + (coverData, state) -> { + coverData.invert = state; + return coverData; + }, + widget -> widget.addTooltip(0, GT_Utility.trans("NORMAL", "Normal")) + .addTooltip(1, GT_Utility.trans("INVERTED", "Inverted")) + .setPos(spaceX * 9, spaceY * getButtonRow())); } } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedWirelessRedstoneBase.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedWirelessRedstoneBase.java index a57b99fd83..c63f2f37d9 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedWirelessRedstoneBase.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_AdvancedWirelessRedstoneBase.java @@ -1,32 +1,27 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.api.GregTech_API; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUICover; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; -import gregtech.api.interfaces.IGuiScreen; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; -import gregtech.api.net.GT_Packet_TileEntityCoverNew; import gregtech.api.util.GT_CoverBehaviorBase; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; -import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import javax.annotation.Nonnull; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; public abstract class GT_Cover_AdvancedWirelessRedstoneBase< @@ -219,225 +214,85 @@ public abstract class GT_Cover_AdvancedWirelessRedstoneBase< } } - /** - * GUI Stuff - */ + // GUI stuff + @Override public boolean hasCoverGUI() { return true; } - protected abstract static class WirelessGUI<X extends WirelessData> extends GT_GUICover { + @Override + public boolean useModularUI() { + return true; + } - protected final byte side; - protected final int coverID; - protected final GT_GuiIntegerTextBox frequencyBox; - protected final GT_GuiIconCheckButton privateButton; - protected final X coverVariable; + protected abstract class AdvancedWirelessRedstoneBaseUIFactory extends UIFactory { protected static final int startX = 10; protected static final int startY = 25; protected static final int spaceX = 18; protected static final int spaceY = 18; - protected final int frequencyRow; - protected final int buttonRow; - private final int privateExtraColumn; - - protected final int textColor = this.getTextColorOrDefault("text", 0xFF555555); - - private static final String guiTexturePath = "gregtech:textures/gui/GuiCoverLong.png"; - - public WirelessGUI( - byte aSide, - int aCoverID, - X aCoverVariable, - ICoverable aTileEntity, - int frequencyRow, - int buttonRow, - boolean shiftPrivateLeft) { - super(aTileEntity, 250, 107, GT_Utility.intToStack(aCoverID)); - this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath); - this.side = aSide; - this.coverID = aCoverID; - this.coverVariable = aCoverVariable; - this.frequencyRow = frequencyRow; - this.buttonRow = buttonRow; - this.privateExtraColumn = shiftPrivateLeft ? 1 : 5; - - frequencyBox = - new GT_GuiShortTextBox(this, 0, 1 + startX, 2 + startY + spaceY * frequencyRow, spaceX * 5 - 4, 12); - privateButton = - new GT_GuiIconCheckButton(this, 0, startX, startY + spaceY * buttonRow, GT_GuiIcon.CHECKMARK, null); - } - - public WirelessGUI(byte aSide, int aCoverID, X aCoverVariable, ICoverable aTileEntity) { - this(aSide, aCoverID, aCoverVariable, aTileEntity, 0, 1, false); + public AdvancedWirelessRedstoneBaseUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - GT_Utility.trans("246", "Frequency"), - startX + spaceX * 5, - 4 + startY + spaceY * frequencyRow, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("602", "Use Private Frequency"), - startX + spaceX * privateExtraColumn, - 4 + startY + spaceY * buttonRow, - textColor); + protected int getGUIWidth() { + return 250; } @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - update(); - frequencyBox.setFocused(true); + protected void addUIWidgets(ModularWindow.Builder builder) { + final int privateExtraColumn = isShiftPrivateLeft() ? 1 : 5; + + CoverDataControllerWidget<T> dataController = new CoverDataControllerWidget<>( + this::getCoverData, this::setCoverData, GT_Cover_AdvancedWirelessRedstoneBase.this); + dataController.setPos(startX, startY); + addUIForDataController(dataController); + + builder.widget(dataController) + .widget(new TextWidget(GT_Utility.trans("246", "Frequency")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5, 4 + startY + spaceY * getFrequencyRow())) + .widget(new TextWidget(GT_Utility.trans("602", "Use Private Frequency")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * privateExtraColumn, 4 + startY + spaceY * getButtonRow())); } - protected void genericMouseWheel( - GT_GuiIntegerTextBox box, - int delta, - int minValue, - int maxValue, - int baseStep, - int ctrlStep, - int shiftStep) { - long step = Math.max(1, Math.abs(delta / 120)); - step = (isShiftKeyDown() ? shiftStep : isCtrlKeyDown() ? ctrlStep : baseStep) * (delta > 0 ? step : -step); - - long value = parseTextBox(box, minValue, maxValue) + step; - if (value > maxValue) value = maxValue; - else if (value < minValue) value = minValue; - - box.setText(Long.toString(value)); + protected void addUIForDataController(CoverDataControllerWidget<T> controller) { + controller + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.frequency), + (coverData, state) -> { + coverData.frequency = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbers() + .setNumbers(0, Integer.MAX_VALUE) + .setFocusOnGuiOpen(true) + .setPos(1, 2 + spaceY * getFrequencyRow()) + .setSize(spaceX * 5 - 4, 12)) + .addFollower( + CoverDataFollower_ToggleButtonWidget.ofCheck(), + coverData -> coverData.uuid != null, + (coverData, state) -> { + if (state) { + coverData.uuid = + getUIBuildContext().getPlayer().getUniqueID(); + } else { + coverData.uuid = null; + } + return coverData; + }, + widget -> widget.setPos(0, spaceY * getButtonRow())); } - protected void genericMouseWheel(GT_GuiIntegerTextBox box, int delta, int minValue, int maxValue) { - genericMouseWheel(box, delta, minValue, maxValue, 1, 50, 1000); - } + protected abstract int getFrequencyRow(); - @Override - public void onMouseWheel(int x, int y, int delta) { - if (frequencyBox.isFocused()) { - genericMouseWheel(frequencyBox, delta, 0, Integer.MAX_VALUE); - } - } + protected abstract int getButtonRow(); - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == frequencyBox) { - coverVariable.frequency = parseTextBox(frequencyBox); - } - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - if (box == frequencyBox) { - frequencyBox.setText(Integer.toString(coverVariable.frequency)); - } - } - - protected void update() { - privateButton.setChecked(coverVariable.uuid != null); - resetTextBox(frequencyBox); - } - - @Override - public void buttonClicked(GuiButton btn) { - if (btn == privateButton) { - coverVariable.uuid = coverVariable.uuid == null - ? Minecraft.getMinecraft().thePlayer.getUniqueID() - : null; - } - - GT_Values.NW.sendToServer(new GT_Packet_TileEntityCoverNew(side, coverID, coverVariable, tile)); - update(); - } - - protected int parseTextBox(GT_GuiIntegerTextBox box, int min, int max) { - String text = box.getText(); - if (text == null) { - return 0; - } - - long value; - try { - value = Long.parseLong(text.trim()); - } catch (NumberFormatException e) { - return 0; - } - - if (value >= max) return max; - else if (value < min) return min; - return (int) value; - } - - protected int parseTextBox(GT_GuiIntegerTextBox box) { - return parseTextBox(box, 0, Integer.MAX_VALUE); - } - - protected class GT_GuiShortTextBox extends GT_GuiIntegerTextBox { - - private final int min; - private final int max; - private final Map<String, String> translation; - private final Map<String, String> inverseTranslation; - - public GT_GuiShortTextBox( - IGuiScreen gui, - int id, - int x, - int y, - int width, - int height, - int min, - int max, - Map<String, String> translate) { - super(gui, id, x, y, width, height); - this.min = min; - this.max = max; - this.translation = translate; - this.inverseTranslation = - translate.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey)); - } - - public GT_GuiShortTextBox(IGuiScreen gui, int id, int x, int y, int width, int height, int min, int max) { - this(gui, id, x, y, width, height, min, max, new HashMap<>()); - } - - public GT_GuiShortTextBox(IGuiScreen gui, int id, int x, int y, int width, int height) { - this(gui, id, x, y, width, height, 0, Integer.MAX_VALUE); - } - - @Override - public boolean textboxKeyTyped(char c, int key) { - if (!super.textboxKeyTyped(c, key)) return false; - - String text = getText().trim(); - if (text.length() > 0) { - setText(String.valueOf(parseTextBox(this, min, max))); - } - - return true; - } - - @Override - public String getText() { - String text = super.getText(); - return inverseTranslation.getOrDefault(text, text); - } - - @Override - public void setText(String text) { - super.setText(translation.getOrDefault(text, text)); - } - } + protected abstract boolean isShiftPrivateLeft(); } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessFluidDetector.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessFluidDetector.java index 772332820b..67b931dd99 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessFluidDetector.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessFluidDetector.java @@ -1,20 +1,23 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.common.covers.GT_Cover_LiquidMeter; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; import io.netty.buffer.ByteBuf; import java.util.UUID; import javax.annotation.Nonnull; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; public class GT_Cover_WirelessFluidDetector extends GT_Cover_AdvancedRedstoneTransmitterBase<GT_Cover_WirelessFluidDetector.FluidTransmitterData> { @@ -114,72 +117,51 @@ public class GT_Cover_WirelessFluidDetector } } - /** - * GUI Stuff - */ + // GUI stuff + @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - FluidTransmitterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new FluidTransmitterGUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new WirelessFluidDetectorUIFactory(buildContext).createWindow(); } - private class FluidTransmitterGUI extends TransmitterGUI<FluidTransmitterData> { - private final GT_GuiIntegerTextBox thresholdBox; - - public FluidTransmitterGUI( - byte aSide, int aCoverID, FluidTransmitterData aCoverVariable, ICoverable aTileEntity) { - super(aSide, aCoverID, aCoverVariable, aTileEntity, 1, 2); + private class WirelessFluidDetectorUIFactory extends AdvancedRedstoneTransmitterBaseUIFactory { - thresholdBox = new GT_GuiShortTextBox(this, 1, 1 + startX, 2 + startY, spaceX * 5 - 4, 12); + public WirelessFluidDetectorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString(GT_Utility.trans("222", "Fluid threshold"), startX + spaceX * 5, 4 + startY, textColor); + protected int getFrequencyRow() { + return 1; } @Override - protected void onInitGui(int guiLeft, int guiTop, int gui_width, int gui_height) { - update(); - thresholdBox.setFocused(true); - } - - @Override - public void onMouseWheel(int x, int y, int delta) { - super.onMouseWheel(x, y, delta); - if (thresholdBox.isFocused()) { - genericMouseWheel(thresholdBox, delta, 0, Integer.MAX_VALUE); - } - } - - @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdBox) { - coverVariable.threshold = parseTextBox(thresholdBox); - } - - super.applyTextBox(box); + protected int getButtonRow() { + return 2; } @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - super.resetTextBox(box); - if (box == thresholdBox) { - thresholdBox.setText(Integer.toString(coverVariable.threshold)); - } + protected void addUIWidgets(ModularWindow.Builder builder) { + super.addUIWidgets(builder); + builder.widget(new TextWidget(GT_Utility.trans("222", "Fluid threshold")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5, 4 + startY)); } @Override - protected void update() { - super.update(); - resetTextBox(thresholdBox); + protected void addUIForDataController(CoverDataControllerWidget<FluidTransmitterData> controller) { + super.addUIForDataController(controller); + controller.addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.threshold), + (coverData, state) -> { + coverData.threshold = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbers() + .setNumbers(0, Integer.MAX_VALUE) + .setPos(1, 2) + .setSize(spaceX * 5 - 4, 12)); } } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessItemDetector.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessItemDetector.java index 46e428e1e9..620f0bc35e 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessItemDetector.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessItemDetector.java @@ -1,27 +1,31 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.gui.widgets.GT_GuiFakeItemButton; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIntegerTextBox; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; import gregtech.api.util.ISerializableObject; import gregtech.common.covers.GT_Cover_ItemMeter; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_TextFieldWidget; +import gregtech.common.gui.modularui.widget.ItemWatcherSlotWidget; import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase; import io.netty.buffer.ByteBuf; -import java.util.Collections; import java.util.UUID; import javax.annotation.Nonnull; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; public class GT_Cover_WirelessItemDetector extends GT_Cover_AdvancedRedstoneTransmitterBase<GT_Cover_WirelessItemDetector.ItemTransmitterData> { @@ -133,128 +137,126 @@ public class GT_Cover_WirelessItemDetector } } - /** - * GUI Stuff - */ + // GUI stuff + @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - ItemTransmitterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new ItemTransmitterGUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new WirelessItemDetectorUIFactory(buildContext).createWindow(); } - private class ItemTransmitterGUI extends TransmitterGUI<ItemTransmitterData> { - private final GT_GuiIntegerTextBox thresholdBox; - private final GT_GuiIntegerTextBox slotBox; - - private final GT_GuiFakeItemButton fakeItemSlot; + private class WirelessItemDetectorUIFactory extends AdvancedRedstoneTransmitterBaseUIFactory { - private final int maxSlot; + private static final String ALL_TEXT = "All"; - public ItemTransmitterGUI( - byte aSide, int aCoverID, ItemTransmitterData aCoverVariable, ICoverable aTileEntity) { - super(aSide, aCoverID, aCoverVariable, aTileEntity, 0, 1); + private int maxSlot; + private final ItemStackHandler targetSlotHandler = new ItemStackHandler(1); - if (tile instanceof TileEntity - && !super.tile.isDead() - && tile instanceof IGregTechTileEntity - && !(((IGregTechTileEntity) tile).getMetaTileEntity() - instanceof GT_MetaTileEntity_DigitalChestBase)) { - maxSlot = tile.getSizeInventory() - 1; - } else { - maxSlot = -1; - } + public WirelessItemDetectorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } - thresholdBox = new GT_GuiShortTextBox( - this, 1, 1 + startX, 2 + startY + spaceY * 2, spaceX * 5 - 4, 12, 0, getMaxCount()); - slotBox = new GT_GuiShortTextBox( - this, - 2, - 1 + startX, - 2 + startY + spaceY * 3, - spaceX * 4 - 8, - 12, - -1, - maxSlot, - Collections.singletonMap("-1", "All")); - fakeItemSlot = - new GT_GuiFakeItemButton(this, startX + spaceX * 4 - 1, startY + spaceY * 3, GT_GuiIcon.SLOT_GRAY); - - slotBox.setEnabled(maxSlot >= 0); - fakeItemSlot.setMimicSlot(true); + @Override + protected int getFrequencyRow() { + return 0; } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - this.getFontRenderer() - .drawString( - GT_Utility.trans("221", "Item threshold"), - startX + spaceX * 5, - 4 + startY + spaceY * 2, - textColor); - this.getFontRenderer() - .drawString( - GT_Utility.trans("254.0", "Detect Slot"), - startX + spaceX * 5, - 4 + startY + spaceY * 3, - textColor); + protected int getButtonRow() { + return 1; } @Override - public void onMouseWheel(int x, int y, int delta) { - super.onMouseWheel(x, y, delta); - if (thresholdBox.isFocused()) { - genericMouseWheel(thresholdBox, delta, 0, getMaxCount(), 1, 10, 64); - } else if (slotBox.isFocused()) { - genericMouseWheel(slotBox, delta, -1, maxSlot, 1, 5, 50); - } + protected void addUIWidgets(ModularWindow.Builder builder) { + maxSlot = getMaxSlot(); + super.addUIWidgets(builder); + builder.widget(new ItemWatcherSlotWidget() + .setGetter(this::getTargetItem) + .setPos(startX + spaceX * 4 - 1, startY + spaceY * 3)) + .widget(new TextWidget(GT_Utility.trans("221", "Item threshold")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5, 4 + startY + spaceY * 2)) + .widget(new TextWidget(GT_Utility.trans("254.0", "Detect Slot")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * 5, 4 + startY + spaceY * 3)); } @Override - public void applyTextBox(GT_GuiIntegerTextBox box) { - if (box == thresholdBox) { - coverVariable.threshold = parseTextBox(thresholdBox, 0, getMaxCount()); - } else if (box == slotBox) { - coverVariable.slot = parseTextBox(slotBox, -1, maxSlot); + protected void addUIForDataController(CoverDataControllerWidget<ItemTransmitterData> controller) { + super.addUIForDataController(controller); + controller + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> String.valueOf(coverData.threshold), + (coverData, state) -> { + coverData.threshold = (int) MathExpression.parseMathExpression(state); + return coverData; + }, + widget -> widget.setOnScrollNumbers(1, 10, 64) + .setNumbers(() -> 0, this::getMaxItemCount) + .setPos(1, 2 + spaceY * 2) + .setSize(spaceX * 5 - 4, 12)) + .addFollower( + new CoverDataFollower_TextFieldWidget<>(), + coverData -> getSlotTextFieldContent(coverData.slot), + (coverData, state) -> { + coverData.slot = getIntFromText(state); + return coverData; + }, + widget -> widget.setOnScrollText() + .setValidator(val -> { + final int valSlot = getIntFromText(val); + if (valSlot > -1) { + return TextFieldWidget.format.format(Math.min(valSlot, maxSlot)); + } else { + return ALL_TEXT; + } + }) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setPos(1, 2 + spaceY * 3) + .setSize(spaceX * 4 - 8, 12)); + } + + private int getMaxSlot() { + final ICoverable tile = getUIBuildContext().getTile(); + if (tile instanceof TileEntity + && !tile.isDead() + && tile instanceof IGregTechTileEntity + && !(((IGregTechTileEntity) tile).getMetaTileEntity() + instanceof GT_MetaTileEntity_DigitalChestBase)) { + return tile.getSizeInventory() - 1; + } else { + return -1; } + } - super.applyTextBox(box); + private int getMaxItemCount() { + return maxSlot > 0 ? maxSlot * 64 : Integer.MAX_VALUE; } - @Override - public void resetTextBox(GT_GuiIntegerTextBox box) { - super.resetTextBox(box); - if (box == thresholdBox) { - thresholdBox.setText(Integer.toString(coverVariable.threshold)); - } else if (box == slotBox) { - slotBox.setText(Integer.toString(coverVariable.slot)); + private int getIntFromText(String text) { + try { + return (int) MathExpression.parseMathExpression(text, -1); + } catch (Exception e) { + return -1; } } - @Override - protected void update() { - super.update(); - resetTextBox(thresholdBox); - resetTextBox(slotBox); + private String getSlotTextFieldContent(int val) { + return val < 0 ? ALL_TEXT : String.valueOf(val); + } - if (coverVariable.slot >= 0 + private ItemStack getTargetItem() { + final ICoverable tile = getUIBuildContext().getTile(); + final ItemTransmitterData coverVariable = getCoverData(); + if (coverVariable != null + && coverVariable.slot >= 0 && tile instanceof TileEntity && !tile.isDead() && tile.getSizeInventory() >= coverVariable.slot) { - ItemStack itemStack = tile.getStackInSlot(coverVariable.slot); - fakeItemSlot.setItem(itemStack); + return tile.getStackInSlot(coverVariable.slot); } else { - fakeItemSlot.setItem(null); + return null; } } - - private int getMaxCount() { - return maxSlot > 0 ? maxSlot * 64 : Integer.MAX_VALUE; - } } } diff --git a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessMaintenanceDetector.java b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessMaintenanceDetector.java index 2505ce8d80..598e289c66 100644 --- a/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessMaintenanceDetector.java +++ b/src/main/java/gregtech/common/covers/redstone/GT_Cover_WirelessMaintenanceDetector.java @@ -1,8 +1,10 @@ package gregtech.common.covers.redstone; import com.google.common.io.ByteArrayDataInput; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiIconCheckButton; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.ICoverable; @@ -11,17 +13,15 @@ import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.util.ISerializableObject; import gregtech.common.covers.GT_Cover_NeedMaintainance; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_ToggleButtonWidget; import io.netty.buffer.ByteBuf; import java.util.UUID; import javax.annotation.Nonnull; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; public class GT_Cover_WirelessMaintenanceDetector extends GT_Cover_AdvancedRedstoneTransmitterBase< @@ -188,82 +188,65 @@ public class GT_Cover_WirelessMaintenanceDetector } } - /** - * GUI Stuff - */ + // GUI stuff + private static final String[] extraTexts = new String[] { "No Issues", ">= 1 Issue", ">= 2 Issues", ">= 3 Issues", ">= 4 Issues", ">= 5 Issues", "Rotor < 80%", "Rotor < 100%" }; @Override - public Object getClientGUIImpl( - byte aSide, - int aCoverID, - MaintenanceTransmitterData aCoverVariable, - ICoverable aTileEntity, - EntityPlayer aPlayer, - World aWorld) { - return new MaintenanceTransmitterGUI(aSide, aCoverID, aCoverVariable, aTileEntity); + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new WirelessMaintenanceDetectorUIFactory(buildContext).createWindow(); } - private class MaintenanceTransmitterGUI extends TransmitterGUI<MaintenanceTransmitterData> { - - private static final String guiTexturePath = "gregtech:textures/gui/GuiCoverBig.png"; - private static final int maintenanceButtonIdStart = 2; - - public MaintenanceTransmitterGUI( - byte aSide, int aCoverID, MaintenanceTransmitterData aCoverVariable, ICoverable aTileEntity) { - super(aSide, aCoverID, aCoverVariable, aTileEntity); - this.mGUIbackgroundLocation = new ResourceLocation(guiTexturePath); - this.gui_height = 143; - - for (int i = 0; i < 8; ++i) { - new GT_GuiIconCheckButton( - this, - maintenanceButtonIdStart + i, - startX + spaceX * (i % 2 == 0 ? 0 : 6), - startY + spaceY * (2 + i / 2), - GT_GuiIcon.CHECKMARK, - null); - } + private class WirelessMaintenanceDetectorUIFactory extends AdvancedRedstoneTransmitterBaseUIFactory { + + public WirelessMaintenanceDetectorUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); } @Override - public void drawExtras(int mouseX, int mouseY, float parTicks) { - super.drawExtras(mouseX, mouseY, parTicks); - for (int i = 0; i < 8; ++i) { - this.getFontRenderer() - .drawString( - extraTexts[i], - startX + spaceX * (i % 2 == 0 ? 1 : 7), - 4 + startY + spaceY * (2 + i / 2), - textColor); - } + protected int getGUIHeight() { + return 143; } @Override - protected void update() { - super.update(); - updateButtons(); + protected int getFrequencyRow() { + return 0; } - private void updateButtons() { - GT_GuiIconCheckButton button; - for (int i = maintenanceButtonIdStart; i < maintenanceButtonIdStart + 8; ++i) { - button = (GT_GuiIconCheckButton) this.buttonList.get(i); - button.enabled = (button.id - maintenanceButtonIdStart) != coverVariable.mode.ordinal(); - button.setChecked(!button.enabled); - } + @Override + protected int getButtonRow() { + return 1; } @Override - public void buttonClicked(GuiButton btn) { - if (btn.id >= maintenanceButtonIdStart && btn.enabled) { - coverVariable.mode = MaintenanceMode.values()[btn.id - maintenanceButtonIdStart]; + protected void addUIWidgets(ModularWindow.Builder builder) { + super.addUIWidgets(builder); + for (int i = 0; i < 8; i++) { + builder.widget(new TextWidget(extraTexts[i]) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX + spaceX * (i % 2 == 0 ? 1 : 7), 4 + startY + spaceY * (2 + i / 2))); } + } - super.buttonClicked(btn); + @Override + protected void addUIForDataController(CoverDataControllerWidget<MaintenanceTransmitterData> controller) { + super.addUIForDataController(controller); + for (int i = 0; i < 8; i++) { + final int index = i; + controller.addFollower( + CoverDataFollower_ToggleButtonWidget.ofDisableable(), + coverData -> coverData.mode == MaintenanceMode.values()[index], + (coverData, state) -> { + coverData.mode = MaintenanceMode.values()[index]; + return coverData; + }, + widget -> widget.setToggleTexture( + GT_UITextures.OVERLAY_BUTTON_CHECKMARK, GT_UITextures.TRANSPARENT) + .setPos(spaceX * (index % 2 == 0 ? 0 : 6), spaceY * (2 + index / 2))); + } } } } diff --git a/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java b/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java deleted file mode 100644 index 2f8fd2a356..0000000000 --- a/src/main/java/gregtech/common/gui/GT_ContainerVolumetricFlask.java +++ /dev/null @@ -1,20 +0,0 @@ -package gregtech.common.gui; - -import gregtech.common.items.GT_VolumetricFlask; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.item.ItemStack; - -public final class GT_ContainerVolumetricFlask extends Container { - ItemStack flask; - - public GT_ContainerVolumetricFlask(InventoryPlayer inventoryPlayer) { - flask = inventoryPlayer.getCurrentItem(); - } - - @Override - public boolean canInteractWith(EntityPlayer p) { - return (flask != null) && (flask.stackSize > 0) && ((flask.getItem() instanceof GT_VolumetricFlask)); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_AdvDebugStructureWriter.java b/src/main/java/gregtech/common/gui/GT_Container_AdvDebugStructureWriter.java deleted file mode 100644 index 15837364f5..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_AdvDebugStructureWriter.java +++ /dev/null @@ -1,213 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.debug.GT_MetaTileEntity_AdvDebugStructureWriter; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_AdvDebugStructureWriter extends GT_ContainerMetaTile_Machine { - public short[] numbers = new short[6]; - public boolean transpose; - public boolean showHighlightBox; - - public Slot printSlot; - public Slot transposeSlot; - public Slot highlightSlot; - - public GT_Container_AdvDebugStructureWriter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 63, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 81, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 8, 99, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 63, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 81, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 26, 99, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 63, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 81, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 152, 99, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 63, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 81, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 134, 99, false, false, 1)); - - printSlot = addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 12, 129, false, false, 1)); - transposeSlot = addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 33, 129, false, false, 1)); - highlightSlot = addSlotToContainer(new GT_Slot_Holo(mTileEntity, 2, 54, 129, false, false, 1)); - } - - public boolean doesBindPlayerInventory() { - return false; - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 0) { - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - Slot tSlot = (Slot) inventorySlots.get(aSlotIndex); - if (tSlot != null && mTileEntity.getMetaTileEntity() != null) { - GT_MetaTileEntity_AdvDebugStructureWriter dsw = - (GT_MetaTileEntity_AdvDebugStructureWriter) mTileEntity.getMetaTileEntity(); - if (dsw.numbers == null) { - return null; - } - switch (aSlotIndex) { - case 0: - dsw.numbers[0] -= aShifthold == 1 ? 512 : 64; - return null; - case 1: - dsw.numbers[1] -= aShifthold == 1 ? 512 : 64; - return null; - case 2: - dsw.numbers[2] -= aShifthold == 1 ? 512 : 64; - return null; - case 3: - dsw.numbers[3] -= aShifthold == 1 ? 512 : 64; - return null; - case 4: - dsw.numbers[4] -= aShifthold == 1 ? 512 : 64; - return null; - case 5: - dsw.numbers[5] -= aShifthold == 1 ? 512 : 64; - return null; - case 6: - dsw.numbers[0] -= aShifthold == 1 ? 16 : 1; - return null; - case 7: - dsw.numbers[1] -= aShifthold == 1 ? 16 : 1; - return null; - case 8: - dsw.numbers[2] -= aShifthold == 1 ? 16 : 1; - return null; - case 9: - dsw.numbers[3] -= aShifthold == 1 ? 16 : 1; - return null; - case 10: - dsw.numbers[4] -= aShifthold == 1 ? 16 : 1; - return null; - case 11: - dsw.numbers[5] -= aShifthold == 1 ? 16 : 1; - return null; - case 12: - dsw.numbers[0] += aShifthold == 1 ? 512 : 64; - return null; - case 13: - dsw.numbers[1] += aShifthold == 1 ? 512 : 64; - return null; - case 14: - dsw.numbers[2] += aShifthold == 1 ? 512 : 64; - return null; - case 15: - dsw.numbers[3] += aShifthold == 1 ? 512 : 64; - return null; - case 16: - dsw.numbers[4] += aShifthold == 1 ? 512 : 64; - return null; - case 17: - dsw.numbers[5] += aShifthold == 1 ? 512 : 64; - return null; - case 18: - dsw.numbers[0] += aShifthold == 1 ? 16 : 1; - return null; - case 19: - dsw.numbers[1] += aShifthold == 1 ? 16 : 1; - return null; - case 20: - dsw.numbers[2] += aShifthold == 1 ? 16 : 1; - return null; - case 21: - dsw.numbers[3] += aShifthold == 1 ? 16 : 1; - return null; - case 22: - dsw.numbers[4] += aShifthold == 1 ? 16 : 1; - return null; - case 23: - dsw.numbers[5] += aShifthold == 1 ? 16 : 1; - return null; - - case 24: - if (dsw.getBaseMetaTileEntity().isServerSide()) { - dsw.printStructure(aPlayer); - } - return null; - case 25: - dsw.transpose = !dsw.transpose; - return null; - case 26: - dsw.showHighlightBox = !dsw.showHighlightBox; - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) { - return; - } - GT_MetaTileEntity_AdvDebugStructureWriter dsw = - (GT_MetaTileEntity_AdvDebugStructureWriter) mTileEntity.getMetaTileEntity(); - if (numbers != null) { - System.arraycopy(dsw.numbers, 0, numbers, 0, dsw.numbers.length); - } - - transpose = dsw.transpose; - showHighlightBox = dsw.showHighlightBox; - - for (Object crafter : crafters) { - ICrafting var1 = (ICrafting) crafter; - if (numbers != null) { - var1.sendProgressBarUpdate(this, 100, numbers[0]); - var1.sendProgressBarUpdate(this, 101, numbers[1]); - var1.sendProgressBarUpdate(this, 102, numbers[2]); - var1.sendProgressBarUpdate(this, 103, numbers[3]); - var1.sendProgressBarUpdate(this, 104, numbers[4]); - var1.sendProgressBarUpdate(this, 105, numbers[5]); - var1.sendProgressBarUpdate(this, 106, transpose ? 1 : 0); - var1.sendProgressBarUpdate(this, 107, showHighlightBox ? 1 : 0); - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int par1, int par2) { - super.updateProgressBar(par1, par2); - if (par1 == 106) { - transpose = par2 > 0; - } else if (par1 == 107) { - showHighlightBox = par2 > 0; - } else { - if (numbers != null && par1 >= 100 && par1 <= 105) { - numbers[par1 - 100] = (short) par2; - } - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_Boiler.java b/src/main/java/gregtech/common/gui/GT_Container_Boiler.java deleted file mode 100644 index a29e732f07..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_Boiler.java +++ /dev/null @@ -1,99 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.boilers.GT_MetaTileEntity_Boiler; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; - -public class GT_Container_Boiler extends GT_ContainerMetaTile_Machine { - public int mWaterAmount = 0; - public int mSteamAmount = 0; - public int mProcessingEnergy = 0; - public int mTemperature = 2; - - public GT_Container_Boiler(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(this.mTileEntity, 2, 116, 62)); - addSlotToContainer(new Slot(this.mTileEntity, 0, 44, 26)); - addSlotToContainer(new Slot(this.mTileEntity, 1, 44, 62)); - addSlotToContainer(new Slot(this.mTileEntity, 3, 116, 26)); - } - - @Override - public int getSlotCount() { - return 4; - } - - @Override - public int getShiftClickSlotCount() { - return 1; - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { - return; - } - - // GT_MetaTileEntity_Boiler.getCapacity() is used for both water and steam capacity. - int capacity = ((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).getCapacity(); - - this.mTemperature = ((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mTemperature; - this.mProcessingEnergy = ((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mProcessingEnergy; - this.mSteamAmount = (((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mSteam == null - ? 0 - : ((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mSteam.amount); - this.mWaterAmount = (((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mFluid == null - ? 0 - : ((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).mFluid.amount); - - this.mTemperature = Math.min( - 54, - Math.max( - 0, - this.mTemperature - * 54 - / (((GT_MetaTileEntity_Boiler) this.mTileEntity.getMetaTileEntity()).maxProgresstime() - - 10))); - this.mSteamAmount = Math.min(54, Math.max(0, this.mSteamAmount * 54 / (capacity - 100))); - this.mWaterAmount = Math.min(54, Math.max(0, this.mWaterAmount * 54 / (capacity - 100))); - this.mProcessingEnergy = - Math.min(14, Math.max(this.mProcessingEnergy > 0 ? 1 : 0, this.mProcessingEnergy * 14 / 1000)); - - for (Object crafter : this.crafters) { - ICrafting player = (ICrafting) crafter; - player.sendProgressBarUpdate(this, 100, this.mTemperature); - player.sendProgressBarUpdate(this, 101, this.mProcessingEnergy); - player.sendProgressBarUpdate(this, 102, this.mSteamAmount); - player.sendProgressBarUpdate(this, 103, this.mWaterAmount); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 100: - this.mTemperature = value; - break; - case 101: - this.mProcessingEnergy = value; - break; - case 102: - this.mSteamAmount = value; - break; - case 103: - this.mWaterAmount = value; - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_BronzeBlastFurnace.java b/src/main/java/gregtech/common/gui/GT_Container_BronzeBlastFurnace.java deleted file mode 100644 index ac2f18f561..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_BronzeBlastFurnace.java +++ /dev/null @@ -1,31 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Output; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; - -public class GT_Container_BronzeBlastFurnace extends GT_ContainerMetaTile_Machine { - public GT_Container_BronzeBlastFurnace(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(this.mTileEntity, 0, 34, 16)); - addSlotToContainer(new Slot(this.mTileEntity, 1, 34, 34)); - addSlotToContainer(new GT_Slot_Output(this.mTileEntity, 2, 86, 25)); - addSlotToContainer(new GT_Slot_Output(this.mTileEntity, 3, 104, 25)); - } - - @Override - public int getSlotCount() { - return 4; - } - - @Override - public int getShiftClickSlotCount() { - return 2; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_ChestBuffer.java b/src/main/java/gregtech/common/gui/GT_Container_ChestBuffer.java deleted file mode 100644 index afa22a738b..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_ChestBuffer.java +++ /dev/null @@ -1,102 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_ChestBuffer; -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_ChestBuffer extends GT_ContainerMetaTile_Machine { - public GT_Container_ChestBuffer(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 9; x++) { - addSlotToContainer(new Slot(this.mTileEntity, x + y * 9, 8 + x * 18, 5 + y * 18)); - } - } - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 8, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 26, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 44, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 62, 63, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 27) { - 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 == 27) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 28) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("118", "Emit Redstone if no Slot is free")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("119", "Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 29) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("120", "Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("121", "Don't invert Redstone")); - } - return null; - } - if (aSlotIndex == 30) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode) { - GT_Utility.sendChatToPlayer( - aPlayer, - GT_Utility.trans( - "217", - "Stocking mode. Keeps this many items in destination input slots. This mode can be server unfriendly.")); - } else { - GT_Utility.sendChatToPlayer( - aPlayer, - GT_Utility.trans( - "218", - "Transfer size mode. Add exactly this many items in destination input slots as long as there is room.")); - } - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public int getSlotCount() { - return 27; - } - - @Override - public int getShiftClickSlotCount() { - return 27; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_Filter.java b/src/main/java/gregtech/common/gui/GT_Container_Filter.java deleted file mode 100644 index d4aabe0cb4..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_Filter.java +++ /dev/null @@ -1,138 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_Filter; -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_Filter extends GT_ContainerMetaTile_Machine { - public GT_Container_Filter(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_Holo(this.mTileEntity, 9, 18, 6, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 35, 6, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 11, 52, 6, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 12, 18, 23, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 13, 35, 23, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 14, 52, 23, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 15, 18, 40, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 16, 35, 40, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 17, 52, 40, false, true, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 8, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 26, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 44, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 62, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 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 < 18) { - ItemStack tStack = aPlayer.inventory.getItemStack(); - if (tStack == null) { - tStack = tSlot.getStack(); - if (aMouseclick == 0) { - tSlot.putStack(null); - } else if (tStack != null) { - tStack = GT_Utility.copyAmountAndMetaData(tStack.stackSize, 32767, tStack); - if (GT_Utility.isStackInvalid(tStack)) { - tStack = null; - } - } - } else { - tSlot.putStack(GT_Utility.copyAmount(1L, new Object[] {tStack})); - } - return null; - } - if (aSlotIndex == 18) { - ((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 19) { - ((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = - (!((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer( - aPlayer, GT_Utility.trans("122", "Emit Redstone if slots contain something")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("123", "Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 20) { - ((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvert = - (!((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("120", "Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("121", "Don't invert Redstone")); - } - return null; - } - if (aSlotIndex == 21) { - ((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvertFilter = - (!((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvertFilter); - if (((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bInvertFilter) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("124", "Invert Filter")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("125", "Don't invert Filter")); - } - return null; - } - if (aSlotIndex == 22) { - ((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bIgnoreNBT = - (!((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bIgnoreNBT); - if (((GT_MetaTileEntity_Filter) this.mTileEntity.getMetaTileEntity()).bIgnoreNBT) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("126", "Ignore NBT")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.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_Container_IndustrialApiary.java b/src/main/java/gregtech/common/gui/GT_Container_IndustrialApiary.java deleted file mode 100644 index 18cbee5d9c..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_IndustrialApiary.java +++ /dev/null @@ -1,249 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import forestry.api.core.ForestryAPI; -import forestry.api.core.IErrorState; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.gui.GT_Slot_Output; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_ApiaryUpgrade; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_IndustrialApiary; -import java.util.ArrayList; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; - -public class GT_Container_IndustrialApiary extends GT_ContainerMetaTile_Machine { - - GT_Slot_Holo slotItemTransferToggle; - GT_Slot_Holo slotSpeedToggle; - GT_Slot_Holo slotCancelProcess; - Slot slotBattery; - Slot slotSpecial; - ArrayList<Slot> slotUpgrade; - - boolean mItemTransfer; - boolean mStuttering; - - int mSpeed = 0; // scale 0 - 8 - boolean mLockedSpeed = true; - - ArrayList<String> mErrorStates = new ArrayList<>(50); - - public GT_Container_IndustrialApiary(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(slotItemTransferToggle = new GT_Slot_Holo(mTileEntity, 0, 8, 63, false, true, 1)); - addSlotToContainer(slotSpeedToggle = new GT_Slot_Holo(mTileEntity, 0, 26, 63, false, true, 1)); - addSlotToContainer(slotCancelProcess = new GT_Slot_Holo(mTileEntity, 0, 8, 27, false, true, 1)); - int tStartIndex = 5; - - addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 22)); - addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 37, 42)); - - slotUpgrade = new ArrayList<>(4); - slotUpgrade.add(addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 24))); - slotUpgrade.add(addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 24))); - slotUpgrade.add(addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 62, 42))); - slotUpgrade.add(addSlotToContainer(new ApiarySlot(this.mTileEntity, tStartIndex++, 80, 42))); - - for (int i = 107; i <= 143; i += 18) - for (int j = 6; j <= 42; j += 18) - addSlotToContainer(new GT_Slot_Output(this.mTileEntity, tStartIndex++, i, j)); - - addSlotToContainer(slotBattery = new Slot(mTileEntity, 1, 80, 63)); - addSlotToContainer(slotSpecial = new Slot(mTileEntity, 3, 125, 63)); - } - - @Override - public ItemStack slotClick(int aSlotNumber, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (mTileEntity.getMetaTileEntity() == null) return null; - GT_MetaTileEntity_IndustrialApiary machine = getMachine(); - if (machine == null) return null; - switch (aSlotNumber) { - case 0: - machine.mItemTransfer = !machine.mItemTransfer; - return null; - case 1: - if (aMouseclick == 0) { - if (machine.mLockedSpeed) return null; - if (aShifthold == 0) { - machine.mSpeed++; - if (machine.mSpeed > machine.getMaxSpeed()) machine.mSpeed = 0; - } else if (aShifthold == 1) { - machine.mSpeed--; - if (machine.mSpeed < 0) machine.mSpeed = machine.getMaxSpeed(); - } - } else if (aMouseclick == 1) { - machine.mLockedSpeed = !machine.mLockedSpeed; - if (machine.mLockedSpeed) machine.mSpeed = machine.getMaxSpeed(); - } - return null; - case 2: - machine.cancelProcess(); - detectAndSendChanges(); - return null; - } - - if (!(aSlotNumber >= getSlotStartIndex() + 2 && aSlotNumber < getSlotStartIndex() + 2 + 4)) - return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - if (aShifthold == 5) return null; - if (aShifthold != 0) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - if (aMouseclick > 1) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - ItemStack s = aPlayer.inventory.getItemStack(); - if (s == null) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - Slot slot = getSlot(aSlotNumber); - ItemStack slotstack = slot.getStack(); - if (slotstack != null && !GT_Utility.areStacksEqual(slotstack, s)) return null; // super would replace item - if (slotstack == null && !slot.isItemValid(s)) - return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - if (!GT_ApiaryUpgrade.isUpgrade(s)) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - int max = GT_ApiaryUpgrade.getUpgrade(s).getMaxNumber(); - if (slotstack != null) max = Math.max(0, max - slotstack.stackSize); - max = Math.min(max, s.stackSize); - if (max == 0) return null; - if (aMouseclick == 1) max = 1; - if (max == s.stackSize) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - ItemStack newstack = s.splitStack(s.stackSize - max); - ItemStack result = super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); - aPlayer.inventory.setItemStack(newstack); - return result; - } - - @Override - public int getSlotStartIndex() { - return 3; - } - - @Override - public int getSlotCount() { - return 6 + 9 + 2; - } - - @Override - public int getShiftClickSlotCount() { - return 6; - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { - return; - } - - this.mSpeed = getMachine().mSpeed; - this.mItemTransfer = getMachine().mItemTransfer; - this.mStuttering = getMachine().mStuttering; - this.mLockedSpeed = getMachine().mLockedSpeed; - - for (Object crafter : this.crafters) { - ICrafting var1 = (ICrafting) crafter; - var1.sendProgressBarUpdate(this, 100, this.mSpeed); - var1.sendProgressBarUpdate(this, 101, this.mItemTransfer ? 1 : 0); - var1.sendProgressBarUpdate(this, 102, 0); - for (IErrorState s : getMachine().mErrorStates) var1.sendProgressBarUpdate(this, 103, s.getID()); - var1.sendProgressBarUpdate(this, 104, this.mStuttering ? 1 : 0); - var1.sendProgressBarUpdate(this, 105, this.mLockedSpeed ? 1 : 0); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int par1, int par2) { - super.updateProgressBar(par1, par2); - switch (par1) { - case 100: - this.mSpeed = par2; - break; - case 101: - this.mItemTransfer = par2 == 1; - break; - case 102: - this.mErrorStates.clear(); - break; - case 103: - this.mErrorStates.add(EnumChatFormatting.RED - + StatCollector.translateToLocal("for." - + ForestryAPI.errorStateRegistry - .getErrorState((short) par2) - .getDescription())); - break; - case 104: - this.mStuttering = par2 == 1; - break; - case 105: - this.mLockedSpeed = par2 == 1; - break; - } - } - - public GT_MetaTileEntity_IndustrialApiary getMachine() { - return (GT_MetaTileEntity_IndustrialApiary) mTileEntity.getMetaTileEntity(); - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) { - Slot s = getSlot(aSlotIndex); - if (s == null) return super.transferStackInSlot(aPlayer, aSlotIndex); - if (!(s.inventory instanceof InventoryPlayer)) return super.transferStackInSlot(aPlayer, aSlotIndex); - ItemStack aStack = s.getStack(); - if (aStack == null) return super.transferStackInSlot(aPlayer, aSlotIndex); - if (!GT_ApiaryUpgrade.isUpgrade(aStack)) return super.transferStackInSlot(aPlayer, aSlotIndex); - for (int i = getSlotStartIndex() + 2; i < getSlotStartIndex() + 2 + 4; i++) { - Slot iSlot = getSlot(i); - ItemStack iStack = iSlot.getStack(); - if (iStack == null) { - if (!iSlot.isItemValid(aStack)) continue; - } else { - if (!GT_Utility.areStacksEqual(aStack, iStack)) continue; - } - int max = GT_ApiaryUpgrade.getUpgrade(aStack).getMaxNumber(); - if (iStack == null) { - max = Math.min(max, aStack.stackSize); - ItemStack newstack = aStack.splitStack(max); - iSlot.putStack(newstack); - } else { - max = Math.max(0, max - iStack.stackSize); - max = Math.min(max, aStack.stackSize); - iStack.stackSize += max; - aStack.stackSize -= max; - iSlot.onSlotChanged(); - } - if (aStack.stackSize == 0) s.putStack(null); - else s.onSlotChanged(); - break; - } - return null; - } - - private static class ApiarySlot extends Slot { - - public ApiarySlot(IInventory p_i1824_1_, int p_i1824_2_, int p_i1824_3_, int p_i1824_4_) { - super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); - } - - @Override - public boolean isItemValid(ItemStack p_75214_1_) { - return this.inventory.isItemValidForSlot(this.getSlotIndex(), p_75214_1_); - } - - @Override - public void onSlotChanged() { - super.onSlotChanged(); - ((GT_MetaTileEntity_IndustrialApiary) ((IGregTechTileEntity) this.inventory).getMetaTileEntity()) - .onInventoryUpdate(this.getSlotIndex()); - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java b/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java deleted file mode 100644 index 58aff9ad08..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_InputBus_ME.java +++ /dev/null @@ -1,121 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.gui.GT_Slot_Holo_ME; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_InputBus_ME extends GT_ContainerMetaTile_Machine { - private static final int LEFT_OFFSET = 8; - private static final int TOP_OFFSET = 10; - private static final int SLOT_SIZE = 18; - public static final int CIRCUIT_SLOT = 32; - - public GT_Container_InputBus_ME(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - for (int y = 0; y < 4; ++y) - for (int x = 0; x < 4; ++x) - addSlotToContainer(new GT_Slot_Holo( - this.mTileEntity, - x + y * 4, - LEFT_OFFSET + x * SLOT_SIZE, - TOP_OFFSET + y * SLOT_SIZE, - false, - true, - 1)); - for (int y = 0; y < 4; ++y) - for (int x = 0; x < 4; ++x) { - GT_Slot_Holo_ME slot = new GT_Slot_Holo_ME( - this.mTileEntity, - x + y * 4 + 16, - LEFT_OFFSET + x * SLOT_SIZE + 90, - TOP_OFFSET + y * SLOT_SIZE, - false, - true); - addSlotToContainer(slot); - } - super.addSlots(aInventoryPlayer); - } - - private boolean containsSuchStack(ItemStack tStack) { - for (int i = 0; i < 16; ++i) { - Slot tSlot = (Slot) this.inventorySlots.get(i); - if (tSlot != null && GT_Utility.areStacksEqual(tSlot.getStack(), tStack, false)) return true; - } - return false; - } - - private static final int PROGRESS_PACKET_INDEX_OFFSET = 200; - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return; - for (Object crafter : this.crafters) { - ICrafting player = (ICrafting) crafter; - for (int i = 0; i < 16; ++i) { - ItemStack s = ((Slot) this.inventorySlots.get(i + 16)).getStack(); - if (s == null) continue; - player.sendProgressBarUpdate(this, PROGRESS_PACKET_INDEX_OFFSET + 2 * i, s.stackSize & 65535); - player.sendProgressBarUpdate(this, PROGRESS_PACKET_INDEX_OFFSET + 2 * i + 1, s.stackSize >>> 16); - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - if (id >= PROGRESS_PACKET_INDEX_OFFSET && id < (PROGRESS_PACKET_INDEX_OFFSET + 32)) { - int index = (id - PROGRESS_PACKET_INDEX_OFFSET) / 2; - ItemStack s = ((Slot) this.inventorySlots.get(index + 16)).getStack(); - if (s != null) { - if ((id - PROGRESS_PACKET_INDEX_OFFSET) % 2 == 0) { - s.stackSize &= 0xFFFF0000; - s.stackSize += (value & 0xFFFF); - } else { - s.stackSize &= 0xFFFF; - s.stackSize += value << 16; - } - } - } - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex >= 0 && aSlotIndex < 16) { - Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); - if (tSlot != null) { - if (this.mTileEntity.getMetaTileEntity() == null) return null; - ItemStack tStack = aPlayer.inventory.getItemStack(); - if (tStack == null) { - tSlot.putStack(null); - } else { - if (containsSuchStack(tStack)) return null; - tSlot.putStack(GT_Utility.copyAmount(1L, tStack)); - } - if (mTileEntity.isServerSide()) { - ItemStack newInfo = ((GT_MetaTileEntity_Hatch_InputBus_ME) mTileEntity.getMetaTileEntity()) - .updateInformationSlot(aSlotIndex, tStack); - ((Slot) this.inventorySlots.get(aSlotIndex + 16)).putStack(newInfo); - detectAndSendChanges(); - } - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_ItemDistributor.java b/src/main/java/gregtech/common/gui/GT_Container_ItemDistributor.java deleted file mode 100644 index 2de68c9752..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_ItemDistributor.java +++ /dev/null @@ -1,83 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_ItemDistributor; -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_ItemDistributor extends GT_ContainerMetaTile_Machine { - public GT_Container_ItemDistributor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 9; x++) { - addSlotToContainer(new Slot(this.mTileEntity, x + y * 9, 8 + x * 18, 5 + y * 18)); - } - } - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 8, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 26, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 27, 44, 63, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 27) { - 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 == 27) { - ((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 28) { - ((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = - (!((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("118", "Emit Redstone if no Slot is free")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("119", "Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 29) { - ((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bInvert = - (!((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_ItemDistributor) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("120", "Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("121", "Don't invert Redstone")); - } - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public int getSlotCount() { - return 27; - } - - @Override - public int getShiftClickSlotCount() { - return 27; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_MicrowaveEnergyTransmitter.java b/src/main/java/gregtech/common/gui/GT_Container_MicrowaveEnergyTransmitter.java deleted file mode 100644 index bd6b917f1f..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_MicrowaveEnergyTransmitter.java +++ /dev/null @@ -1,188 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_MicrowaveEnergyTransmitter; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_MicrowaveEnergyTransmitter extends GT_ContainerMetaTile_Machine { - public int mEgg = 0; - public int mTargetD = 0; - public int mTargetZ = 0; - public int mTargetY = 0; - public int mTargetX = 0; - - public GT_Container_MicrowaveEnergyTransmitter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 59, false, false, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 0) { - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); - if ((tSlot != null) && (this.mTileEntity.getMetaTileEntity() != null)) { - switch (aSlotIndex) { - case 0: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetX -= - (aShifthold == 1 ? 512 : 64); - return null; - case 1: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetY -= - (aShifthold == 1 ? 512 : 64); - return null; - case 2: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetZ -= - (aShifthold == 1 ? 512 : 64); - return null; - case 3: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetD -= - (aShifthold == 1 ? 16 : 8); - return null; - case 4: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetX -= - (aShifthold == 1 ? 16 : 1); - return null; - case 5: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetY -= - (aShifthold == 1 ? 16 : 1); - return null; - case 6: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetZ -= - (aShifthold == 1 ? 16 : 1); - return null; - case 7: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetD -= - (aShifthold == 1 ? 4 : 1); - return null; - case 8: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetX += - (aShifthold == 1 ? 512 : 64); - return null; - case 9: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetY += - (aShifthold == 1 ? 512 : 64); - return null; - case 10: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetZ += - (aShifthold == 1 ? 512 : 64); - return null; - case 11: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetD += - (aShifthold == 1 ? 16 : 8); - return null; - case 12: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetX += - (aShifthold == 1 ? 16 : 1); - return null; - case 13: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetY += - (aShifthold == 1 ? 16 : 1); - return null; - case 14: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetZ += - (aShifthold == 1 ? 16 : 1); - return null; - case 15: - ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetD += - (aShifthold == 1 ? 4 : 1); - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { - return; - } - this.mTargetX = ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetX; - this.mTargetY = ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetY; - this.mTargetZ = ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetZ; - this.mTargetD = ((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()).mTargetD; - this.mEgg = (((GT_MetaTileEntity_MicrowaveEnergyTransmitter) this.mTileEntity.getMetaTileEntity()) - .hasDimensionalTeleportCapability() - ? 1 - : 0); - - for (Object crafter : this.crafters) { - ICrafting aPlayer = (ICrafting) crafter; - aPlayer.sendProgressBarUpdate(this, 100, this.mTargetX & 0xFFFF); - aPlayer.sendProgressBarUpdate(this, 101, this.mTargetX >>> 16); - aPlayer.sendProgressBarUpdate(this, 102, this.mTargetY & 0xFFFF); - aPlayer.sendProgressBarUpdate(this, 103, this.mTargetY >>> 16); - aPlayer.sendProgressBarUpdate(this, 104, this.mTargetZ & 0xFFFF); - aPlayer.sendProgressBarUpdate(this, 105, this.mTargetZ >>> 16); - aPlayer.sendProgressBarUpdate(this, 106, this.mTargetD & 0xFFFF); - aPlayer.sendProgressBarUpdate(this, 107, this.mTargetD >>> 16); - aPlayer.sendProgressBarUpdate(this, 108, this.mEgg); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 100: - this.mTargetX = (this.mTargetX & 0xFFFF0000 | value & 0xFFFF); - break; - case 101: - this.mTargetX = (this.mTargetX & 0xFFFF | value << 16); - break; - case 102: - this.mTargetY = (this.mTargetY & 0xFFFF0000 | value & 0xFFFF); - break; - case 103: - this.mTargetY = (this.mTargetY & 0xFFFF | value << 16); - break; - case 104: - this.mTargetZ = (this.mTargetZ & 0xFFFF0000 | value & 0xFFFF); - break; - case 105: - this.mTargetZ = (this.mTargetZ & 0xFFFF | value << 16); - break; - case 106: - this.mTargetD = (this.mTargetD & 0xFFFF0000 | value & 0xFFFF); - break; - case 107: - this.mTargetD = (this.mTargetD & 0xFFFF | value << 16); - break; - case 108: - this.mEgg = value; - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java b/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java deleted file mode 100644 index e42e145eb3..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java +++ /dev/null @@ -1,53 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_Container_BasicTank; -import gregtech.api.gui.GT_Slot_Output; -import gregtech.api.gui.GT_Slot_Render; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; -import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class GT_Container_OutputHatch extends GT_Container_BasicTank { - - public GT_Container_OutputHatch(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(mTileEntity, 0, 80, 17)); - addSlotToContainer(new GT_Slot_Output(mTileEntity, 1, 80, 53)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 3, 150, 42)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex == 3 && aMouseclick < 2) { - GT_MetaTileEntity_Hatch_Output tHatch = (GT_MetaTileEntity_Hatch_Output) mTileEntity.getMetaTileEntity(); - FluidStack tReadyLockFluid = GT_Utility.getFluidForFilledItem(aPlayer.inventory.getItemStack(), true); - byte tMode = tHatch.getMode(); - // If player click the locker slot with empty or the same fluid cell, clear the lock fluid - if (tReadyLockFluid == null - || (tMode >= 8 && tReadyLockFluid.getFluid().getName().equals(tHatch.getLockedFluidName()))) { - tHatch.setLockedFluidName(null); - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("300.1", "Fluid Lock Cleared.")); - tHatch.lockFluid(false); - } else { - tHatch.setLockedFluidName(tReadyLockFluid.getFluid().getName()); - GT_Utility.sendChatToPlayer( - aPlayer, - String.format( - GT_Utility.trans("151.4", "Successfully locked Fluid to %s"), - tReadyLockFluid.getLocalizedName())); - tHatch.lockFluid(true); - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/gui/GT_Container_PrimitiveBlastFurnace.java deleted file mode 100644 index e19b6167ec..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_PrimitiveBlastFurnace.java +++ /dev/null @@ -1,37 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Output; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_PrimitiveBlastFurnace; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; - -public class GT_Container_PrimitiveBlastFurnace extends GT_ContainerMetaTile_Machine { - - public GT_Container_PrimitiveBlastFurnace(InventoryPlayer inventoryPlayer, IGregTechTileEntity tileEntity) { - super(inventoryPlayer, tileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - for (int i = 0; i < GT_MetaTileEntity_PrimitiveBlastFurnace.INPUT_SLOTS; i++) { - addSlotToContainer(new Slot(this.mTileEntity, i, 34, 16 + 18 * i)); - } - for (int i = 0; i < GT_MetaTileEntity_PrimitiveBlastFurnace.OUTPUT_SLOTS; i++) { - addSlotToContainer(new GT_Slot_Output( - mTileEntity, GT_MetaTileEntity_PrimitiveBlastFurnace.INPUT_SLOTS + i, 86 + i * 18, 25)); - } - } - - @Override - public int getSlotCount() { - return GT_MetaTileEntity_PrimitiveBlastFurnace.INPUT_SLOTS - + GT_MetaTileEntity_PrimitiveBlastFurnace.OUTPUT_SLOTS; - } - - @Override - public int getShiftClickSlotCount() { - return GT_MetaTileEntity_PrimitiveBlastFurnace.INPUT_SLOTS; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_QuantumChest.java b/src/main/java/gregtech/common/gui/GT_Container_QuantumChest.java deleted file mode 100644 index a072017d08..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_QuantumChest.java +++ /dev/null @@ -1,70 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Output; -import gregtech.api.gui.GT_Slot_Render; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.storage.GT_MetaTileEntity_QuantumChest; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; - -public class GT_Container_QuantumChest extends GT_ContainerMetaTile_Machine { - - public int mContent = 0; - - public GT_Container_QuantumChest(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new Slot(mTileEntity, 0, 80, 17)); - addSlotToContainer(new GT_Slot_Output(mTileEntity, 1, 80, 53)); - addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42)); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - - if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return; - if (mTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_QuantumChest) { - mContent = ((GT_MetaTileEntity_QuantumChest) mTileEntity.getMetaTileEntity()).mItemCount; - } else { - mContent = 0; - } - - for (Object crafter : this.crafters) { - ICrafting aPlayer = (ICrafting) crafter; - aPlayer.sendProgressBarUpdate(this, 100, mContent & 65535); - aPlayer.sendProgressBarUpdate(this, 101, mContent >>> 16); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 100: - mContent = mContent & 0xffff0000 | value & 0x0000ffff; - break; - case 101: - mContent = mContent & 0x0000ffff | value << 16; - break; - } - } - - @Override - public int getSlotCount() { - return 2; - } - - @Override - public int getShiftClickSlotCount() { - return 1; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java b/src/main/java/gregtech/common/gui/GT_Container_Regulator.java deleted file mode 100644 index 3079b40470..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_Regulator.java +++ /dev/null @@ -1,177 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_Regulator; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_Regulator extends GT_ContainerMetaTile_Machine { - public int[] mTargetSlots = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - - public GT_Container_Regulator(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - this.mTargetSlots = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0}; - - addSlotToContainer(new Slot(this.mTileEntity, 0, 8, 6)); - addSlotToContainer(new Slot(this.mTileEntity, 1, 26, 6)); - addSlotToContainer(new Slot(this.mTileEntity, 2, 44, 6)); - addSlotToContainer(new Slot(this.mTileEntity, 3, 8, 24)); - addSlotToContainer(new Slot(this.mTileEntity, 4, 26, 24)); - addSlotToContainer(new Slot(this.mTileEntity, 5, 44, 24)); - addSlotToContainer(new Slot(this.mTileEntity, 6, 8, 42)); - addSlotToContainer(new Slot(this.mTileEntity, 7, 26, 42)); - addSlotToContainer(new Slot(this.mTileEntity, 8, 44, 42)); - - addSlotToContainer(new Slot(this.mTileEntity, 19, 44, 63)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 9, 64, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 10, 81, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 11, 98, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 12, 64, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 13, 81, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 14, 98, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 15, 64, 41, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 16, 81, 41, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 17, 98, 41, false, true, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 7, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 24, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 119, 41, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 136, 41, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 153, 41, false, true, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 18, 8, 63, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 10) { - 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 == 28) { - ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if ((aSlotIndex < 19)) { - ItemStack tStack = aPlayer.inventory.getItemStack(); - if (tStack != null) { - tSlot.putStack(GT_Utility.copyOrNull(tStack)); - } else if (tSlot.getStack() != null) { - if (aMouseclick == 0) { - tSlot.getStack().stackSize -= (aShifthold == 1 ? 8 : 1); - if (tSlot.getStack().stackSize <= 0) { - tSlot.putStack(null); - } - } else { - tSlot.getStack().stackSize += (aShifthold == 1 ? 8 : 1); - if (tSlot.getStack().stackSize > tSlot.getStack().getMaxStackSize()) { - tSlot.getStack().stackSize = tSlot.getStack().getMaxStackSize(); - } - } - } - return null; - } - if ((aSlotIndex < 28)) { - ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[(aSlotIndex - 19)] = - Math.min( - 99, - Math.max( - 0, - ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()) - .mTargetSlots[(aSlotIndex - 19)] - + (aMouseclick == 0 ? -1 : 1) * (aShifthold == 0 ? 1 : 16))); - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { - return; - } - this.mTargetSlots = new int[9]; - for (int i = 0; i < 9; i++) { - this.mTargetSlots[i] = ((GT_MetaTileEntity_Regulator) this.mTileEntity.getMetaTileEntity()).mTargetSlots[i]; - } - for (Object crafter : this.crafters) { - ICrafting player = (ICrafting) crafter; - for (int i = 0; i < 9; i++) { - player.sendProgressBarUpdate(this, 100 + i, this.mTargetSlots[i]); - } - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 100: - this.mTargetSlots[0] = value; - break; - case 101: - this.mTargetSlots[1] = value; - break; - case 102: - this.mTargetSlots[2] = value; - break; - case 103: - this.mTargetSlots[3] = value; - break; - case 104: - this.mTargetSlots[4] = value; - break; - case 105: - this.mTargetSlots[5] = value; - break; - case 106: - this.mTargetSlots[6] = value; - break; - case 107: - this.mTargetSlots[7] = value; - break; - case 108: - this.mTargetSlots[8] = value; - } - } - - @Override - public int getSlotCount() { - return 10; - } - - @Override - public int getShiftClickSlotCount() { - return 10; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_SuperBuffer.java b/src/main/java/gregtech/common/gui/GT_Container_SuperBuffer.java deleted file mode 100644 index 0fda1a485f..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_SuperBuffer.java +++ /dev/null @@ -1,97 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.automation.GT_MetaTileEntity_ChestBuffer; -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_SuperBuffer extends GT_ContainerMetaTile_Machine { - public GT_Container_SuperBuffer(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 256, 8, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 256, 26, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 256, 44, 63, false, true, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 256, 62, 63, false, true, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 0) { - 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 == 0) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bOutput) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("116", "Emit Energy to Outputside")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("117", "Don't emit Energy")); - } - return null; - } - if (aSlotIndex == 1) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bRedstoneIfFull) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("118", "Emit Redstone if no Slot is free")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("119", "Don't emit Redstone")); - } - return null; - } - if (aSlotIndex == 2) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bInvert) { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("120", "Invert Redstone")); - } else { - GT_Utility.sendChatToPlayer(aPlayer, GT_Utility.trans("121", "Don't invert Redstone")); - } - return null; - } - if (aSlotIndex == 3) { - ((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode = - (!((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode); - if (((GT_MetaTileEntity_ChestBuffer) this.mTileEntity.getMetaTileEntity()).bStockingMode) { - GT_Utility.sendChatToPlayer( - aPlayer, - GT_Utility.trans( - "217", - "Stocking mode. Keeps this many items in destination input slots. This mode can be server unfriendly.")); - } else { - GT_Utility.sendChatToPlayer( - aPlayer, - GT_Utility.trans( - "218", - "Transfer size mode. Add exactly this many items in destination input slots as long as there is room.")); - } - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public int getSlotCount() { - return 0; - } - - @Override - public int getShiftClickSlotCount() { - return 0; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_Container_Teleporter.java b/src/main/java/gregtech/common/gui/GT_Container_Teleporter.java deleted file mode 100644 index 219391e662..0000000000 --- a/src/main/java/gregtech/common/gui/GT_Container_Teleporter.java +++ /dev/null @@ -1,190 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.gui.GT_ContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Teleporter; -import java.util.Iterator; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GT_Container_Teleporter extends GT_ContainerMetaTile_Machine { - public int mEgg = 0; - public int mTargetD = 0; - public int mTargetZ = 0; - public int mTargetY = 0; - public int mTargetX = 0; - - public GT_Container_Teleporter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(aInventoryPlayer, aTileEntity); - } - - @Override - public void addSlots(InventoryPlayer aInventoryPlayer) { - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 8, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 26, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 152, 59, false, false, 1)); - - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 5, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 23, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 41, false, false, 1)); - addSlotToContainer(new GT_Slot_Holo(this.mTileEntity, 2, 134, 59, false, false, 1)); - } - - @Override - public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (aSlotIndex < 0) { - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - Slot tSlot = (Slot) this.inventorySlots.get(aSlotIndex); - if ((tSlot != null) && (this.mTileEntity.getMetaTileEntity() != null)) { - switch (aSlotIndex) { - case 0: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetX -= - (aShifthold == 1 ? 512 : 64); - return null; - case 1: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetY -= - (aShifthold == 1 ? 512 : 64); - return null; - case 2: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetZ -= - (aShifthold == 1 ? 512 : 64); - return null; - case 3: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetD -= - (aShifthold == 1 ? 16 : 8); - return null; - case 4: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetX -= - (aShifthold == 1 ? 16 : 1); - return null; - case 5: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetY -= - (aShifthold == 1 ? 16 : 1); - return null; - case 6: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetZ -= - (aShifthold == 1 ? 16 : 1); - return null; - case 7: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetD -= - (aShifthold == 1 ? 4 : 1); - return null; - case 8: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetX += - (aShifthold == 1 ? 512 : 64); - return null; - case 9: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetY += - (aShifthold == 1 ? 512 : 64); - return null; - case 10: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetZ += - (aShifthold == 1 ? 512 : 64); - return null; - case 11: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetD += - (aShifthold == 1 ? 16 : 8); - return null; - case 12: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetX += - (aShifthold == 1 ? 16 : 1); - return null; - case 13: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetY += - (aShifthold == 1 ? 16 : 1); - return null; - case 14: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetZ += - (aShifthold == 1 ? 16 : 1); - return null; - case 15: - ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetD += - (aShifthold == 1 ? 4 : 1); - return null; - } - } - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); - } - - @Override - public void detectAndSendChanges() { - super.detectAndSendChanges(); - if ((this.mTileEntity.isClientSide()) || (this.mTileEntity.getMetaTileEntity() == null)) { - return; - } - this.mTargetX = ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetX; - this.mTargetY = ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetY; - this.mTargetZ = ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetZ; - this.mTargetD = ((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()).mTargetD; - this.mEgg = (((GT_MetaTileEntity_Teleporter) this.mTileEntity.getMetaTileEntity()) - .hasDimensionalTeleportCapability() - ? 1 - : 0); - - Iterator playerIterator = this.crafters.iterator(); - while (playerIterator.hasNext()) { - ICrafting player = (ICrafting) playerIterator.next(); - player.sendProgressBarUpdate(this, 100, this.mTargetX & 0xFFFF); - player.sendProgressBarUpdate(this, 101, this.mTargetX >>> 16); - player.sendProgressBarUpdate(this, 102, this.mTargetY & 0xFFFF); - player.sendProgressBarUpdate(this, 103, this.mTargetY >>> 16); - player.sendProgressBarUpdate(this, 104, this.mTargetZ & 0xFFFF); - player.sendProgressBarUpdate(this, 105, this.mTargetZ >>> 16); - player.sendProgressBarUpdate(this, 106, this.mTargetD & 0xFFFF); - player.sendProgressBarUpdate(this, 107, this.mTargetD >>> 16); - player.sendProgressBarUpdate(this, 108, this.mEgg); - } - } - - @Override - @SideOnly(Side.CLIENT) - public void updateProgressBar(int id, int value) { - super.updateProgressBar(id, value); - switch (id) { - case 100: - this.mTargetX = (this.mTargetX & 0xFFFF0000 | value & 0xFFFF); - break; - case 101: - this.mTargetX = (this.mTargetX & 0xFFFF | value << 16); - break; - case 102: - this.mTargetY = (this.mTargetY & 0xFFFF0000 | value & 0xFFFF); - break; - case 103: - this.mTargetY = (this.mTargetY & 0xFFFF | value << 16); - break; - case 104: - this.mTargetZ = (this.mTargetZ & 0xFFFF0000 | value & 0xFFFF); - break; - case 105: - this.mTargetZ = (this.mTargetZ & 0xFFFF | value << 16); - break; - case 106: - this.mTargetD = (this.mTargetD & 0xFFFF0000 | value & 0xFFFF); - break; - case 107: - this.mTargetD = (this.mTargetD & 0xFFFF | value << 16); - break; - case 108: - this.mEgg = value; - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java b/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java deleted file mode 100644 index 45df55cbe9..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainerVolumetricFlask.java +++ /dev/null @@ -1,234 +0,0 @@ -package gregtech.common.gui; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.enums.GT_Values; -import gregtech.api.net.GT_Packet_UpdateItem; -import gregtech.common.items.GT_VolumetricFlask; -import java.text.DecimalFormat; -import java.text.ParseException; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; - -@SideOnly(Side.CLIENT) -public final class GT_GUIContainerVolumetricFlask extends GuiContainer { - private static final ResourceLocation BACKGROUND = - new ResourceLocation("gregtech:textures/gui/VolumetricFlask.png"); - - private GuiIntegerBox amount; - private GuiButton apply; - private GuiButton plus1; - private GuiButton plus10; - private GuiButton plus100; - private GuiButton plus1000; - private GuiButton minus1; - private GuiButton minus10; - private GuiButton minus100; - private GuiButton minus1000; - private GT_ContainerVolumetricFlask container; - - public GT_GUIContainerVolumetricFlask(GT_ContainerVolumetricFlask container) { - super(container); - this.container = container; - } - - @Override - public void initGui() { - super.initGui(); - - buttonList.add(plus1 = new GuiButton(0, guiLeft + 20, guiTop + 26, 22, 20, "+1")); - buttonList.add(plus10 = new GuiButton(0, guiLeft + 48, guiTop + 26, 28, 20, "+10")); - buttonList.add(plus100 = new GuiButton(0, guiLeft + 82, guiTop + 26, 32, 20, "+100")); - buttonList.add(plus1000 = new GuiButton(0, guiLeft + 120, guiTop + 26, 38, 20, "+1000")); - - buttonList.add(minus1 = new GuiButton(0, guiLeft + 20, guiTop + 75, 22, 20, "-1")); - buttonList.add(minus10 = new GuiButton(0, guiLeft + 48, guiTop + 75, 28, 20, "-10")); - buttonList.add(minus100 = new GuiButton(0, guiLeft + 82, guiTop + 75, 32, 20, "-100")); - buttonList.add(minus1000 = new GuiButton(0, guiLeft + 120, guiTop + 75, 38, 20, "-1000")); - - buttonList.add(apply = new GuiButton(0, guiLeft + 128, guiTop + 51, 38, 20, "Accept")); - - amount = new GuiIntegerBox( - fontRendererObj, - guiLeft + 62, - guiTop + 57, - 59, - fontRendererObj.FONT_HEIGHT, - ((GT_VolumetricFlask) container.flask.getItem()).getMaxCapacity()); - amount.setEnableBackgroundDrawing(false); - amount.setMaxStringLength(16); - amount.setTextColor(16777215); - amount.setVisible(true); - amount.setFocused(true); - amount.setText("1"); - System.out.println(((GT_VolumetricFlask) container.flask.getItem()).getCapacity(container.flask)); - amount.setText(String.valueOf(((GT_VolumetricFlask) container.flask.getItem()).getCapacity(container.flask))); - } - - @Override - protected final void drawGuiContainerBackgroundLayer(float f, int x, int y) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - mc.getTextureManager().bindTexture(BACKGROUND); - drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); - - try { - Long.parseLong(amount.getText()); - apply.enabled = (amount.getText().length() > 0); - } catch (NumberFormatException e) { - apply.enabled = false; - } - - amount.drawTextBox(); - } - - @Override - protected void keyTyped(char character, int key) { - if (!checkHotbarKeys(key)) { - if (key == 28) actionPerformed(apply); - if (((key == 211) - || (key == 205) - || (key == 203) - || (key == 14) - || (character == '-') - || (Character.isDigit(character))) - && (amount.textboxKeyTyped(character, key))) { - try { - String out = amount.getText(); - boolean fixed = false; - while ((out.startsWith("0")) && (out.length() > 1)) { - out = out.substring(1); - fixed = true; - } - if (fixed) { - amount.setText(out); - } - if (out.isEmpty()) { - out = "0"; - } - long result = Long.parseLong(out); - if (result < 0L) { - amount.setText("1"); - } - - } catch (NumberFormatException ignored) { - } - } else { - super.keyTyped(character, key); - } - } - } - - @Override - protected void actionPerformed(GuiButton btn) { - try { - if (btn == apply) { - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("cap", Integer.parseInt(amount.getText())); - GT_Values.NW.sendToServer(new GT_Packet_UpdateItem(tag)); - mc.thePlayer.closeScreen(); - } - - } catch (NumberFormatException e) { - amount.setText("1"); - } - - boolean isPlus = (btn == plus1) || (btn == plus10) || (btn == plus100) || (btn == plus1000); - boolean isMinus = (btn == minus1) || (btn == minus10) || (btn == minus100) || (btn == minus1000); - - if ((isPlus) || (isMinus)) { - addQty(getQty(btn)); - } - } - - private void addQty(int i) { - try { - String out = amount.getText(); - - boolean fixed = false; - while ((out.startsWith("0")) && (out.length() > 1)) { - out = out.substring(1); - fixed = true; - } - - if (fixed) { - amount.setText(out); - } - if (out.isEmpty()) { - out = "0"; - } - long result = Integer.parseInt(out); - - if ((result == 1L) && (i > 1)) { - result = 0L; - } - result += i; - if (result < 1L) { - result = 1L; - } - out = Long.toString(result); - Integer.parseInt(out); - amount.setText(out); - } catch (NumberFormatException ignored) { - } - } - - protected int getQty(GuiButton btn) { - try { - DecimalFormat df = new DecimalFormat("+#;-#"); - return df.parse(btn.displayString).intValue(); - } catch (ParseException ignored) { - } - - return 0; - } - - public class GuiIntegerBox extends GuiTextField { - private final int maxValue; - - public GuiIntegerBox(FontRenderer fontRenderer, int x, int y, int width, int height) { - this(fontRenderer, x, y, width, height, Integer.MAX_VALUE); - } - - public GuiIntegerBox(FontRenderer fontRenderer, int x, int y, int width, int height, int maxValue) { - super(fontRenderer, x, y, width, height); - this.maxValue = maxValue; - } - - @Override - public void writeText(String selectedText) { - String original = getText(); - super.writeText(selectedText); - - try { - int i = Integer.parseInt(getText()); - if (i > maxValue) { - setText(String.valueOf(maxValue)); - } else if (i < 0) { - setText("0"); - } - } catch (NumberFormatException e) { - setText(original); - } - } - - @Override - public void setText(String s) { - try { - int i = Integer.parseInt(s); - if (i > maxValue) { - s = String.valueOf(maxValue); - } else if (i < 0) { - s = "0"; - } - } catch (NumberFormatException e) { - s = String.valueOf(maxValue); - } - super.setText(s); - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_AdvDebugStructureWriter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_AdvDebugStructureWriter.java deleted file mode 100644 index 3ae07cef8e..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_AdvDebugStructureWriter.java +++ /dev/null @@ -1,76 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; -import static net.minecraft.util.StatCollector.translateToLocal; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.gui.widgets.GT_GuiSlotTooltip; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_AdvDebugStructureWriter extends GT_GUIContainerMetaTile_Machine { - - private static final String ADVDEBUGSTRUCTUREWRITER_PRINT_TOOLTIP = - "GT5U.machines.advdebugstructurewriter.gui.print.tooltip"; - private static final String ADVDEBUGSTRUCTUREWRITER_TRANSPOSE_TOOLTIP = - "GT5U.machines.advdebugstructurewriter.gui.transpose.tooltip"; - private static final String ADVDEBUGSTRUCTUREWRITER_HIGHLIGHT_TOOLTIP = - "GT5U.machines.advdebugstructurewriter.gui.highlight.tooltip"; - - public GT_GUIContainer_AdvDebugStructureWriter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super( - new GT_Container_AdvDebugStructureWriter(aInventoryPlayer, aTileEntity), - RES_PATH_GUI + "AdvDebugStructureWriter.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int par1, int par2) { - if (mContainer != null) { - GT_Container_AdvDebugStructureWriter dsw = (GT_Container_AdvDebugStructureWriter) mContainer; - if (dsw.numbers == null) { - return; - } - fontRendererObj.drawString( - translateToLocal("GT5U.machines.advdebugstructurewriter.gui.origin"), 46, 8, 16448255); - fontRendererObj.drawString("A: " + dsw.numbers[0], 46, 18, 16448255); - fontRendererObj.drawString("B: " + dsw.numbers[1], 46, 26, 16448255); - fontRendererObj.drawString("C: " + dsw.numbers[2], 46, 34, 16448255); - - fontRendererObj.drawString( - translateToLocal("GT5U.machines.advdebugstructurewriter.gui.size"), 46, 60, 16448255); - fontRendererObj.drawString("A: " + dsw.numbers[3], 46, 70, 16448255); - fontRendererObj.drawString("B: " + dsw.numbers[4], 46, 78, 16448255); - fontRendererObj.drawString("C: " + dsw.numbers[5], 46, 86, 16448255); - } - } - - @Override - protected void setupTooltips() { - addToolTip(new GT_GuiSlotTooltip( - getContainer().printSlot, mTooltipCache.getData(ADVDEBUGSTRUCTUREWRITER_PRINT_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().transposeSlot, mTooltipCache.getData(ADVDEBUGSTRUCTUREWRITER_TRANSPOSE_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().highlightSlot, mTooltipCache.getData(ADVDEBUGSTRUCTUREWRITER_HIGHLIGHT_TOOLTIP))); - } - - private GT_Container_AdvDebugStructureWriter getContainer() { - return ((GT_Container_AdvDebugStructureWriter) this.mContainer); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { - super.drawGuiContainerBackgroundLayer(par1, par2, par3); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - if (mContainer != null) { - if (((GT_Container_AdvDebugStructureWriter) mContainer).transpose) { - drawTexturedModalRect(x + 32, y + 128, 176, 0, 18, 18); - } - if (((GT_Container_AdvDebugStructureWriter) mContainer).showHighlightBox) { - drawTexturedModalRect(x + 53, y + 128, 176, 18, 18, 18); - } - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_Boiler.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_Boiler.java deleted file mode 100644 index ef7ed15720..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_Boiler.java +++ /dev/null @@ -1,46 +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_Boiler extends GT_GUIContainerMetaTile_Machine { - - private final int textColor = this.getTextColorOrDefault("title", 0x404040); - - public GT_GUIContainer_Boiler( - InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aTextureName) { - super(new GT_Container_Boiler(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/" + aTextureName); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString("Boiler", 8, 4, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - if (this.mContainer != null) { - int tScale = ((GT_Container_Boiler) this.mContainer).mSteamAmount; - if (tScale > 0) { - drawTexturedModalRect(x + 70, y + 25 + 54 - tScale, 194, 54 - tScale, 10, tScale); - } - tScale = ((GT_Container_Boiler) this.mContainer).mWaterAmount; - if (tScale > 0) { - drawTexturedModalRect(x + 83, y + 25 + 54 - tScale, 204, 54 - tScale, 10, tScale); - } - tScale = ((GT_Container_Boiler) this.mContainer).mTemperature; - if (tScale > 0) { - drawTexturedModalRect(x + 96, y + 25 + 54 - tScale, 214, 54 - tScale, 10, tScale); - } - tScale = ((GT_Container_Boiler) this.mContainer).mProcessingEnergy; - if (tScale > 0) { - drawTexturedModalRect(x + 117, y + 44 + 14 - tScale, 177, 14 - tScale, 15, tScale + 1); - } - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_BronzeBlastFurnace.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_BronzeBlastFurnace.java deleted file mode 100644 index b92f7e9243..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_BronzeBlastFurnace.java +++ /dev/null @@ -1,47 +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_BronzeBlastFurnace extends GT_GUIContainerMetaTile_Machine { - - private final int textColor = this.getTextColorOrDefault("title", 0x404040); - - public GT_GUIContainer_BronzeBlastFurnace(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super( - new GT_Container_BronzeBlastFurnace(aInventoryPlayer, aTileEntity), - "gregtech:textures/gui/BronzeBlastFurnace.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString("Bronze Blast Furnace", 8, 4, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - if ((this.mContainer != null) && (this.mContainer.mProgressTime > 0)) { - drawTexturedModalRect( - x + 58, - y + 28, - 176, - 0, - Math.max( - 0, - Math.min( - 20, - (this.mContainer.mProgressTime > 0 ? 1 : 0) - + this.mContainer.mProgressTime - * 20 - / (this.mContainer.mMaxProgressTime < 1 - ? 1 - : this.mContainer.mMaxProgressTime))), - 11); - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_ChestBuffer.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_ChestBuffer.java deleted file mode 100644 index 2f993140ac..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_ChestBuffer.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_ChestBuffer extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_ChestBuffer(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_ChestBuffer(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/ChestBuffer.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_Filter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_Filter.java deleted file mode 100644 index 2ad3ea3018..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_Filter.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_Filter extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_Filter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_Filter(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/Filter.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_FusionReactor.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_FusionReactor.java deleted file mode 100644 index 87e035c61a..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_FusionReactor.java +++ /dev/null @@ -1,96 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.gui.GT_Container_MultiMachine; -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import gregtech.nei.NEI_TransferRectHost; -import java.awt.Rectangle; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_FusionReactor extends GT_GUIContainerMetaTile_Machine implements NEI_TransferRectHost { - - public String mNEI; - String mName = ""; - - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("title", 0xFAFAFF), - textColorValue = this.getTextColorOrDefault("value", 0xFF0000); - - public GT_GUIContainer_FusionReactor( - InventoryPlayer aInventoryPlayer, - IGregTechTileEntity aTileEntity, - String aName, - String aTextureFile, - String aNEI) { - super( - new GT_Container_MultiMachine(aInventoryPlayer, aTileEntity, false), - RES_PATH_GUI + "multimachines/" + (aTextureFile == null ? "MultiblockDisplay" : aTextureFile)); - mName = aName; - mNEI = aNEI; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString(mName, 8, -10, textColorTitle); - - if (mContainer != null) { - if ((mContainer.mDisplayErrorCode & 64) != 0) - fontRendererObj.drawString("Incomplete Structure.", 10, 8, textColor); - - if (mContainer.mDisplayErrorCode == 0) { - if (mContainer.mActive == 0) { - fontRendererObj.drawString( - "Hit with Soft Mallet to (re-)start the Machine if it doesn't start.", -70, 170, textColor); - } else { - fontRendererObj.drawString("Running perfectly.", 10, 170, textColor); - } - } - if (this.mContainer.mEnergy > 160000000 && this.mContainer.mEnergy < 160010000) - fontRendererObj.drawString("160,000,000 EU", 50, 155, textColorValue); - else if (this.mContainer.mEnergy > 320000000 && this.mContainer.mEnergy < 320010000) - fontRendererObj.drawString("320,000,000 EU", 50, 155, textColorValue); - else if (this.mContainer.mEnergy > 640000000 && this.mContainer.mEnergy < 640010000) - fontRendererObj.drawString("640,000,000 EU", 50, 155, textColorValue); - else if (this.mContainer.mEnergyLong > 5120000000L && this.mContainer.mEnergyLong < 5120080000L) - fontRendererObj.drawString("5,120,000,000 EU", 50, 155, textColorValue); - else - fontRendererObj.drawString( - GT_Utility.formatNumbers(this.mContainer.mEnergyLong) + " EU", 50, 155, textColorValue); - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - if (this.mContainer != null) { - double tScale = (double) this.mContainer.mEnergyLong / (double) this.mContainer.mStorageLong; - drawTexturedModalRect(x + 5, y + 156, 0, 251, Math.min(147, (int) (tScale * 148)), 5); - } - } - - @Override - public String getNeiTransferRectString() { - return mNEI; - } - - @Override - public String getNeiTransferRectTooltip() { - return "Recipes"; - } - - @Override - public Object[] getNeiTransferRectArgs() { - return new Object[0]; - } - - @Override - public Rectangle getNeiTransferRect() { - return new Rectangle(149, -7, 18, 18); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java deleted file mode 100644 index 015e9f74a5..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_IndustrialApiary.java +++ /dev/null @@ -1,174 +0,0 @@ -package gregtech.common.gui; - -import forestry.api.apiculture.*; -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.gui.widgets.GT_GuiSlotTooltip; -import gregtech.api.gui.widgets.GT_GuiTooltip; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_TooltipDataCache; -import gregtech.api.util.GT_Utility; -import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_IndustrialApiary; -import java.awt.*; -import java.util.ArrayList; -import java.util.Arrays; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; - -public class GT_GUIContainer_IndustrialApiary extends GT_GUIContainerMetaTile_Machine { - - private static final String BATTERY_SLOT_TOOLTIP = "GT5U.machines.battery_slot.tooltip", - UNUSED_SLOT_TOOLTIP = "GT5U.machines.unused_slot.tooltip", - STALLED_STUTTERING_TOOLTIP = "GT5U.machines.stalled_stuttering.tooltip", - ITEM_TRANSFER_TOOLTIP = "GT5U.machines.item_transfer.tooltip", - POWER_SOURCE_POWER = "GT5U.machines.powersource.power", - CANCEL_PROCESS_TOOLTIP = "GT5U.machines.industrialapiary.cancel.tooltip", - SPEED_TOOLTIP = "GT5U.machines.industrialapiary.speed.tooltip", - SPEED_LOCKED_TOOLTIP = "GT5U.machines.industrialapiary.speedlocked.tooltip", - INFO_TOOLTIP = "GT5U.machines.industrialapiary.info.tooltip", - INFO_WITH_BEE_TOOLTIP = "GT5U.machines.industrialapiary.infoextended.tooltip", - UPGRADE_TOOLTIP = "GT5U.machines.industrialapiary.upgradeslot.tooltip"; - private final int textColor = this.getTextColorOrDefault("text", 0x404040), - textColorTitle = this.getTextColorOrDefault("title", 0x404040), - textColorValue = this.getTextColorOrDefault("value", 0x404040); - - GT_GuiTooltip mErrorStatesTooltip; - GT_GuiTooltip mSpeedToggleTooltip; - GT_GuiTooltip mInfoTooltip; - - public GT_GUIContainer_IndustrialApiary(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super( - new GT_Container_IndustrialApiary(aInventoryPlayer, aTileEntity), - "gregtech:textures/gui/basicmachines/IndustrialApiary.png"); - } - - @Override - protected void setupTooltips() { - Rectangle tBeeProblemArea = new Rectangle(this.guiLeft + 100, this.guiTop + 63, 18, 18); - addToolTip( - mErrorStatesTooltip = new GT_GuiTooltip(tBeeProblemArea, "") { - @Override - protected void onTick() { - boolean e = this.enabled; - super.onTick(); - this.enabled = e; - } - }); - addToolTip( - mSpeedToggleTooltip = new GT_GuiSlotTooltip( - getContainer().slotSpeedToggle, new GT_TooltipDataCache.TooltipData(null, null))); - mErrorStatesTooltip.enabled = false; - addToolTip(mInfoTooltip = new GT_GuiTooltip(new Rectangle(this.guiLeft + 163, guiTop + 5, 6, 17))); - - addToolTip( - new GT_GuiSlotTooltip(getContainer().slotCancelProcess, mTooltipCache.getData(CANCEL_PROCESS_TOOLTIP))); - getContainer() - .slotUpgrade - .forEach(s -> addToolTip(new GT_GuiSlotTooltip(s, mTooltipCache.getData(UPGRADE_TOOLTIP)))); - - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotItemTransferToggle, mTooltipCache.getData(ITEM_TRANSFER_TOOLTIP))); - addToolTip(new GT_GuiSlotTooltip( - getContainer().slotBattery, - mTooltipCache.getData( - BATTERY_SLOT_TOOLTIP, powerTierName(getContainer().getMachine().mTier), powerTierName((byte) - (getContainer().getMachine().mTier + 1))))); - addToolTip(new GT_GuiSlotTooltip(getContainer().slotSpecial, mTooltipCache.getData(UNUSED_SLOT_TOOLTIP))); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float parTicks) { - mErrorStatesTooltip.enabled = !getContainer().mErrorStates.isEmpty(); - if (mErrorStatesTooltip.enabled) { - mErrorStatesTooltip.setToolTipText( - new GT_TooltipDataCache.TooltipData(getContainer().mErrorStates, getContainer().mErrorStates)); - } else if (getContainer().mStuttering) { - mErrorStatesTooltip.enabled = true; - mErrorStatesTooltip.setToolTipText(mTooltipCache.getData( - STALLED_STUTTERING_TOOLTIP, StatCollector.translateToLocal(POWER_SOURCE_POWER))); - } - int accelerated = (1 << getContainer().mSpeed); - int energyusage = 0; - if (accelerated == 2) energyusage = 32; - else if (accelerated > 2) energyusage = 32 * accelerated << (getContainer().mSpeed - 2); - mSpeedToggleTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData( - getContainer().mLockedSpeed ? SPEED_LOCKED_TOOLTIP : SPEED_TOOLTIP, - accelerated, - GT_Utility.formatNumbers(energyusage))); - ArrayList<String> s = new ArrayList<>(); - GT_MetaTileEntity_IndustrialApiary IA = getContainer().getMachine(); - - String energyreq = GT_Utility.formatNumbers( - (int) ((float) GT_MetaTileEntity_IndustrialApiary.baseEUtUsage * IA.getEnergyModifier() * accelerated) - + energyusage); - String Temp = StatCollector.translateToLocal(IA.getTemperature().getName()); - String Hum = StatCollector.translateToLocal(IA.getHumidity().getName()); - boolean moreinformationgiven = false; - if (IA.getUsedQueen() != null && BeeManager.beeRoot.isMember(IA.getUsedQueen(), EnumBeeType.QUEEN.ordinal())) { - IBee bee = BeeManager.beeRoot.getMember(IA.getUsedQueen()); - if (bee.isAnalyzed()) { - moreinformationgiven = true; - IBeeGenome genome = bee.getGenome(); - IBeeModifier mod = - BeeManager.beeRoot.getBeekeepingMode(IA.getWorld()).getBeeModifier(); - float tmod = IA.getTerritoryModifier(null, 1f) * mod.getTerritoryModifier(null, 1f); - int[] t = Arrays.stream(genome.getTerritory()) - .map(i -> (int) ((float) i * tmod)) - .toArray(); - mInfoTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData( - INFO_WITH_BEE_TOOLTIP, - energyreq, - Temp, - Hum, - genome.getSpeed(), - IA.getProductionModifier(null, 1f) * mod.getProductionModifier(null, 1f), - Math.round(IA.getFloweringModifier(null, 1f) - * genome.getFlowering() - * mod.getFloweringModifier(null, 1f)), - Math.round(IA.getLifespanModifier(null, null, 1f) - * genome.getLifespan() - * mod.getLifespanModifier(null, null, 1f)), - t[0], - t[1], - t[2])); - } - } - if (!moreinformationgiven) - mInfoTooltip.setToolTipText(mTooltipCache.getUncachedTooltipData(INFO_TOOLTIP, energyreq, Temp, Hum)); - - super.drawScreen(mouseX, mouseY, parTicks); - } - - @Override - protected void drawGuiContainerForegroundLayer(int par1, int par2) { - this.fontRendererObj.drawString("Ind. Apiary", 8, 4, textColorTitle); - this.fontRendererObj.drawString("x", 30, 63, textColor); - this.fontRendererObj.drawString((1 << getContainer().mSpeed) + "", 26, 72, textColorValue); - } - - @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); - if (this.mContainer != null) { - if (getContainer().mItemTransfer) drawTexturedModalRect(x + 7, y + 62, 176, 18, 18, 18); - if (getContainer().mMaxProgressTime > 0) { - double p = (double) getContainer().mProgressTime / getContainer().mMaxProgressTime; - drawTexturedModalRect(x + 70, y + 3, 176, 0, (int) (p * 20), 18); - } - if (mErrorStatesTooltip.enabled) - drawTexturedModalRect(x + 100, y + 63, 176, 36, getContainer().mStuttering ? 18 : 9, 18); - } - } - - private GT_Container_IndustrialApiary getContainer() { - return ((GT_Container_IndustrialApiary) this.mContainer); - } - - // taken from GT_GUIContainer_BasicMachine - private String powerTierName(byte machineTier) { - return GT_Values.TIER_COLORS[machineTier] + GT_Values.VN[machineTier]; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java deleted file mode 100644 index 9b19da6367..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_InputBus_ME.java +++ /dev/null @@ -1,77 +0,0 @@ -package gregtech.common.gui; - -import appeng.client.render.AppEngRenderItem; -import appeng.core.AELog; -import appeng.integration.IntegrationRegistry; -import appeng.integration.IntegrationType; -import appeng.integration.abstraction.INEI; -import appeng.util.Platform; -import cpw.mods.fml.common.Optional; -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.gui.GT_Slot_Holo_ME; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.entity.RenderItem; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Slot; - -public class GT_GUIContainer_InputBus_ME extends GT_GUIContainerMetaTile_Machine { - - private final AppEngRenderItem aeRenderItem = new AppEngRenderItem(); - - public GT_GUIContainer_InputBus_ME(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_InputBus_ME(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/InputBusME.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - } - - // base method is made public by AE2 ASM - public void func_146977_a(final Slot s) { - this.drawSlot(s); - } - - @Optional.Method(modid = "appliedenergistics2") - private RenderItem setItemRender(final RenderItem item) { - if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.NEI)) { - return ((INEI) IntegrationRegistry.INSTANCE.getInstance(IntegrationType.NEI)).setItemRender(item); - } else { - final RenderItem ri = itemRender; - itemRender = item; - return ri; - } - } - - @Optional.Method(modid = "appliedenergistics2") - private void drawSlot(final Slot s) { - if (s instanceof GT_Slot_Holo_ME) { - final RenderItem pIR = this.setItemRender(this.aeRenderItem); - try { - this.zLevel = 0.0F; - itemRender.zLevel = 0.0F; - this.aeRenderItem.setAeStack(Platform.getAEStackInSlot(s)); - this.safeDrawSlot(s); - } catch (final Exception err) { - AELog.warn("[AppEng] AE prevented crash while drawing slot: " + err.toString()); - } - this.setItemRender(pIR); - return; - } - safeDrawSlot(s); - } - - @Optional.Method(modid = "appliedenergistics2") - private void safeDrawSlot(final Slot s) { - try { - GuiContainer.class - .getDeclaredMethod("func_146977_a_original", Slot.class) - .invoke(this, s); - } catch (final Exception ignored) { - } - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_ItemDistributor.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_ItemDistributor.java deleted file mode 100644 index 2c8fa870a1..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_ItemDistributor.java +++ /dev/null @@ -1,21 +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_ItemDistributor extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_ItemDistributor(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super( - new GT_Container_ItemDistributor(aInventoryPlayer, aTileEntity), - "gregtech:textures/gui/ItemDistributor.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_MicrowaveEnergyTransmitter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_MicrowaveEnergyTransmitter.java deleted file mode 100644 index 7b0b840276..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_MicrowaveEnergyTransmitter.java +++ /dev/null @@ -1,75 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_MicrowaveEnergyTransmitter extends GT_GUIContainerMetaTile_Machine { - - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("title", 0xFAFAFF); - - public GT_GUIContainer_MicrowaveEnergyTransmitter( - InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super( - new GT_Container_MicrowaveEnergyTransmitter(aInventoryPlayer, aTileEntity), - RES_PATH_GUI + "Teleporter.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString("Teleporter", 46, 8, textColorTitle); - if (this.mContainer != null) { - this.fontRendererObj.drawString( - "X: " - + GT_Utility.parseNumberToString( - ((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mTargetX), - 46, - 16, - textColor); - this.fontRendererObj.drawString( - "Y: " - + GT_Utility.parseNumberToString( - ((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mTargetY), - 46, - 24, - textColor); - this.fontRendererObj.drawString( - "Z: " - + GT_Utility.parseNumberToString( - ((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mTargetZ), - 46, - 32, - textColor); - if (((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mEgg > 0) { - this.fontRendererObj.drawString( - "Dim: " - + GT_Utility.parseNumberToString( - ((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mTargetD), - 46, - 40, - textColor); - this.fontRendererObj.drawString( - "Dim Valid: " - + (GT_Utility.isRealDimension( - ((GT_Container_MicrowaveEnergyTransmitter) this.mContainer).mTargetD) - ? "Yes" - : "No"), - 46, - 48, - textColor); - } - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_OutputHatch.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java deleted file mode 100644 index ab00d16291..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java +++ /dev/null @@ -1,75 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.IDragAndDropSupport; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.net.GT_Packet_SetLockedFluid; -import gregtech.api.util.GT_Utility; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; -import net.minecraftforge.fluids.FluidStack; - -public class GT_GUIContainer_OutputHatch extends GT_GUIContainerMetaTile_Machine implements IDragAndDropSupport { - - private final String mName; - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("title", 0x404040), - textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); - - public GT_GUIContainer_OutputHatch( - InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { - super(new GT_Container_OutputHatch(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "OutputHatch.png"); - mName = aName; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString( - StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorTitle); - fontRendererObj.drawString(mName, 8, 6, textColorTitle); - if (mContainer != null) { - fontRendererObj.drawString("Liquid Amount", 10, 20, textColor); - fontRendererObj.drawString( - GT_Utility.parseNumberToString(((GT_Container_OutputHatch) mContainer).mContent), - 10, - 30, - textColorValue); - fontRendererObj.drawString("Locked Fluid", 101, 20, textColor); - ItemStack tLockedDisplayStack = - (ItemStack) mContainer.getInventory().get(3); - String fluidName = tLockedDisplayStack == null ? "None" : tLockedDisplayStack.getDisplayName(); - fontRendererObj.drawString(fluidName, 101, 30, textColorValue); - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - } - - @Override - public boolean handleDragAndDropGT( - GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button, boolean isGhost) { - if (isGhost - && gui instanceof GT_GUIContainer_OutputHatch - && ((GT_GUIContainer_OutputHatch) gui).isMouseOverSlot(3, mousex, mousey)) { - // the instanceof check should be unnecessary, but we will do it regardless, just in case. - FluidStack tFluidStack = GT_Utility.getFluidFromContainerOrFluidDisplay(draggedStack); - if (tFluidStack != null) { - GT_Values.NW.sendToServer(new GT_Packet_SetLockedFluid( - ((GT_GUIContainer_OutputHatch) gui).mContainer.mTileEntity, tFluidStack)); - draggedStack.stackSize = 0; - return true; - } - } - return false; - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java deleted file mode 100644 index 060b93674a..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_PrimitiveBlastFurnace.java +++ /dev/null @@ -1,81 +0,0 @@ -package gregtech.common.gui; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.gui.widgets.GT_GuiIcon; -import gregtech.api.gui.widgets.GT_GuiTabLine.GT_GuiTabIconSet; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.nei.NEI_TransferRectHost; -import java.awt.*; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_PrimitiveBlastFurnace extends GT_GUIContainerMetaTile_Machine - implements NEI_TransferRectHost { - private String name; - public String mNEI; - private static final GT_GuiTabIconSet TAB_ICONSET = new GT_GuiTabIconSet( - GT_GuiIcon.TAB_NORMAL_BRICK, GT_GuiIcon.TAB_HIGHLIGHT_BRICK, GT_GuiIcon.TAB_DISABLED_BRICK); - private final int textColor = this.getTextColorOrDefault("title", 0x404040); - - public GT_GUIContainer_PrimitiveBlastFurnace( - InventoryPlayer inventoryPlayer, IGregTechTileEntity tileEntity, String name, String aNEI) { - super( - new GT_Container_PrimitiveBlastFurnace(inventoryPlayer, tileEntity), - String.format("gregtech:textures/gui/%s.png", name.replace(" ", ""))); - this.name = name; - this.mNEI = aNEI; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString(name, 8, 4, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - if ((this.mContainer != null) && (this.mContainer.mProgressTime > 0)) { - drawTexturedModalRect( - x + 58, - y + 28, - 176, - 0, - Math.max( - 0, - Math.min( - 20, - (1) - + this.mContainer.mProgressTime - * 20 - / (Math.max(this.mContainer.mMaxProgressTime, 1)))), - 11); - } - } - - @Override - protected GT_GuiTabIconSet getTabBackground() { - return TAB_ICONSET; - } - - @Override - public String getNeiTransferRectString() { - return mNEI; - } - - @Override - public String getNeiTransferRectTooltip() { - return "Recipes"; - } - - @Override - public Object[] getNeiTransferRectArgs() { - return new Object[0]; - } - - @Override - public Rectangle getNeiTransferRect() { - return new Rectangle(51, 10, 24, 24); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_QuantumChest.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_QuantumChest.java deleted file mode 100644 index 530e48e550..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_QuantumChest.java +++ /dev/null @@ -1,46 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; - -public class GT_GUIContainer_QuantumChest extends GT_GUIContainerMetaTile_Machine { - - private final String mName; - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("title", 0x404040), - textColorValue = this.getTextColorOrDefault("value", 0xFAFAFF); - - public GT_GUIContainer_QuantumChest( - InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName) { - super(new GT_Container_QuantumChest(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "BasicTank.png"); - mName = aName; - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - fontRendererObj.drawString( - StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, textColorTitle); - fontRendererObj.drawString(mName, 8, 6, textColorTitle); - if (mContainer != null) { - fontRendererObj.drawString("Item Amount", 10, 20, textColor); - fontRendererObj.drawString( - GT_Utility.parseNumberToString(((GT_Container_QuantumChest) mContainer).mContent), - 10, - 30, - textColorValue); - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - int x = (width - xSize) / 2; - int y = (height - ySize) / 2; - drawTexturedModalRect(x, y, 0, 0, xSize, ySize); - } -} diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java deleted file mode 100644 index 8bfc2c0944..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_RecipeFilter.java +++ /dev/null @@ -1,23 +0,0 @@ -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_Regulator.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_Regulator.java deleted file mode 100644 index c3d579e58c..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_Regulator.java +++ /dev/null @@ -1,44 +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_Regulator extends GT_GUIContainerMetaTile_Machine { - - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF); - - public GT_GUIContainer_Regulator(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_Regulator(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/Regulator.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[0]), 120, 9, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[1]), 137, 9, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[2]), 155, 9, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[3]), 120, 26, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[4]), 137, 26, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[5]), 155, 26, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[6]), 120, 43, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[7]), 137, 43, textColor); - this.fontRendererObj.drawString( - String.valueOf(((GT_Container_Regulator) this.mContainer).mTargetSlots[8]), 155, 43, textColor); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_SuperBuffer.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_SuperBuffer.java deleted file mode 100644 index e7b7730d75..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_SuperBuffer.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_SuperBuffer extends GT_GUIContainerMetaTile_Machine { - public GT_GUIContainer_SuperBuffer(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_SuperBuffer(aInventoryPlayer, aTileEntity), "gregtech:textures/gui/SuperBuffer.png"); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/GT_GUIContainer_Teleporter.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_Teleporter.java deleted file mode 100644 index a5e035b4ff..0000000000 --- a/src/main/java/gregtech/common/gui/GT_GUIContainer_Teleporter.java +++ /dev/null @@ -1,63 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.enums.GT_Values.RES_PATH_GUI; - -import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; - -public class GT_GUIContainer_Teleporter extends GT_GUIContainerMetaTile_Machine { - - private final int textColor = this.getTextColorOrDefault("text", 0xFAFAFF), - textColorTitle = this.getTextColorOrDefault("text", 0xFAFAFF); - - public GT_GUIContainer_Teleporter(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) { - super(new GT_Container_Teleporter(aInventoryPlayer, aTileEntity), RES_PATH_GUI + "Teleporter.png"); - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - this.fontRendererObj.drawString("Teleporter", 46, 8, textColorTitle); - if (this.mContainer != null) { - this.fontRendererObj.drawString( - "X: " + GT_Utility.parseNumberToString(((GT_Container_Teleporter) this.mContainer).mTargetX), - 46, - 16, - textColor); - this.fontRendererObj.drawString( - "Y: " + GT_Utility.parseNumberToString(((GT_Container_Teleporter) this.mContainer).mTargetY), - 46, - 24, - textColor); - this.fontRendererObj.drawString( - "Z: " + GT_Utility.parseNumberToString(((GT_Container_Teleporter) this.mContainer).mTargetZ), - 46, - 32, - textColor); - if (((GT_Container_Teleporter) this.mContainer).mEgg > 0) { - this.fontRendererObj.drawString( - "Dim: " + GT_Utility.parseNumberToString(((GT_Container_Teleporter) this.mContainer).mTargetD), - 46, - 40, - textColor); - this.fontRendererObj.drawString( - "Dim Valid: " - + (GT_Utility.isRealDimension(((GT_Container_Teleporter) this.mContainer).mTargetD) - ? "Yes" - : "No"), - 46, - 48, - textColor); - } - } - } - - @Override - protected void drawGuiContainerBackgroundLayer(float parTicks, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(parTicks, mouseX, mouseY); - 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/gui/modularui/UIHelper.java b/src/main/java/gregtech/common/gui/modularui/UIHelper.java new file mode 100644 index 0000000000..f500514258 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/UIHelper.java @@ -0,0 +1,222 @@ +package gregtech.common.gui.modularui; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.SteamTexture; +import gregtech.api.util.GT_Recipe; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +public class UIHelper { + + /** + * Iterates over candidates for slot placement. + */ + public static void forEachSlots( + ForEachSlot forEachItemInputSlot, + ForEachSlot forEachItemOutputSlot, + ForEachSlot forEachSpecialSlot, + ForEachSlot forEachFluidInputSlot, + ForEachSlot forEachFluidOutputSlot, + IDrawable itemSlotBackground, + IDrawable fluidSlotBackground, + @Nullable GT_Recipe.GT_Recipe_Map recipeMap, + int itemInputCount, + int itemOutputCount, + int fluidInputCount, + int fluidOutputCount, + SteamVariant steamVariant, + Pos2d offset) { + List<Pos2d> itemInputPositions = recipeMap != null + ? recipeMap.getItemInputPositions(itemInputCount) + : UIHelper.getItemInputPositions(itemInputCount); + itemInputPositions = itemInputPositions.stream().map(p -> p.add(offset)).collect(Collectors.toList()); + for (int i = 0; i < itemInputPositions.size(); i++) { + forEachItemInputSlot.accept( + i, + getBackgroundsForSlot(itemSlotBackground, recipeMap, false, false, i, false, steamVariant), + itemInputPositions.get(i)); + } + + List<Pos2d> itemOutputPositions = recipeMap != null + ? recipeMap.getItemOutputPositions(itemOutputCount) + : UIHelper.getItemOutputPositions(itemOutputCount); + itemOutputPositions = + itemOutputPositions.stream().map(p -> p.add(offset)).collect(Collectors.toList()); + for (int i = 0; i < itemOutputPositions.size(); i++) { + forEachItemOutputSlot.accept( + i, + getBackgroundsForSlot(itemSlotBackground, recipeMap, false, true, i, false, steamVariant), + itemOutputPositions.get(i)); + } + + forEachSpecialSlot.accept( + 0, + getBackgroundsForSlot(itemSlotBackground, recipeMap, false, false, 0, true, steamVariant), + (recipeMap != null ? recipeMap.getSpecialItemPosition() : UIHelper.getSpecialItemPosition()) + .add(offset)); + + List<Pos2d> fluidInputPositions = recipeMap != null + ? recipeMap.getFluidInputPositions(fluidInputCount) + : UIHelper.getFluidInputPositions(fluidInputCount); + fluidInputPositions = + fluidInputPositions.stream().map(p -> p.add(offset)).collect(Collectors.toList()); + for (int i = 0; i < fluidInputPositions.size(); i++) { + forEachFluidInputSlot.accept( + i, + getBackgroundsForSlot(fluidSlotBackground, recipeMap, true, false, i, false, steamVariant), + fluidInputPositions.get(i)); + } + + List<Pos2d> fluidOutputPositions = recipeMap != null + ? recipeMap.getFluidOutputPositions(fluidOutputCount) + : UIHelper.getFluidOutputPositions(fluidOutputCount); + fluidOutputPositions = + fluidOutputPositions.stream().map(p -> p.add(offset)).collect(Collectors.toList()); + for (int i = 0; i < fluidOutputPositions.size(); i++) { + forEachFluidOutputSlot.accept( + i, + getBackgroundsForSlot(fluidSlotBackground, recipeMap, true, true, i, false, steamVariant), + fluidOutputPositions.get(i)); + } + } + + /** + * @return Display positions for GUI, including border (18x18 size) + */ + public static List<Pos2d> getItemInputPositions(int itemInputCount) { + switch (itemInputCount) { + case 0: + return Collections.emptyList(); + case 1: + return getItemGridPositions(itemInputCount, 52, 24, 1, 1); + case 2: + return getItemGridPositions(itemInputCount, 34, 24, 2, 1); + case 3: + return getItemGridPositions(itemInputCount, 16, 24, 3, 1); + case 4: + case 5: + return getItemGridPositions(itemInputCount, 16, 24, 3, 2); + case 6: + return getItemGridPositions(itemInputCount, 16, 15, 3, 2); + default: + return getItemGridPositions(itemInputCount, 16, 6, 3, 3); + } + } + + /** + * @return Display positions for GUI, including border (18x18 size) + */ + public static List<Pos2d> getItemOutputPositions(int itemOutputCount) { + switch (itemOutputCount) { + case 0: + return Collections.emptyList(); + case 1: + return getItemGridPositions(itemOutputCount, 106, 24, 1, 1); + case 2: + return getItemGridPositions(itemOutputCount, 106, 24, 2, 1); + case 3: + return getItemGridPositions(itemOutputCount, 106, 24, 3, 1); + case 4: + return getItemGridPositions(itemOutputCount, 106, 15, 2, 2); + case 5: + case 6: + return getItemGridPositions(itemOutputCount, 106, 15, 3, 2); + default: + return getItemGridPositions(itemOutputCount, 106, 6, 3, 3); + } + } + + /** + * @return Display position for GUI, including border (18x18 size) + */ + public static Pos2d getSpecialItemPosition() { + return new Pos2d(124, 62); + } + + /** + * @return Display positions for GUI, including border (18x18 size) + */ + public static List<Pos2d> getFluidInputPositions(int fluidInputCount) { + List<Pos2d> results = new ArrayList<>(); + int x = 52; + for (int i = 0; i < fluidInputCount; i++) { + results.add(new Pos2d(x, 62)); + x -= 18; + } + return results; + } + + /** + * @return Display positions for GUI, including border (18x18 size) + */ + public static List<Pos2d> getFluidOutputPositions(int fluidOutputCount) { + List<Pos2d> results = new ArrayList<>(); + int x = 106; + for (int i = 0; i < fluidOutputCount; i++) { + results.add(new Pos2d(x, 62)); + x += 18; + } + return results; + } + + public static List<Pos2d> getItemGridPositions( + int itemCount, int xOrigin, int yOrigin, int xDirMaxCount, int yDirMaxCount) { + // 18 pixels to get to a new grid for placing an item tile since they are 16x16 and have 1 pixel buffers + // around them. + int distanceGrid = 18; + int xMax = xOrigin + xDirMaxCount * distanceGrid; + + List<Pos2d> results = new ArrayList<>(); + // Temp variables to keep track of current coordinates to place item at. + int xCoord = xOrigin; + int yCoord = yOrigin; + + for (int i = 0; i < itemCount; i++) { + results.add(new Pos2d(xCoord, yCoord)); + xCoord += distanceGrid; + if (xCoord == xMax) { + xCoord = xOrigin; + yCoord += distanceGrid; + } + } + + return results; + } + + private static IDrawable[] getBackgroundsForSlot( + IDrawable base, + GT_Recipe.GT_Recipe_Map recipeMap, + boolean isFluid, + boolean isOutput, + int index, + boolean isSpecial, + SteamVariant steamVariant) { + if (recipeMap != null) { + IDrawable overlay; + if (steamVariant != SteamVariant.NONE) { + SteamTexture steamTexture = recipeMap.getOverlayForSlotSteam(isFluid, isOutput, index, isSpecial); + if (steamTexture != null) { + overlay = steamTexture.get(steamVariant); + } else { + overlay = null; + } + } else { + overlay = recipeMap.getOverlayForSlot(isFluid, isOutput, index, isSpecial); + } + if (overlay != null) { + return new IDrawable[] {base, overlay}; + } + } + return new IDrawable[] {base}; + } + + @FunctionalInterface + public interface ForEachSlot { + void accept(int index, IDrawable[] backgrounds, Pos2d pos); + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java b/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java new file mode 100644 index 0000000000..c3da5cb1b4 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/uifactory/SelectItemUIFactory.java @@ -0,0 +1,221 @@ +package gregtech.common.gui.modularui.uifactory; + +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.enums.Dyes; +import gregtech.api.gui.GT_GUIColorOverride; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.util.GT_Util; +import gregtech.api.util.GT_Utility; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.function.Supplier; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; + +/** + * Creates UI for selecting item from given list. + * This is client-only UI to allow using client-preferred settings. + */ +public class SelectItemUIFactory { + + private final String header; + private final ItemStack headerItem; + public static final int UNSELECTED = -1; + private static final int cols = 9; + private final Consumer<ItemStack> selectedCallback; + // passed in stack + private final List<ItemStack> stacks; + private final boolean noDeselect; + private int selected; + private boolean anotherWindow = false; + private AtomicBoolean dialogOpened; + private int guiTint = GT_Util.getRGBInt(Dyes.MACHINE_METAL.getRGBA()); + private final ItemStackHandler currentDisplayItemHandler = new ItemStackHandler(); + private Supplier<ItemStack> currentGetter; + + private final GT_GUIColorOverride colorOverride = new GT_GUIColorOverride("SelectItemUIFactory"); + + private int getTextColorOrDefault(String textType, int defaultColor) { + return colorOverride.getTextColorOrDefault(textType, defaultColor); + } + + private final Supplier<Integer> COLOR_TITLE = () -> getTextColorOrDefault("title", 0x222222); + private final Supplier<Integer> COLOR_TEXT_GRAY = () -> getTextColorOrDefault("text_gray", 0x555555); + + public SelectItemUIFactory( + String header, ItemStack headerItem, Consumer<ItemStack> selectedCallback, List<ItemStack> stacks) { + this(header, headerItem, selectedCallback, stacks, UNSELECTED); + } + + public SelectItemUIFactory( + String header, + ItemStack headerItem, + Consumer<ItemStack> selectedCallback, + List<ItemStack> stacks, + int selected) { + this(header, headerItem, selectedCallback, stacks, selected, false); + } + + /** + * Constructor for a dialog to select an item from given list. Given callback may be called zero or more times depending on user action. + * @param header Header text + * @param headerItem ItemStack to use as Dialog icon + * @param selectedCallback callback upon selected + * @param stacks list to choose from + * @param selected preselected item. Use {@link #UNSELECTED} for unselected. Invalid selected will be clamped to 0 or highest index + * @param noDeselect true if player cannot deselect, false otherwise. If this is set to true, selectedCallback is guaranteed to be called with a nonnull stack + */ + public SelectItemUIFactory( + String header, + ItemStack headerItem, + Consumer<ItemStack> selectedCallback, + List<ItemStack> stacks, + int selected, + boolean noDeselect) { + this.header = header; + this.headerItem = headerItem; + this.selectedCallback = selectedCallback; + this.stacks = stacks; + this.noDeselect = noDeselect; + this.selected = noDeselect ? Math.max(0, selected) : selected; + this.currentDisplayItemHandler.setStackInSlot(0, getCandidate(selected)); + } + + /** + * @param anotherWindow If UI is shown on top of another window + * @param dialogOpened Flag to store whether this UI is opened and hence it should block duplicated creation of this UI + */ + public SelectItemUIFactory setAnotherWindow(boolean anotherWindow, AtomicBoolean dialogOpened) { + this.anotherWindow = anotherWindow; + this.dialogOpened = dialogOpened; + return this; + } + + public SelectItemUIFactory setGuiTint(int guiTint) { + this.guiTint = guiTint; + return this; + } + + /** + * @param currentGetter Getter for "current" item displayed that may change from external reasons + */ + public SelectItemUIFactory setCurrentGetter(Supplier<ItemStack> currentGetter) { + this.currentGetter = currentGetter; + return this; + } + + public ModularWindow createWindow(UIBuildContext buildContext) { + ModularWindow.Builder builder = + ModularWindow.builder(getGUIWidth(), 53 + 18 * ((stacks.size() - 1) / cols + 1)); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + builder.setGuiTint(guiTint); + + if (headerItem != null) { + builder.widget(new ItemDrawable(headerItem).asWidget().setPos(5, 5).setSize(16, 16)); + } + builder.widget(new TextWidget(header).setDefaultColor(COLOR_TITLE.get()).setPos(25, 9)); + + builder.widget( + new SlotWidget(BaseSlot.phantom(currentDisplayItemHandler, 0)) { + @Override + public void draw(float partialTicks) { + if (currentGetter != null) { + ItemStack current = currentGetter.get(); + currentDisplayItemHandler.setStackInSlot(0, current); + selected = GT_Utility.findMatchingStackInList(stacks, current); + } + super.draw(partialTicks); + } + }.disableInteraction() + .setBackground(GT_UITextures.SLOT_DARK_GRAY) + .setPos( + 9 + + getFontRenderer() + .getStringWidth(StatCollector.translateToLocal( + "GT5U.gui.select.current")), + 24)) + .widget(new TextWidget(StatCollector.translateToLocal("GT5U.gui.select.current")) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(8, 25 + (18 - getFontRenderer().FONT_HEIGHT) / 2)); + + for (int i = 0; i < stacks.size(); i++) { + final int index = i; + builder.widget( + new SlotWidget(new BaseSlot(new ItemStackHandler(new ItemStack[] {stacks.get(index)}), 0, true)) { + @Override + public ClickResult onClick(int buttonId, boolean doubleClick) { + if (buttonId == 0) { + setSelected(index); + } else if (buttonId == 1) { + setSelected(UNSELECTED); + } else { + return ClickResult.ACCEPT; + } + selectedCallback.accept(getCandidate(getSelected())); + return ClickResult.SUCCESS; + } + + @Override + public IDrawable[] getBackground() { + return new IDrawable[] { + index == selected ? GT_UITextures.SLOT_DARK_GRAY : ModularUITextures.ITEM_SLOT + }; + } + }.disableInteraction().setPos(7 + 18 * (index % cols), 43 + 18 * (index / cols))); + } + + if (anotherWindow) { + dialogOpened.set(true); + builder.widget( + new ButtonWidget() { + @Override + public void onDestroy() { + dialogOpened.set(false); + } + }.setOnClick((clickData, widget) -> widget.getWindow().tryClose()) + .setBackground(ModularUITextures.VANILLA_BACKGROUND, new Text("x")) + .setPos(getGUIWidth() - 15, 3) + .setSize(12, 12)); + } + + return builder.build(); + } + + public int getSelected() { + return selected; + } + + public void setSelected(int selected) { + if (selected == this.selected) return; + int newSelected = GT_Utility.clamp(selected, UNSELECTED, stacks.size() - 1); + if (noDeselect && newSelected == UNSELECTED) return; + + this.selected = newSelected; + currentDisplayItemHandler.setStackInSlot(0, getCandidate(this.selected)); + } + + private ItemStack getCandidate(int listIndex) { + return listIndex < 0 || listIndex >= stacks.size() ? null : stacks.get(listIndex); + } + + private FontRenderer getFontRenderer() { + return Minecraft.getMinecraft().fontRenderer; + } + + private int getGUIWidth() { + return 176; + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/AESlotWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/AESlotWidget.java new file mode 100644 index 0000000000..f3620d3234 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/AESlotWidget.java @@ -0,0 +1,40 @@ +package gregtech.common.gui.modularui.widget; + +import appeng.client.render.AppEngRenderItem; +import appeng.core.AELog; +import appeng.util.Platform; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.inventory.Slot; + +public class AESlotWidget extends SlotWidget { + + public AESlotWidget(BaseSlot slot) { + super(slot); + } + + @Override + @SideOnly(Side.CLIENT) + protected void drawSlot(Slot slotIn) { + final AppEngRenderItem aeRenderItem = new AppEngRenderItem(); + final RenderItem pIR = this.setItemRender(aeRenderItem); + try { + aeRenderItem.setAeStack(Platform.getAEStackInSlot(slotIn)); + super.drawSlot(slotIn, false); + } catch (final Exception err) { + AELog.warn("[AppEng] AE prevented crash while drawing slot: " + err); + } + this.setItemRender(pIR); + } + + @SideOnly(Side.CLIENT) + private RenderItem setItemRender(final RenderItem item) { + final RenderItem ri = ModularGui.getItemRenderer(); + ModularGui.setItemRenderer(item); + return ri; + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverCycleButtonWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverCycleButtonWidget.java new file mode 100644 index 0000000000..599ed28a5f --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverCycleButtonWidget.java @@ -0,0 +1,89 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.gui.modularui.GT_UITextures; +import org.lwjgl.opengl.GL11; + +/** + * Fires click action on mouse release, not on press. + * Draws different backgrounds depending on whether the mouse is being pressed or the widget is hovered. + */ +public class CoverCycleButtonWidget extends CycleButtonWidget { + + private static final UITexture BUTTON_NORMAL_NOT_PRESSED = + GT_UITextures.BUTTON_COVER_NORMAL.getSubArea(0, 0, 1, 0.5f); + private static final UITexture BUTTON_NORMAL_PRESSED = GT_UITextures.BUTTON_COVER_NORMAL.getSubArea(0, 0.5f, 1, 1); + private static final UITexture BUTTON_HOVERED_NOT_PRESSED = + GT_UITextures.BUTTON_COVER_NORMAL_HOVERED.getSubArea(0, 0, 1, 0.5f); + private static final UITexture BUTTON_HOVERED_PRESSED = + GT_UITextures.BUTTON_COVER_NORMAL_HOVERED.getSubArea(0, 0.5f, 1, 1); + + private boolean clickPressed; + + private static final int TOOLTIP_DELAY = 5; + + public CoverCycleButtonWidget() { + setSize(16, 16); + setTooltipShowUpDelay(TOOLTIP_DELAY); + } + + @Override + public ClickResult onClick(int buttonId, boolean doubleClick) { + updateState(); + if (!canClick()) return ClickResult.REJECT; + clickPressed = true; + return ClickResult.SUCCESS; + } + + @Override + public boolean onClickReleased(int buttonId) { + clickPressed = false; + updateState(); + if (!isHovering() || !canClick()) return false; + return onClickImpl(buttonId); + } + + protected boolean onClickImpl(int buttonId) { + super.onClick(buttonId, false); + return true; + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + protected boolean canClick() { + return true; + } + + @SideOnly(Side.CLIENT) + protected void updateState() {} + + public boolean isClickPressed() { + return clickPressed; + } + + @Override + public void drawBackground(float partialTicks) { + GL11.glColor4f(1, 1, 1, 1); + super.drawBackground(partialTicks); + } + + @Override + public IDrawable[] getBackground() { + if (isHovering()) { + if (clickPressed) { + return new IDrawable[] {BUTTON_HOVERED_PRESSED}; + } else { + return new IDrawable[] {BUTTON_HOVERED_NOT_PRESSED}; + } + } else { + if (clickPressed) { + return new IDrawable[] {BUTTON_NORMAL_PRESSED}; + } else { + return new IDrawable[] {BUTTON_NORMAL_NOT_PRESSED}; + } + } + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverDataControllerWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataControllerWidget.java new file mode 100644 index 0000000000..d28117054a --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataControllerWidget.java @@ -0,0 +1,138 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.GT_CoverBehaviorBase; +import gregtech.api.util.ISerializableObject; +import java.io.IOException; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +import net.minecraft.network.PacketBuffer; + +public class CoverDataControllerWidget<T extends ISerializableObject> extends DataControllerWidget<T> { + + protected final GT_CoverBehaviorBase<T> coverBehavior; + + /** + * @param dataGetter () -> cover data this widget handles + * @param dataSetter data to set -> if setting cover data is successful + * @param coverBehavior cover this widget handles data update + */ + public CoverDataControllerWidget( + Supplier<T> dataGetter, Function<T, Boolean> dataSetter, GT_CoverBehaviorBase<T> coverBehavior) { + super(dataGetter, dataSetter); + this.coverBehavior = coverBehavior; + } + + @Override + public <U, W extends Widget & IDataFollowerWidget<T, U>> CoverDataControllerWidget<T> addFollower( + W widget, Function<T, U> dataToStateGetter, BiFunction<T, U, T> dataUpdater, Consumer<W> applyForWidget) { + super.addFollower(widget, dataToStateGetter, dataUpdater, applyForWidget); + return this; + } + + @Override + protected void writeToPacket(PacketBuffer buffer, T data) { + try { + NetworkUtils.writeNBTBase(buffer, data.saveDataToNBT()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + protected T readFromPacket(PacketBuffer buffer) throws IOException { + return coverBehavior.createDataObject(NetworkUtils.readNBTBase(buffer)); + } + + /** + * Uses int index to determine toggle button behaviors. + */ + public static class CoverDataIndexedControllerWidget_ToggleButtons<T extends ISerializableObject> + extends CoverDataControllerWidget<T> { + + private final BiFunction<Integer, T, Boolean> dataToStateGetter; + private final BiFunction<Integer, T, T> dataUpdater; + + /** + * @param coverDataGetter () -> cover data this widget handles + * @param coverDataSetter data to set -> if setting cover data is successful + * @param coverBehavior cover this widget handles data update + * @param dataToStateGetter (index of button, given cover data) -> button state + * @param dataUpdater (index of button, current cover data) -> new cover data + */ + public CoverDataIndexedControllerWidget_ToggleButtons( + Supplier<T> coverDataGetter, + Function<T, Boolean> coverDataSetter, + GT_CoverBehaviorBase<T> coverBehavior, + BiFunction<Integer, T, Boolean> dataToStateGetter, + BiFunction<Integer, T, T> dataUpdater) { + super(coverDataGetter, coverDataSetter, coverBehavior); + this.dataToStateGetter = dataToStateGetter; + this.dataUpdater = dataUpdater; + } + + /** + * @param index index of widget to add + * @param widget widget to add + * @param applyForWidget methods to call for widget to add + */ + public <W extends CoverDataFollower_ToggleButtonWidget<T>> + CoverDataIndexedControllerWidget_ToggleButtons<T> addToggleButton( + int index, W widget, Consumer<CoverDataFollower_ToggleButtonWidget<T>> applyForWidget) { + addFollower( + widget, + data -> dataToStateGetter.apply(index, data), + (data, state) -> dataUpdater.apply(index, data), + applyForWidget); + return this; + } + } + + /** + * Uses int index to determine cycle button behaviors. + */ + public static class CoverDataIndexedControllerWidget_CycleButtons<T extends ISerializableObject> + extends CoverDataControllerWidget<T> { + + private final BiFunction<Integer, T, Integer> dataToStateGetter; + private final BiFunction<Integer, T, T> dataUpdater; + + /** + * @param coverDataGetter () -> cover data this widget handles + * @param coverDataSetter data to set -> if setting cover data is successful + * @param coverBehavior cover this widget handles data update + * @param dataToStateGetter (index of button, given cover data) -> button state + * @param dataUpdater (index of button, current cover data) -> new cover data + */ + public CoverDataIndexedControllerWidget_CycleButtons( + Supplier<T> coverDataGetter, + Function<T, Boolean> coverDataSetter, + GT_CoverBehaviorBase<T> coverBehavior, + BiFunction<Integer, T, Integer> dataToStateGetter, + BiFunction<Integer, T, T> dataUpdater) { + super(coverDataGetter, coverDataSetter, coverBehavior); + this.dataToStateGetter = dataToStateGetter; + this.dataUpdater = dataUpdater; + } + + /** + * @param index index of widget to add + * @param widget widget to add + * @param applyForWidget methods to call for the widget to add + */ + public <W extends CoverDataFollower_CycleButtonWidget<T>> + CoverDataIndexedControllerWidget_CycleButtons<T> addCycleButton( + int index, W widget, Consumer<CoverDataFollower_CycleButtonWidget<T>> applyForWidget) { + addFollower( + widget, + data -> dataToStateGetter.apply(index, data), + (data, state) -> dataUpdater.apply(index, data), + applyForWidget); + return this; + } + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_CycleButtonWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_CycleButtonWidget.java new file mode 100644 index 0000000000..d07165cc6e --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_CycleButtonWidget.java @@ -0,0 +1,38 @@ +package gregtech.common.gui.modularui.widget; + +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.ISerializableObject; +import java.util.function.Consumer; +import java.util.function.Function; + +/** + * Determines button state with cover data. + */ +public class CoverDataFollower_CycleButtonWidget<T extends ISerializableObject> extends CoverCycleButtonWidget + implements IDataFollowerWidget<T, Integer> { + + private Function<T, Integer> dataToStateGetter; + + public CoverDataFollower_CycleButtonWidget() { + super(); + setGetter(() -> 0); // fake getter; used only for init + setSynced(false, false); + } + + @Override + public CoverDataFollower_CycleButtonWidget<T> setDataToStateGetter(Function<T, Integer> dataToStateGetter) { + this.dataToStateGetter = dataToStateGetter; + return this; + } + + @Override + public CoverDataFollower_CycleButtonWidget<T> setStateSetter(Consumer<Integer> setter) { + super.setSetter(setter); + return this; + } + + @Override + public void updateState(T data) { + setState(dataToStateGetter.apply(data), false, false); + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_SlotWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_SlotWidget.java new file mode 100644 index 0000000000..c09c5b5279 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_SlotWidget.java @@ -0,0 +1,102 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.widget.Interactable; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.ISerializableObject; +import java.io.IOException; +import java.util.function.Consumer; +import java.util.function.Function; +import net.minecraft.item.ItemStack; + +public class CoverDataFollower_SlotWidget<T extends ISerializableObject> extends SlotWidget + implements IDataFollowerWidget<T, ItemStack> { + + private Function<T, ItemStack> dataToStateGetter; + private Consumer<ItemStack> dataSetter; + + public CoverDataFollower_SlotWidget(BaseSlot slot) { + super(slot); + } + + public CoverDataFollower_SlotWidget(IItemHandlerModifiable handler, int index, boolean phantom) { + this(new BaseSlot(handler, index, phantom)); + } + + public CoverDataFollower_SlotWidget(IItemHandlerModifiable handler, int index) { + this(handler, index, false); + } + + @Override + public CoverDataFollower_SlotWidget<T> setDataToStateGetter(Function<T, ItemStack> dataToStateGetter) { + this.dataToStateGetter = dataToStateGetter; + return this; + } + + @Override + public CoverDataFollower_SlotWidget<T> setStateSetter(Consumer<ItemStack> setter) { + this.dataSetter = setter; + return this; + } + + @Override + public void updateState(T data) { + getMcSlot().putStack(dataToStateGetter.apply(data)); + } + + @Override + public void detectAndSendChanges(boolean init) {} + + // Slot sync is handled differently from other DataFollowers, + // so we need to also sync slot content directly to server. + + @Override + public ClickResult onClick(int buttonId, boolean doubleClick) { + if (interactionDisabled) return ClickResult.REJECT; + if (isPhantom()) { + ClickData clickData = ClickData.create(buttonId, doubleClick); + syncToServer(2, clickData::writeToPacket); + phantomClick(clickData); + dataSetter.accept(getMcSlot().getStack()); + return ClickResult.ACCEPT; + } + return ClickResult.REJECT; + } + + @Override + public boolean onMouseScroll(int direction) { + if (interactionDisabled) return false; + if (isPhantom()) { + if (Interactable.hasShiftDown()) { + direction *= 8; + } + final int finalDirection = direction; + syncToServer(3, buffer -> buffer.writeVarIntToBuffer(finalDirection)); + phantomScroll(finalDirection); + dataSetter.accept(getMcSlot().getStack()); + return true; + } + return false; + } + + @Override + public boolean handleDragAndDrop(ItemStack draggedStack, int button) { + if (interactionDisabled) return false; + if (!isPhantom()) return false; + ClickData clickData = ClickData.create(button, false); + syncToServer(5, buffer -> { + try { + clickData.writeToPacket(buffer); + buffer.writeItemStackToBuffer(draggedStack); + } catch (IOException e) { + e.printStackTrace(); + } + }); + phantomClick(clickData, draggedStack); + dataSetter.accept(getMcSlot().getStack()); + draggedStack.stackSize = 0; + return true; + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_TextFieldWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_TextFieldWidget.java new file mode 100644 index 0000000000..9130f8e3d0 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_TextFieldWidget.java @@ -0,0 +1,110 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.ISerializableObject; +import java.util.function.Consumer; +import java.util.function.Function; +import net.minecraft.client.gui.GuiScreen; + +public class CoverDataFollower_TextFieldWidget<T extends ISerializableObject> extends TextFieldWidget + implements IDataFollowerWidget<T, String> { + + private Function<T, String> dataToStateGetter; + + public CoverDataFollower_TextFieldWidget() { + super(); + setGetter(() -> ""); // fake getter; used only for init + setSynced(false, false); + setTextColor(Color.WHITE.dark(1)); + setTextAlignment(Alignment.CenterLeft); + setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD.withOffset(-1, -1, 2, 2)); + } + + @Override + public void onPostInit() { + // Widget#onPostInit is called earlier than IDataFollowerWidget#onPostInit, + // so we make sure cursor is set after text is set + super.onPostInit(); + + // On first call #handler does not contain text. + // On second call, it contains correct text to update #lastText, + // but #shouldGetFocus call is skipped by Cursor#updateFocused, + // so we need to manually call this. + if (focusOnGuiOpen) { + shouldGetFocus(); + } + } + + @Override + public CoverDataFollower_TextFieldWidget<T> setDataToStateGetter(Function<T, String> dataToStateGetter) { + this.dataToStateGetter = dataToStateGetter; + return this; + } + + @Override + public CoverDataFollower_TextFieldWidget<T> setStateSetter(Consumer<String> setter) { + super.setSetter(setter); + return this; + } + + @Override + public void updateState(T data) { + setText(dataToStateGetter.apply(data)); + } + + public CoverDataFollower_TextFieldWidget<T> setOnScrollNumbers(int baseStep, int ctrlStep, int shiftStep) { + setOnScrollNumbers((val, direction) -> { + int step = (GuiScreen.isShiftKeyDown() ? shiftStep : GuiScreen.isCtrlKeyDown() ? ctrlStep : baseStep) + * direction; + try { + val = Math.addExact(val, step); + } catch (ArithmeticException ignored) { + val = Integer.MAX_VALUE; + } + return val; + }); + return this; + } + + public CoverDataFollower_TextFieldWidget<T> setOnScrollNumbers() { + return setOnScrollNumbers(1, 50, 1000); + } + + public CoverDataFollower_TextFieldWidget<T> setOnScrollText(int baseStep, int ctrlStep, int shiftStep) { + setOnScroll((text, direction) -> { + int val = (int) MathExpression.parseMathExpression(text, -1); + int step = (GuiScreen.isShiftKeyDown() ? shiftStep : GuiScreen.isCtrlKeyDown() ? ctrlStep : baseStep) + * direction; + try { + val = Math.addExact(val, step); + } catch (ArithmeticException ignored) { + val = Integer.MAX_VALUE; + } + return TextFieldWidget.format.format(val); + }); + return this; + } + + public CoverDataFollower_TextFieldWidget<T> setOnScrollText() { + return setOnScrollText(1, 5, 50); + } + + public CoverDataFollower_TextFieldWidget<T> setOnScrollNumbersLong(long baseStep, long ctrlStep, long shiftStep) { + setOnScrollNumbersLong((val, direction) -> { + long step = (GuiScreen.isShiftKeyDown() ? shiftStep : GuiScreen.isCtrlKeyDown() ? ctrlStep : baseStep) + * direction; + try { + val = Math.addExact(val, step); + } catch (ArithmeticException ignored) { + val = Long.MAX_VALUE; + } + return val; + }); + return this; + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_ToggleButtonWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_ToggleButtonWidget.java new file mode 100644 index 0000000000..8e091d7bc6 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/CoverDataFollower_ToggleButtonWidget.java @@ -0,0 +1,84 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.ISerializableObject; +import java.util.function.Consumer; +import java.util.function.Function; + +public class CoverDataFollower_ToggleButtonWidget<T extends ISerializableObject> extends CoverCycleButtonWidget + implements IDataFollowerWidget<T, Boolean> { + + private Function<T, Boolean> dataToStateGetter; + + public CoverDataFollower_ToggleButtonWidget() { + super(); + setGetter(() -> 0); // fake getter; used only for init + setSynced(false, false); + setLength(2); + } + + @Override + public CoverDataFollower_ToggleButtonWidget<T> setDataToStateGetter(Function<T, Boolean> dataToStateGetter) { + this.dataToStateGetter = dataToStateGetter; + return this; + } + + @Override + public CoverDataFollower_ToggleButtonWidget<T> setStateSetter(Consumer<Boolean> setter) { + super.setSetter(val -> setter.accept(val == 1)); + return this; + } + + @Override + public void updateState(T data) { + setState(dataToStateGetter.apply(data) ? 1 : 0, false, false); + } + + public CoverDataFollower_ToggleButtonWidget<T> setToggleTexture(IDrawable active, IDrawable inactive) { + setTextureGetter(state -> state == 1 ? active : inactive); + return this; + } + + public static <T extends ISerializableObject> CoverDataFollower_ToggleButtonWidget<T> ofCheckAndCross() { + return new CoverDataFollower_ToggleButtonWidget<T>() + .setToggleTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK, GT_UITextures.OVERLAY_BUTTON_CROSS); + } + + public static <T extends ISerializableObject> CoverDataFollower_ToggleButtonWidget<T> ofCheck() { + return new CoverDataFollower_ToggleButtonWidget<T>() + .setToggleTexture(GT_UITextures.OVERLAY_BUTTON_CHECKMARK, GT_UITextures.TRANSPARENT); + } + + public static <T extends ISerializableObject> CoverDataFollower_ToggleButtonWidget<T> ofRedstone() { + return new CoverDataFollower_ToggleButtonWidget<T>() + .setToggleTexture(GT_UITextures.OVERLAY_BUTTON_REDSTONE_ON, GT_UITextures.OVERLAY_BUTTON_REDSTONE_OFF); + } + + public static <T extends ISerializableObject> CoverDataFollower_ToggleButtonWidget<T> ofDisableable() { + return new CoverDataFollower_DisableableToggleButtonWidget<>(); + } + + /** + * Disables clicking if button is already pressed. + */ + public static class CoverDataFollower_DisableableToggleButtonWidget<T extends ISerializableObject> + extends CoverDataFollower_ToggleButtonWidget<T> { + + public CoverDataFollower_DisableableToggleButtonWidget() { + super(); + } + + @Override + protected boolean canClick() { + return getState() == 0; + } + + @Override + public IDrawable[] getBackground() { + if (!canClick()) return new IDrawable[] {GT_UITextures.BUTTON_COVER_NORMAL_DISABLED}; + return super.getBackground(); + } + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/DataControllerWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/DataControllerWidget.java new file mode 100644 index 0000000000..f29b8eeaf9 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/DataControllerWidget.java @@ -0,0 +1,162 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.gui.modularui.IDataFollowerWidget; +import gregtech.api.util.ISerializableObject; +import java.io.IOException; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +import net.minecraft.network.PacketBuffer; + +/** + * Controls state of child widgets with specific data, and allows centralized control of multiple widgets. + * e.g. clicking button B will set machine mode to B, so button A, whose state is bound to the mode, + * will be automatically deactivated by this widget. + * <br> This widget wraps data and handles validation, e.g. tell client to close GUI when tile is broken or cover is removed. + * <br> Data can be anything, e.g. {@link ISerializableObject} or machine recipe mode. + * @param <T> Data type stored in this widget + * @see IDataFollowerWidget + */ +public abstract class DataControllerWidget<T> extends MultiChildWidget implements ISyncedWidget { + + private final Supplier<T> dataGetter; + private final Function<T, Boolean> dataSetter; + + protected T lastData; + + private boolean needsUpdate; + + /** + * @param dataGetter () -> data this widget handles + * @param dataSetter data to set -> if setting data is successful + */ + public DataControllerWidget(Supplier<T> dataGetter, Function<T, Boolean> dataSetter) { + this.dataGetter = dataGetter; + this.dataSetter = dataSetter; + } + + protected T getLastData() { + return lastData; + } + + @Override + public void onPostInit() { + super.onPostInit(); + // client _should_ have received initial cover data from `GT_UIInfos#openCoverUI` + lastData = dataGetter.get(); + if (NetworkUtils.isClient()) { + updateChildren(true); + } + } + + @Override + public void detectAndSendChanges(boolean init) { + T actualValue = dataGetter.get(); + if (actualValue == null) { + // data is in invalid state e.g. tile is broken, cover is removed + getWindow().tryClose(); + return; + } + if (init || !actualValue.equals(getLastData())) { + // init sync or someone else edited data + lastData = actualValue; + syncDataToClient(actualValue); + } + } + + protected void syncDataToClient(T data) { + syncToClient(0, buffer -> writeToPacket(buffer, data)); + } + + protected void syncDataToServer(T data) { + syncToServer(0, buffer -> writeToPacket(buffer, data)); + updateChildren(); + } + + @Override + public void readOnClient(int id, PacketBuffer buf) throws IOException { + if (id == 0) { + lastData = readFromPacket(buf); + dataSetter.apply(getLastData()); + updateChildren(); + } + } + + @Override + public void readOnServer(int id, PacketBuffer buf) throws IOException { + if (id == 0) { + lastData = readFromPacket(buf); + if (dataSetter.apply(getLastData())) { + markForUpdate(); + } else { + getWindow().closeWindow(); + } + } + } + + @SuppressWarnings("unchecked") + @SideOnly(Side.CLIENT) + protected void updateChildren(boolean postInit) { + for (Widget child : getChildren()) { + if (child instanceof IDataFollowerWidget) { + ((IDataFollowerWidget<T, ?>) child).updateState(getLastData()); + if (postInit) { + ((IDataFollowerWidget<T, ?>) child).onPostInit(); + } + } + } + } + + @SideOnly(Side.CLIENT) + protected void updateChildren() { + updateChildren(false); + } + + protected abstract void writeToPacket(PacketBuffer buffer, T data); + + protected abstract T readFromPacket(PacketBuffer buffer) throws IOException; + + @Override + public void markForUpdate() { + needsUpdate = true; + } + + @Override + public void unMarkForUpdate() { + needsUpdate = false; + } + + @Override + public boolean isMarkedForUpdate() { + return needsUpdate; + } + + /** + * @param widget widget to add that implements {@link IDataFollowerWidget} + * @param dataToStateGetter given data -> state of the widget to add + * @param dataUpdater (current data, state of the widget to add) -> new data to set + * @param applyForWidget methods to call for the widget to add + * @param <U> state type stored in the widget to add + * @param <W> widget type to add + */ + public <U, W extends Widget & IDataFollowerWidget<T, U>> DataControllerWidget<T> addFollower( + W widget, Function<T, U> dataToStateGetter, BiFunction<T, U, T> dataUpdater, Consumer<W> applyForWidget) { + widget.setDataToStateGetter(dataToStateGetter); + widget.setStateSetter(state -> { + T newData = dataUpdater.apply(getLastData(), state); + lastData = newData; + dataSetter.apply(getLastData()); + syncDataToServer(newData); + }); + applyForWidget.accept(widget); + addChild(widget); + return this; + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java new file mode 100644 index 0000000000..99200e5e8d --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java @@ -0,0 +1,474 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import gregtech.GT_Mod; +import gregtech.api.interfaces.IFluidAccess; +import gregtech.api.interfaces.IHasFluidDisplayItem; +import gregtech.api.interfaces.metatileentity.IFluidLockable; +import gregtech.api.util.GT_Utility; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Supplier; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +public class FluidDisplaySlotWidget extends SlotWidget { + + private IHasFluidDisplayItem iHasFluidDisplay; + private Supplier<IFluidAccess> fluidAccessConstructor; + private Supplier<Boolean> canDrainGetter; + private Supplier<Boolean> canFillGetter; + private Action actionRealClick = Action.NONE; + private Action actionDragAndDrop = Action.NONE; + private BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeRealClick; + private BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeDragAndDrop; + private Runnable updateFluidDisplayItem = () -> { + if (iHasFluidDisplay != null) { + iHasFluidDisplay.updateFluidDisplayItem(); + } + }; + + public FluidDisplaySlotWidget(BaseSlot slot) { + super(slot); + setAccess(false, false); + disableShiftInsert(); + } + + public FluidDisplaySlotWidget(IItemHandlerModifiable handler, int index) { + this(new BaseSlot(handler, index, true)); + } + + // === client actions === + + @Override + public ClickResult onClick(int buttonId, boolean doubleClick) { + if (actionRealClick == Action.NONE) return ClickResult.REJECT; + if (interactionDisabled) return ClickResult.REJECT; + + /* + * While a logical client don't really need to process fluid cells upon click (it could have just wait + * for server side to send the result), doing so would result in every fluid interaction having a + * noticeable delay between clicking and changes happening even on single player. + * I'd imagine this lag to become only more severe when playing MP over ethernet, which would have much more latency + * than a memory connection + */ + ClickData clickData = ClickData.create(buttonId, doubleClick); + ItemStack verifyToken = executeRealClick(clickData); + syncToServer(2, buffer -> { + clickData.writeToPacket(buffer); + try { + buffer.writeItemStackToBuffer(verifyToken); + } catch (IOException e) { + e.printStackTrace(); + } + }); + return ClickResult.ACCEPT; + } + + @Override + public boolean handleDragAndDrop(ItemStack draggedStack, int button) { + if (actionDragAndDrop == Action.NONE || actionDragAndDrop == Action.TRANSFER) return false; + if (interactionDisabled) return false; + + ClickData clickData = ClickData.create(button, false); + executeDragAndDrop(clickData, draggedStack); + syncToServer(5, buffer -> { + try { + clickData.writeToPacket(buffer); + buffer.writeItemStackToBuffer(draggedStack); + } catch (IOException e) { + e.printStackTrace(); + } + }); + draggedStack.stackSize = 0; + return true; + } + + @Override + public List<String> getExtraTooltip() { + return Collections.emptyList(); + } + + // === server actions === + + @Override + public void readOnServer(int id, PacketBuffer buf) throws IOException { + if (id == 1) { + getMcSlot().xDisplayPosition = buf.readVarIntFromBuffer(); + getMcSlot().yDisplayPosition = buf.readVarIntFromBuffer(); + } else if (id == 2) { + onClickServer(ClickData.readPacket(buf), buf.readItemStackFromBuffer()); + } else if (id == 3) { + phantomScroll(buf.readVarIntFromBuffer()); + } else if (id == 4) { + setEnabled(buf.readBoolean()); + } else if (id == 5) { + executeDragAndDrop(ClickData.readPacket(buf), buf.readItemStackFromBuffer()); + if (onDragAndDropComplete != null) { + onDragAndDropComplete.accept(this); + } + } + markForUpdate(); + } + + private void onClickServer(ClickData clickData, ItemStack clientVerifyToken) { + ItemStack serverVerifyToken = executeRealClick(clickData); + // similar to what NetHandlerPlayServer#processClickWindow does + if (!ItemStack.areItemStacksEqual(clientVerifyToken, serverVerifyToken)) { + ((EntityPlayerMP) getContext().getPlayer()) + .sendContainerToPlayer(getContext().getContainer()); + } + } + + // === client/server actions === + + private ItemStack executeRealClick(ClickData clickData) { + if (actionRealClick == Action.NONE) return null; + if (beforeRealClick != null && !beforeRealClick.apply(clickData, this)) return null; + + ItemStack ret = null; + if (actionRealClick == Action.TRANSFER) { + if (fluidAccessConstructor == null) { + GT_Mod.GT_FML_LOGGER.warn( + "FluidDisplaySlotWidget is asked to transfer fluid, but fluidAccessConstructor is null!"); + return null; + } + ret = transferFluid( + fluidAccessConstructor.get(), + getContext().getPlayer(), + clickData.mouseButton == 0, + canDrainGetter != null ? canDrainGetter.get() : true, + canFillGetter != null ? canFillGetter.get() : true); + } else if (actionRealClick == Action.LOCK) { + lockFluid(getContext().getPlayer().inventory.getItemStack()); + } + + updateFluidDisplayItem.run(); + return ret; + } + + protected ItemStack transferFluid( + IFluidAccess aFluidAccess, + EntityPlayer aPlayer, + boolean aProcessFullStack, + boolean aCanDrain, + boolean aCanFill) { + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; + FluidStack tInputFluid = aFluidAccess.get(); + FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true); + if (tFluidHeld != null && tFluidHeld.amount <= 0) tFluidHeld = null; + if (tInputFluid == null) { + // tank empty, consider fill only from now on + if (!aCanFill) + // cannot fill and nothing to take, bail out + return null; + if (tFluidHeld == null) + // no fluid to fill + return null; + return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); + } + // tank not empty, both action possible + if (tFluidHeld != null && tInputFluid.amount < aFluidAccess.getCapacity()) { + // both nonnull and have space left for filling. + if (aCanFill) + // actually both pickup and fill is reasonable, but I'll go with fill here + return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); + if (!aCanDrain) + // cannot take AND cannot fill, why make this call then? + return null; + // the slot does not allow filling, so try take some + return drainFluid(aFluidAccess, aPlayer, aProcessFullStack); + } else { + // cannot fill and there is something to take + if (!aCanDrain) + // but the slot does not allow taking, so bail out + return null; + return drainFluid(aFluidAccess, aPlayer, aProcessFullStack); + } + } + + protected static ItemStack drainFluid(IFluidAccess aFluidAccess, EntityPlayer aPlayer, boolean aProcessFullStack) { + FluidStack tTankStack = aFluidAccess.get(); + if (tTankStack == null) return null; + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; + int tOriginalFluidAmount = tTankStack.amount; + ItemStack tFilledContainer = GT_Utility.fillFluidContainer(tTankStack, tStackSizedOne, true, false); + if (tFilledContainer == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { + IFluidContainerItem tContainerItem = (IFluidContainerItem) tStackSizedOne.getItem(); + int tFilledAmount = tContainerItem.fill(tStackSizedOne, tTankStack, true); + if (tFilledAmount > 0) { + tFilledContainer = tStackSizedOne; + tTankStack.amount -= tFilledAmount; + } + } + if (tFilledContainer != null) { + if (aProcessFullStack) { + int tFilledAmount = tOriginalFluidAmount - tTankStack.amount; + /* + work out how many more items we can fill + one cell is already used, so account for that + the round down behavior will left over a fraction of a cell worth of fluid + the user then get to decide what to do with it + it will not be too fancy if it spills out partially filled cells + */ + int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, tTankStack.amount / tFilledAmount); + tTankStack.amount -= tFilledAmount * tAdditionalParallel; + tFilledContainer.stackSize += tAdditionalParallel; + } + replaceCursorItemStack(aPlayer, tFilledContainer); + } + aFluidAccess.verifyFluidStack(); + return tFilledContainer; + } + + protected static ItemStack fillFluid( + IFluidAccess aFluidAccess, EntityPlayer aPlayer, FluidStack aFluidHeld, boolean aProcessFullStack) { + // we are not using aMachine.fill() here any more, so we need to check for fluid type here ourselves + if (aFluidAccess.get() != null && !aFluidAccess.get().isFluidEqual(aFluidHeld)) return null; + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null) return null; + + int tFreeSpace = aFluidAccess.getCapacity() - (aFluidAccess.get() != null ? aFluidAccess.get().amount : 0); + if (tFreeSpace <= 0) + // no space left + return null; + + // find out how much fluid can be taken + // some cells cannot be partially filled + ItemStack tStackEmptied = null; + int tAmountTaken = 0; + if (tFreeSpace >= aFluidHeld.amount) { + // fully accepted - try take it from item now + // IFluidContainerItem is intentionally not checked here. it will be checked later + tStackEmptied = GT_Utility.getContainerForFilledItem(tStackSizedOne, false); + tAmountTaken = aFluidHeld.amount; + } + if (tStackEmptied == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) { + // either partially accepted, or is IFluidContainerItem + IFluidContainerItem container = (IFluidContainerItem) tStackSizedOne.getItem(); + FluidStack tDrained = container.drain(tStackSizedOne, tFreeSpace, true); + if (tDrained != null && tDrained.amount > 0) { + // something is actually drained - change the cell and drop it to player + tStackEmptied = tStackSizedOne; + tAmountTaken = tDrained.amount; + } + } + if (tStackEmptied == null) + // somehow the cell refuse to give out that amount of fluid, no op then + return null; + + // find out how many fill can we do + // same round down behavior as above + // however here the fluid stack is not changed at all, so the exact code will slightly differ + int tParallel = aProcessFullStack ? Math.min(tFreeSpace / tAmountTaken, tStackHeld.stackSize) : 1; + if (aFluidAccess.get() == null) { + FluidStack tNewFillableStack = aFluidHeld.copy(); + tNewFillableStack.amount = tAmountTaken * tParallel; + aFluidAccess.set(tNewFillableStack); + } else { + aFluidAccess.addAmount(tAmountTaken * tParallel); + } + tStackEmptied.stackSize = tParallel; + replaceCursorItemStack(aPlayer, tStackEmptied); + return tStackEmptied; + } + + protected static void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) { + int tStackResultMaxStackSize = tStackResult.getMaxStackSize(); + while (tStackResult.stackSize > tStackResultMaxStackSize) { + aPlayer.inventory.getItemStack().stackSize -= tStackResultMaxStackSize; + GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult.splitStack(tStackResultMaxStackSize)); + } + if (aPlayer.inventory.getItemStack().stackSize == tStackResult.stackSize) { + // every cell is mutated. it could just stay on the cursor. + aPlayer.inventory.setItemStack(tStackResult); + } else { + // some cells not mutated. The mutated cells must go into the inventory + // or drop into the world if there isn't enough space. + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + tStackHeld.stackSize -= tStackResult.stackSize; + GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult); + } + } + + protected void executeDragAndDrop(ClickData clickData, ItemStack draggedStack) { + if (actionDragAndDrop == Action.NONE || actionDragAndDrop == Action.TRANSFER) return; + if (beforeDragAndDrop != null && !beforeDragAndDrop.apply(clickData, this)) return; + + if (actionDragAndDrop == Action.LOCK) { + lockFluid(draggedStack); + } + updateFluidDisplayItem.run(); + } + + protected void lockFluid(ItemStack cursorStack) { + if (!(iHasFluidDisplay instanceof IFluidLockable)) return; + IFluidLockable mteToLock = (IFluidLockable) iHasFluidDisplay; + + if (cursorStack == null) { + if (!mteToLock.allowChangingLockedFluid(null)) return; + + mteToLock.lockFluid(false); + mteToLock.setLockedFluidName(null); + GT_Utility.sendChatToPlayer(getContext().getPlayer(), GT_Utility.trans("300.1", "Fluid Lock Cleared.")); + + if (!isClient()) { + mteToLock.onFluidLockPacketReceived(null); + } + } else { + FluidStack fluidStack = GT_Utility.getFluidFromContainerOrFluidDisplay(cursorStack); + if (fluidStack == null) return; + Fluid tFluid = fluidStack.getFluid(); + if (tFluid == null) return; + + if (!mteToLock.allowChangingLockedFluid(tFluid.getName())) return; + + mteToLock.lockFluid(true); + mteToLock.setLockedFluidName(tFluid.getName()); + GT_Utility.sendChatToPlayer( + getContext().getPlayer(), + String.format( + GT_Utility.trans("151.4", "Successfully locked Fluid to %s"), + new FluidStack(tFluid, 1).getLocalizedName())); + + if (!isClient()) { + mteToLock.onFluidLockPacketReceived(tFluid.getName()); + } + } + } + + protected void updateFluidDisplayItem() { + if (iHasFluidDisplay != null) { + iHasFluidDisplay.updateFluidDisplayItem(); + } + } + + // === setters === + + public FluidDisplaySlotWidget setFluidAccessConstructor(Supplier<IFluidAccess> fluidAccessConstructor) { + this.fluidAccessConstructor = fluidAccessConstructor; + return this; + } + + public FluidDisplaySlotWidget setIHasFluidDisplay(IHasFluidDisplayItem iHasFluidDisplay) { + this.iHasFluidDisplay = iHasFluidDisplay; + return this; + } + + public FluidDisplaySlotWidget setCanDrainGetter(Supplier<Boolean> canDrainGetter) { + this.canDrainGetter = canDrainGetter; + return this; + } + + public FluidDisplaySlotWidget setCanDrain(boolean canDrain) { + return setCanDrainGetter(() -> canDrain); + } + + public FluidDisplaySlotWidget setCanFillGetter(Supplier<Boolean> canFillGetter) { + this.canFillGetter = canFillGetter; + return this; + } + + public FluidDisplaySlotWidget setCanFill(boolean canFill) { + return setCanFillGetter(() -> canFill); + } + + /** + * Sets action called on click while holding the real item. + */ + public FluidDisplaySlotWidget setActionRealClick(Action actionRealClick) { + this.actionRealClick = actionRealClick; + return this; + } + + /** + * Sets action called on drag-and-drop from NEI. + * You can't use {@link Action#TRANSFER} here. + */ + public FluidDisplaySlotWidget setActionDragAndDrop(Action actionDragAndDrop) { + this.actionDragAndDrop = actionDragAndDrop; + return this; + } + + /** + * Sets function called before {@link #executeRealClick}. + * @param beforeRealClick (click data, this widget) -> if allow click + */ + public FluidDisplaySlotWidget setBeforeRealClick( + BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeRealClick) { + this.beforeRealClick = beforeRealClick; + return this; + } + + /** + * Sets function called before {@link #executeDragAndDrop}. + * @param beforeDragAndDrop (click data, this widget) -> if allow click + */ + public FluidDisplaySlotWidget setBeforeDragAndDrop( + BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeDragAndDrop) { + this.beforeDragAndDrop = beforeDragAndDrop; + return this; + } + + /** + * Sets function called before both of {@link #executeRealClick} and {@link #executeDragAndDrop}. + * @param beforeClick (click data, this widget) -> if allow click + */ + public FluidDisplaySlotWidget setBeforeClick(BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeClick) { + setBeforeRealClick(beforeClick); + setBeforeDragAndDrop(beforeClick); + return this; + } + + /** + * By default, this widget runs {@link IHasFluidDisplayItem#updateFluidDisplayItem} after click. + * You can specify custom update action with this method. + */ + public FluidDisplaySlotWidget setUpdateFluidDisplayItem(Runnable updateFluidDisplayItem) { + this.updateFluidDisplayItem = updateFluidDisplayItem; + return this; + } + + /** + * Action triggered on mouse click or NEI drag-and-drop. + */ + public enum Action { + + /** + * Fill/drain fluid into/from the tank. + * Uses fluid amount, so drag-and-drop cannot use this mode. + */ + TRANSFER, + + /** + * Lock fluid for {@link IFluidLockable}. + * Does not use fluid amount. + */ + LOCK, + + /** + * Set filter for the tank. (not implemented yet) + * Does not use fluid amount. + */ + FILTER, + + /** + * Does nothing. + */ + NONE + } +} diff --git a/src/main/java/gregtech/common/gui/modularui/widget/ItemWatcherSlotWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/ItemWatcherSlotWidget.java new file mode 100644 index 0000000000..7385208874 --- /dev/null +++ b/src/main/java/gregtech/common/gui/modularui/widget/ItemWatcherSlotWidget.java @@ -0,0 +1,47 @@ +package gregtech.common.gui.modularui.widget; + +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import gregtech.api.util.GT_Utility; +import java.util.function.Supplier; +import net.minecraft.item.ItemStack; + +/** + * Watches specific ItemStack and pulls changes from it. + * Player cannot interact with slot, other than viewing NEI recipe or adding bookmark. + */ +public class ItemWatcherSlotWidget extends SlotWidget { + + private ItemStack lastItem; + private Supplier<ItemStack> getter; + + public ItemWatcherSlotWidget() { + super(BaseSlot.phantom(new ItemStackHandler(), 0)); + disableInteraction(); + } + + public ItemWatcherSlotWidget setGetter(Supplier<ItemStack> getter) { + this.getter = getter; + return this; + } + + @Override + public void detectAndSendChanges(boolean init) { + ItemStack target = getter.get(); + if (init || !GT_Utility.areStacksEqual(lastItem, target)) { + ItemStack toPut; + if (target != null) { + toPut = target.copy(); + toPut.stackSize = 1; + } else { + toPut = null; + } + ((IItemHandlerModifiable) getMcSlot().getItemHandler()).setStackInSlot(0, toPut); + lastItem = target; + getMcSlot().onSlotChanged(); + } + super.detectAndSendChanges(init); + } +} diff --git a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java index d82d307ee8..a5842bb9c1 100644 --- a/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java +++ b/src/main/java/gregtech/common/items/GT_IntegratedCircuit_Item.java @@ -3,7 +3,7 @@ package gregtech.common.items; import static gregtech.GT_Mod.GT_FML_LOGGER; import static gregtech.api.enums.GT_Values.RES_PATH_ITEM; -import cpw.mods.fml.common.FMLCommonHandler; +import com.gtnewhorizons.modularui.api.UIInfos; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.GregTech_API; @@ -11,7 +11,6 @@ import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_GUIDialogSelectItem; import gregtech.api.interfaces.INetworkUpdatableItem; import gregtech.api.items.GT_Generic_Item; import gregtech.api.net.GT_Packet_UpdateItem; @@ -21,6 +20,7 @@ import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.uifactory.SelectItemUIFactory; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -270,20 +270,19 @@ public class GT_IntegratedCircuit_Item extends GT_Generic_Item implements INetwo } configuratorStack = player.inventory.mainInventory[configurator.getKey()]; } - openSelectorGui(configuratorStack, stack.getItemDamage()); + openSelectorGui(configuratorStack, stack.getItemDamage(), player); return stack; } - private void openSelectorGui(ItemStack configurator, int meta) { - FMLCommonHandler.instance() - .showGuiScreen(new GT_GUIDialogSelectItem( + private void openSelectorGui(ItemStack configurator, int meta, EntityPlayer player) { + UIInfos.openClientUI(player, buildContext -> new SelectItemUIFactory( StatCollector.translateToLocal("GT5U.item.programmed_circuit.select.header"), configurator, - null, GT_IntegratedCircuit_Item::onConfigured, ALL_VARIANTS, meta, - true)); + true) + .createWindow(buildContext)); } private static void onConfigured(ItemStack stack) { diff --git a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java index f4ee8a7c85..0d7d503690 100644 --- a/src/main/java/gregtech/common/items/GT_VolumetricFlask.java +++ b/src/main/java/gregtech/common/items/GT_VolumetricFlask.java @@ -6,19 +6,31 @@ import static ic2.core.util.LiquidUtil.drainContainerStack; import static ic2.core.util.LiquidUtil.fillContainerStack; import static ic2.core.util.LiquidUtil.placeFluid; +import com.gtnewhorizons.modularui.api.ModularUITextures; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; +import com.gtnewhorizons.modularui.api.math.MathExpression; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.IItemWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.VanillaButtonWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.BaseTextFieldWidget; +import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gregtech.api.enums.GT_Values; -import gregtech.api.interfaces.INetworkUpdatableItem; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.items.GT_Generic_Item; import gregtech.api.util.GT_Utility; import ic2.core.util.LiquidUtil; import java.util.List; +import java.util.function.Function; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -37,7 +49,7 @@ import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidHandler; -public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem, INetworkUpdatableItem { +public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContainerItem, IItemWithModularUI { private final int maxCapacity; private final String unlocalFlaskName; @@ -55,7 +67,7 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!world.isRemote && isEmpty(stack) && getMovingObjectPositionFromPlayer(world, player, true) == null) - player.openGui(GT_Values.GT, 1010, world, 0, 0, 0); + GT_UIInfos.openPlayerHeldItemUI(player); return super.onItemRightClick(stack, world, player); } @@ -300,12 +312,83 @@ public class GT_VolumetricFlask extends GT_Generic_Item implements IFluidContain } @Override - public boolean receive(ItemStack stack, EntityPlayerMP player, NBTTagCompound tag) { - if (stack != null && stack.stackSize > 0) { - Item item = stack.getItem(); - if (item == this) setCapacity(stack, tag.getInteger("cap")); - return true; + public ModularWindow createWindow(UIBuildContext buildContext, ItemStack stack) { + if (!(stack.getItem() instanceof GT_VolumetricFlask)) return null; + return new VolumetricFlaskUIFactory(buildContext, stack).createWindow(); + } + + private class VolumetricFlaskUIFactory { + + private final UIBuildContext buildContext; + private final int maxCapacity; + private TextFieldWidget textField; + + public VolumetricFlaskUIFactory(UIBuildContext buildContext, ItemStack flask) { + this.buildContext = buildContext; + this.maxCapacity = ((GT_VolumetricFlask) flask.getItem()).getMaxCapacity(); + } + + public ModularWindow createWindow() { + ModularWindow.Builder builder = ModularWindow.builder(176, 107); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND); + + textField = new TextFieldWidget() { + @Override + public void onDestroy() { + if (isClient()) return; + setCapacity(getCurrentItem(), (int) MathExpression.parseMathExpression(getText(), 1)); + getContext().onWidgetUpdate(); + } + }; + textField.setText( + String.valueOf(((GT_VolumetricFlask) getCurrentItem().getItem()).getCapacity(getCurrentItem()))); + builder.widget(textField + .setNumbers(() -> 1, () -> maxCapacity) + .setPattern(BaseTextFieldWidget.NATURAL_NUMS) + .setTextAlignment(Alignment.CenterLeft) + .setTextColor(Color.WHITE.dark(1)) + .setFocusOnGuiOpen(true) + .setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD_LIGHT_GRAY.withOffset(-1, -1, 2, 2)) + .setPos(60, 55) + .setSize(59, 12)); + + addChangeAmountButton(builder, "+1", new Pos2d(20, 26), new Size(22, 20), val -> val + 1); + addChangeAmountButton(builder, "+10", new Pos2d(48, 26), new Size(28, 20), val -> val + 10); + addChangeAmountButton(builder, "+100", new Pos2d(82, 26), new Size(32, 20), val -> val + 100); + addChangeAmountButton(builder, "+1000", new Pos2d(120, 26), new Size(38, 20), val -> val + 1000); + addChangeAmountButton(builder, "-1", new Pos2d(20, 75), new Size(22, 20), val -> val - 1); + addChangeAmountButton(builder, "-10", new Pos2d(48, 75), new Size(28, 20), val -> val - 10); + addChangeAmountButton(builder, "-100", new Pos2d(82, 75), new Size(32, 20), val -> val - 100); + addChangeAmountButton(builder, "-1000", new Pos2d(120, 75), new Size(38, 20), val -> val - 1000); + builder.widget(new VanillaButtonWidget() + .setDisplayString("Accept") + .setClickableGetter(() -> MathExpression.parseMathExpression(textField.getText()) > 0) + .setOnClick((clickData, widget) -> { + textField.onRemoveFocus(); + widget.getWindow().tryClose(); + }) + .setPos(128, 51) + .setSize(38, 20)); + + return builder.build(); + } + + private void addChangeAmountButton( + ModularWindow.Builder builder, String text, Pos2d pos, Size size, Function<Integer, Integer> function) { + builder.widget(new VanillaButtonWidget() + .setDisplayString(text) + .setOnClick((clickData, widget) -> { + String currentText = textField.getText(); + int amount = (int) MathExpression.parseMathExpression(currentText, 1); + amount = Math.min(maxCapacity, Math.max(1, function.apply(amount))); + textField.setText(String.valueOf(amount)); + }) + .setPos(pos) + .setSize(size)); + } + + private ItemStack getCurrentItem() { + return buildContext.getPlayer().inventory.getCurrentItem(); } - return false; } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java index f5fcda6d7b..7bcbe33b86 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java @@ -3,16 +3,18 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_CHESTBUFFER; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_CHESTBUFFER_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; import gregtech.api.render.TextureFactory; -import gregtech.common.gui.GT_Container_ChestBuffer; -import gregtech.common.gui.GT_GUIContainer_ChestBuffer; -import net.minecraft.entity.player.InventoryPlayer; -public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { +public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer implements IAddUIWidgets { private static final int[] tickRate = {400, 200, 100, 20, 4, 1, 1, 1, 1, 1, 1, 1, 1}; private static final int[] maxStacks = {1, 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 128}; @@ -83,16 +85,6 @@ public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { } } - @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_ChestBuffer(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_ChestBuffer(aPlayerInventory, aBaseMetaTileEntity); - } - protected static String getTickRateDesc(int tier) { int tickRate = getTickRate(tier); String timeStr = ""; @@ -118,4 +110,21 @@ public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { // Included higher tiers on the off chance they actually work without blowing things up lmao return tier > 9 ? MAX : Math.min(maxStacks[tier], MAX); } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + addEmitEnergyButton(builder); + addEmitRedstoneButton(builder); + addInvertRedstoneButton(builder); + addStockingModeButton(builder); + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(69, true)) + .setPos(80, 60) + .setSize(69, 22)); + addMainUI(builder); + } + + protected void addMainUI(ModularWindow.Builder builder) { + addInventorySlots(builder); + } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java index f3ab391109..99ada34c17 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Filter.java @@ -3,19 +3,23 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_FILTER; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_FILTER_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_Filter; -import gregtech.common.gui.GT_GUIContainer_Filter; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer { +public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer implements IAddUIWidgets { public boolean bIgnoreNBT = false; public boolean bInvertFilter = false; @@ -56,16 +60,6 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Filter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Filter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setBoolean("bInvertFilter", this.bInvertFilter); @@ -106,4 +100,68 @@ public class GT_MetaTileEntity_Filter extends GT_MetaTileEntity_Buffer { for (byte b = 0; b < 6; b++) aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b, (byte) emptySlots); } else for (byte b = 0; b < 6; b++) aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b, (byte) 0); } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + addEmitEnergyButton(builder); + addEmitRedstoneButton(builder); + addInvertRedstoneButton(builder); + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bInvertFilter = !bInvertFilter; + if (bInvertFilter) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("124", "Invert Filter")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), + GT_Utility.trans("125", "Don't invert Filter")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_INVERT_FILTER) + .setPos(61, 62) + .setSize(18, 18)) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + bIgnoreNBT = !bIgnoreNBT; + if (bIgnoreNBT) { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("126", "Ignore NBT")); + } else { + GT_Utility.sendChatToPlayer( + widget.getContext().getPlayer(), GT_Utility.trans("127", "NBT has to match")); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_NBT) + .setPos(79, 62) + .setSize(18, 18)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_WHITE.apply(9, false)) + .setPos(6, 19) + .setSize(9, 24)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_BLUE.apply(24, true)) + .setPos(71, 19) + .setSize(24, 24)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_24_RED.apply(19, true)) + .setPos(152, 19) + .setSize(19, 24)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SLOTS_HOLO_3BY3) + .setPos(16, 4) + .setSize(54, 54)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .phantom(true) + .applyForWidget(widget -> widget.disableShiftInsert().setBackground(GT_UITextures.TRANSPARENT)) + .build() + .setPos(16, 4)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(9) + .endAtSlot(17) + .build() + .setPos(97, 4)); + } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java index 4241fa8d11..bf2fa41b0d 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java @@ -3,22 +3,24 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_ITEMDISTRIBUTOR; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_ITEMDISTRIBUTOR_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_ItemDistributor; -import gregtech.common.gui.GT_GUIContainer_ItemDistributor; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer { +public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer implements IAddUIWidgets { private byte[] itemsPerSide = new byte[6]; private byte currentSide = 0, currentSideItemCount = 0; @@ -53,11 +55,6 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_ItemDistributor(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public ITexture getOverlayIcon() { return TextureFactory.of( TextureFactory.of(AUTOMATION_ITEMDISTRIBUTOR), @@ -68,11 +65,6 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_ItemDistributor(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return aSide == aBaseMetaTileEntity.getFrontFacing(); } @@ -187,4 +179,16 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer super.setItemNBT(aNBT); aNBT.setByteArray("mItemsPerSide", itemsPerSide); } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + addEmitEnergyButton(builder); + addEmitRedstoneButton(builder); + addInvertRedstoneButton(builder); + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(87, true)) + .setPos(62, 60) + .setSize(87, 22)); + addInventorySlots(builder); + } } 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 index 007fa79213..14a6af709a 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_RecipeFilter.java @@ -3,6 +3,7 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_RECIPEFILTER_GLOW; +import com.gtnewhorizons.modularui.api.drawable.Text; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -11,8 +12,8 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_SpecialFilt 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 java.util.Collections; +import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -38,11 +39,6 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil } @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); @@ -55,9 +51,9 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil return; } } + mInventory[SPECIAL_SLOT_INDEX] = null; + mRecipeMap = null; } - mInventory[SPECIAL_SLOT_INDEX] = null; - mRecipeMap = null; } @Override @@ -92,4 +88,9 @@ public class GT_MetaTileEntity_RecipeFilter extends GT_MetaTileEntity_SpecialFil protected boolean isStackAllowed(ItemStack aStack) { return mRecipeMap != null && mRecipeMap.containsInput(aStack); } + + @Override + protected List<Text> getEmptySlotTooltip() { + return Collections.singletonList(Text.localised("GT5U.recipe_filter.representation_slot.tooltip")); + } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java index 71c4cbb258..39151cedff 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java @@ -3,21 +3,27 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_REGULATOR; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_REGULATOR_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Buffer; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_Regulator; -import gregtech.common.gui.GT_GUIContainer_Regulator; import java.util.Collections; 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_Regulator extends GT_MetaTileEntity_Buffer { +public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer implements IAddUIWidgets { public int[] mTargetSlots = {0, 0, 0, 0, 0, 0, 0, 0, 0}; private boolean charge = false, decharge = false; @@ -62,16 +68,6 @@ public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Regulator(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Regulator(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); aNBT.setInteger("mTargetSlot1", this.mTargetSlots[0]); @@ -166,4 +162,56 @@ public class GT_MetaTileEntity_Regulator extends GT_MetaTileEntity_Buffer { decharge = aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity() / 3; } } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + addEmitEnergyButton(builder); + builder.widget(createChargerSlot(43, 62)); + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_22_RED.apply(84, true)) + .setPos(65, 60) + .setSize(84, 22)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(0) + .endAtSlot(8) + .build() + .setPos(7, 5)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SLOTS_HOLO_3BY3) + .setPos(62, 5) + .setSize(54, 54)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 3) + .phantom(true) + .startFromSlot(9) + .endAtSlot(17) + .applyForWidget(widget -> widget.setBackground(GT_UITextures.TRANSPARENT)) + .build() + .setPos(62, 5)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SLOTS_HOLO_3BY3) + .setPos(117, 5) + .setSize(54, 54)); + + int xBase = 117, yBase = 5; + for (int i = 0; i < mTargetSlots.length; i++) { + final int index = i; + int xPos = xBase + (i % 3) * 18, yPos = yBase + (i / 3) * 18; + builder.widget( + new SlotWidget(BaseSlot.empty()) { + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + mTargetSlots[index] = Math.min( + 99, + Math.max( + 0, + mTargetSlots[index] + + (clickData.mouseButton == 0 ? -1 : 1) + * (clickData.shift ? 16 : 1))); + } + }.setBackground(GT_UITextures.TRANSPARENT).setPos(xPos, yPos)) + .widget(TextWidget.dynamicString(() -> String.valueOf(mTargetSlots[index])) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(xPos + 2 + (i % 3 == 0 ? 1 : 0), yPos + 3 + (i / 3 == 0 ? 1 : 0))); + } + } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java index ffa33f426e..a91a082c4e 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_SuperBuffer.java @@ -3,18 +3,18 @@ package gregtech.common.tileentities.automation; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_SUPERBUFFER; import static gregtech.api.enums.Textures.BlockIcons.AUTOMATION_SUPERBUFFER_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_SuperBuffer; -import gregtech.common.gui.GT_GUIContainer_SuperBuffer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_SuperBuffer extends GT_MetaTileEntity_ChestBuffer { @@ -85,12 +85,10 @@ public class GT_MetaTileEntity_SuperBuffer extends GT_MetaTileEntity_ChestBuffer } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_SuperBuffer(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_SuperBuffer(aPlayerInventory, aBaseMetaTileEntity); + protected void addMainUI(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SUPER_BUFFER) + .setPos(61, 4) + .setSize(54, 54)); } } 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 da1ca6d42a..6c3441c905 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 @@ -13,8 +13,12 @@ import gregtech.api.objects.ItemData; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; +import java.util.Arrays; +import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilter { public int mRotationIndex = 0; @@ -54,6 +58,7 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte .build()); } + @Override public void clickTypeIcon(boolean aRightClick, ItemStack aHandStack) { if (getBaseMetaTileEntity().isServerSide()) { ItemData data = GT_OreDictUnificator.getAssociation(aHandStack); @@ -143,4 +148,13 @@ public class GT_MetaTileEntity_TypeFilter extends GT_MetaTileEntity_SpecialFilte } return tAllowPrefix; } + + @Override + protected List<String> getItemExtraTooltip() { + return Arrays.asList( + EnumChatFormatting.DARK_GRAY + + StatCollector.translateToLocal("GT5U.type_filter.representation_slot.tooltip.0"), + EnumChatFormatting.DARK_GRAY + + StatCollector.translateToLocal("GT5U.type_filter.representation_slot.tooltip.1")); + } } diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java index 9d832e134c..67e18cf1b0 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java @@ -2,13 +2,26 @@ package gregtech.common.tileentities.boilers; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Materials; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.modularui.IGetTitleColor; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.objects.GT_ItemStack; @@ -25,7 +38,8 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; -public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTank { +public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTank + implements IGetTitleColor, IAddUIWidgets { public static final byte SOUND_EVENT_LET_OFF_EXCESS_STEAM = 1; public int mTemperature = 20; public int mProcessingEnergy = 0; @@ -126,7 +140,7 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa aPlayer.getCurrentEquippedItem().func_150996_a(Items.bucket); } } else { - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); } } return true; @@ -399,4 +413,100 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa } protected abstract void updateFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick); + + @Override + public SteamVariant getSteamVariant() { + return SteamVariant.BRONZE; + } + + protected IDrawable[] getFuelSlotBackground() { + return new IDrawable[] { + getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_COAL_STEAM.get(getSteamVariant()) + }; + } + + protected IDrawable[] getAshSlotBackground() { + return new IDrawable[] { + getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_DUST_STEAM.get(getSteamVariant()) + }; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new SlotWidget(inventoryHandler, 0) + .setPos(43, 25) + .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotIn())) + .widget(new SlotWidget(inventoryHandler, 1) + .setPos(43, 61) + .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotOut())) + .widget(new SlotWidget(inventoryHandler, 2).setPos(115, 61).setBackground(getFuelSlotBackground())) + .widget(new SlotWidget(inventoryHandler, 3).setPos(115, 25).setBackground(getAshSlotBackground())) + .widget(new ProgressBar() + .setProgress(() -> mSteam == null ? 0 : (float) mSteam.amount / getCapacity()) + .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_STEAM, 10) + .setDirection(ProgressBar.Direction.UP) + .setPos(70, 25) + .setSize(10, 54)) + .widget(new ProgressBar() + .setProgress(() -> mFluid == null ? 0 : (float) mFluid.amount / getCapacity()) + .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_WATER, 10) + .setDirection(ProgressBar.Direction.UP) + .setPos(83, 25) + .setSize(10, 54)) + .widget(new ProgressBar() + .setProgress(() -> (float) mTemperature / maxProgresstime()) + .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_HEAT, 10) + .setDirection(ProgressBar.Direction.UP) + .setPos(96, 25) + .setSize(10, 54)) + .widget(new ProgressBar() + // cap minimum so that one can easily see there's fuel remaining + .setProgress( + () -> mProcessingEnergy > 0 ? Math.max((float) mProcessingEnergy / 1000, 1f / 5) : 0) + .setTexture(getProgressbarFuel(), 14) + .setDirection(ProgressBar.Direction.UP) + .setPos(116, 45) + .setSize(14, 14)) + .widget(new DrawableWidget() + .setDrawable(getOverlaySlotCanister()) + .setPos(43, 43) + .setSize(18, 18)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.STEAM.apply(getSteamVariant()); + } + + @Override + public int getTitleColor() { + return getSteamVariant() == SteamVariant.BRONZE ? COLOR_TITLE.get() : COLOR_TITLE_WHITE.get(); + } + + // for GT++ + + protected IDrawable getOverlaySlotIn() { + return GT_UITextures.OVERLAY_SLOT_IN_STEAM.get(getSteamVariant()); + } + + protected IDrawable getOverlaySlotOut() { + return GT_UITextures.OVERLAY_SLOT_OUT_STEAM.get(getSteamVariant()); + } + + protected IDrawable getOverlaySlotCanister() { + return GT_UITextures.OVERLAY_SLOT_CANISTER_STEAM.get(getSteamVariant()); + } + + protected UITexture getProgressbarEmpty() { + return GT_UITextures.PROGRESSBAR_BOILER_EMPTY_STEAM.get(getSteamVariant()); + } + + protected UITexture getProgressbarFuel() { + return GT_UITextures.PROGRESSBAR_FUEL_STEAM.get(getSteamVariant()); + } } diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java index 9d3c61fc82..ef343d24f2 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java @@ -16,6 +16,7 @@ import gregtech.GT_Mod; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.ParticleFX; +import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -25,10 +26,7 @@ import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; import gregtech.common.GT_Pollution; -import gregtech.common.gui.GT_Container_Boiler; -import gregtech.common.gui.GT_GUIContainer_Boiler; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.util.ForgeDirection; @@ -93,16 +91,6 @@ public class GT_MetaTileEntity_Boiler_Bronze extends GT_MetaTileEntity_Boiler { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Boiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Boiler(aPlayerInventory, aBaseMetaTileEntity, "BronzeBoiler.png"); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Boiler_Bronze(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); } @@ -318,4 +306,9 @@ public class GT_MetaTileEntity_Boiler_Bronze extends GT_MetaTileEntity_Boiler { 1L)); } } + + @Override + public SteamVariant getSteamVariant() { + return SteamVariant.BRONZE; + } } diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java index 38bef79f38..14a2833549 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java @@ -12,15 +12,13 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE; import gregtech.GT_Mod; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_OreDictUnificator; -import gregtech.common.gui.GT_Container_Boiler; -import gregtech.common.gui.GT_GUIContainer_Boiler; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraftforge.fluids.FluidStack; public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { @@ -86,16 +84,6 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Boiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Boiler(aPlayerInventory, aBaseMetaTileEntity, "SteelBoiler.png"); - } - - @Override public int getCapacity() { return 32000; } @@ -145,6 +133,11 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override + public SteamVariant getSteamVariant() { + return SteamVariant.STEEL; + } + + @Override public final int fill(FluidStack aFluid, boolean doFill) { if ((GT_ModHandler.isLava(aFluid)) && (this.mProcessingEnergy < 50)) { int tFilledAmount = Math.min(50, aFluid.amount); diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java index cccfb1b6b4..d86fd544e7 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java @@ -5,8 +5,11 @@ import static gregtech.api.enums.ConfigCategories.machineconfig; import static mcp.mobius.waila.api.SpecialChars.GOLD; import static mcp.mobius.waila.api.SpecialChars.RESET; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; import gregtech.api.enums.Dyes; +import gregtech.api.enums.SteamVariant; import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -14,13 +17,10 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_Boiler; -import gregtech.common.gui.GT_GUIContainer_Boiler; import java.util.List; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -124,16 +124,6 @@ public class GT_MetaTileEntity_Boiler_Solar extends GT_MetaTileEntity_Boiler { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Boiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Boiler(aPlayerInventory, aBaseMetaTileEntity, "SolarBoiler.png"); - } - - @Override public ITexture[] getTexture( IGregTechTileEntity aBaseMetaTileEntity, byte aSide, @@ -254,6 +244,11 @@ public class GT_MetaTileEntity_Boiler_Solar extends GT_MetaTileEntity_Boiler { } @Override + public SteamVariant getSteamVariant() { + return SteamVariant.BRONZE; + } + + @Override public boolean isGivingInformation() { return true; } @@ -290,6 +285,16 @@ public class GT_MetaTileEntity_Boiler_Solar extends GT_MetaTileEntity_Boiler { } @Override + protected IDrawable[] getFuelSlotBackground() { + return new IDrawable[] {GT_UITextures.TRANSPARENT}; + } + + @Override + protected IDrawable[] getAshSlotBackground() { + return new IDrawable[] {GT_UITextures.TRANSPARENT}; + } + + @Override public void getWailaBody( ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor, IWailaConfigHandler config) { final NBTTagCompound tag = accessor.getNBTData(); diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar_Steel.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar_Steel.java index 223c280ad4..997ca33df5 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar_Steel.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar_Steel.java @@ -3,13 +3,12 @@ package gregtech.common.tileentities.boilers; import static gregtech.api.enums.ConfigCategories.machineconfig; import gregtech.api.enums.Dyes; +import gregtech.api.enums.SteamVariant; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; -import gregtech.common.gui.GT_GUIContainer_Boiler; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Boiler_Solar_Steel extends GT_MetaTileEntity_Boiler_Solar { public GT_MetaTileEntity_Boiler_Solar_Steel(int aID, String aName, String aNameRegional) { @@ -59,13 +58,13 @@ public class GT_MetaTileEntity_Boiler_Solar_Steel extends GT_MetaTileEntity_Boil } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Boiler(aPlayerInventory, aBaseMetaTileEntity, "SolarHPBoiler.png"); + public int getCapacity() { + return 32000; } @Override - public int getCapacity() { - return 32000; + public SteamVariant getSteamVariant() { + return SteamVariant.STEEL; } @Override diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Steel.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Steel.java index b417ece4d5..0ae425f792 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Steel.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Steel.java @@ -10,13 +10,11 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_STEELBRICKS_TOP; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE; import gregtech.GT_Mod; +import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; -import gregtech.common.gui.GT_Container_Boiler; -import gregtech.common.gui.GT_GUIContainer_Boiler; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Boiler_Steel extends GT_MetaTileEntity_Boiler_Bronze { @@ -77,16 +75,6 @@ public class GT_MetaTileEntity_Boiler_Steel extends GT_MetaTileEntity_Boiler_Bro } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Boiler(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Boiler(aPlayerInventory, aBaseMetaTileEntity, "SteelBoiler.png"); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Boiler_Steel(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); } @@ -120,4 +108,9 @@ public class GT_MetaTileEntity_Boiler_Steel extends GT_MetaTileEntity_Boiler_Bro protected int getCooldownInterval() { return 40; } + + @Override + public SteamVariant getSteamVariant() { + return SteamVariant.STEEL; + } } diff --git a/src/main/java/gregtech/common/tileentities/debug/GT_MetaTileEntity_AdvDebugStructureWriter.java b/src/main/java/gregtech/common/tileentities/debug/GT_MetaTileEntity_AdvDebugStructureWriter.java index ae03df5789..663b7ed326 100644 --- a/src/main/java/gregtech/common/tileentities/debug/GT_MetaTileEntity_AdvDebugStructureWriter.java +++ b/src/main/java/gregtech/common/tileentities/debug/GT_MetaTileEntity_AdvDebugStructureWriter.java @@ -6,22 +6,32 @@ import static net.minecraft.util.StatCollector.translateToLocal; import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import com.gtnewhorizon.structurelib.structure.StructureUtility; import com.gtnewhorizon.structurelib.util.Vec3Impl; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.render.TextureFactory; -import gregtech.common.gui.GT_Container_AdvDebugStructureWriter; -import gregtech.common.gui.GT_GUIContainer_AdvDebugStructureWriter; import java.util.HashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; @@ -30,14 +40,15 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; -public class GT_MetaTileEntity_AdvDebugStructureWriter extends GT_MetaTileEntity_TieredMachineBlock { +public class GT_MetaTileEntity_AdvDebugStructureWriter extends GT_MetaTileEntity_TieredMachineBlock + implements IAddGregtechLogo, IAddUIWidgets { private static final HashMap<GT_MetaTileEntity_AdvDebugStructureWriter, BoundHighlighter> bondingBoxes = new HashMap<>(1); private final BoundHighlighter boundingBox = new BoundHighlighter(); - public short[] numbers = new short[6]; - public boolean transpose = false; - public boolean showHighlightBox = true; - public String[] result = new String[] {"Undefined"}; + private final short[] numbers = new short[6]; + private boolean transpose = false; + private boolean showHighlightBox = true; + private String[] result = new String[] {"Undefined"}; public GT_MetaTileEntity_AdvDebugStructureWriter(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 0, ""); @@ -81,16 +92,6 @@ public class GT_MetaTileEntity_AdvDebugStructureWriter extends GT_MetaTileEntity } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_AdvDebugStructureWriter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_AdvDebugStructureWriter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public boolean allowPutStack(IGregTechTileEntity iGregTechTileEntity, int i, byte b, ItemStack itemStack) { return false; } @@ -193,10 +194,7 @@ public class GT_MetaTileEntity_AdvDebugStructureWriter extends GT_MetaTileEntity @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -235,6 +233,104 @@ public class GT_MetaTileEntity_AdvDebugStructureWriter extends GT_MetaTileEntity return result; } + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setSize(90, 112) + .setPos(43, 4)) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + if (getBaseMetaTileEntity().isServerSide()) { + printStructure(widget.getContext().getPlayer()); + } + }) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_PRINT) + .setSize(18, 18) + .setPos(11, 128) + .addTooltip(translateToLocal("GT5U.machines.advdebugstructurewriter.gui.print.tooltip"))) + .widget(new CycleButtonWidget() + .setToggle(() -> transpose, aBoolean -> transpose = aBoolean) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_TRANSPOSE) + .setSize(18, 18) + .setPos(32, 128) + .addTooltip(translateToLocal("GT5U.machines.advdebugstructurewriter.gui.transpose.tooltip"))) + .widget(new CycleButtonWidget() + .setToggle(() -> showHighlightBox, aBoolean -> showHighlightBox = aBoolean) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_BOUNDING_BOX) + .setSize(18, 18) + .setPos(53, 128) + .addTooltip(translateToLocal("GT5U.machines.advdebugstructurewriter.gui.highlight.tooltip"))) + .widget(new MultiChildWidget() + .addChild(new TextWidget(translateToLocal("GT5U.machines.advdebugstructurewriter.gui.origin")) + .setDefaultColor(0xf0f0ff) + .setPos(0, 0)) + .addChild(TextWidget.dynamicString(() -> "A: " + numbers[0]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 10)) + .addChild(TextWidget.dynamicString(() -> "B: " + numbers[1]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 18)) + .addChild(TextWidget.dynamicString(() -> "C: " + numbers[2]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 26)) + .addChild(new TextWidget(translateToLocal("GT5U.machines.advdebugstructurewriter.gui.size")) + .setDefaultColor(0xf0f0ff) + .setPos(0, 52)) + .addChild(TextWidget.dynamicString(() -> "A: " + numbers[3]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 62)) + .addChild(TextWidget.dynamicString(() -> "B: " + numbers[4]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 70)) + .addChild(TextWidget.dynamicString(() -> "C: " + numbers[5]) + .setDefaultColor(0xf0f0ff) + .setPos(0, 78)) + .setPos(46, 8)); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, -512, -64, 7); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, -16, -1, 25); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, 16, 1, 133); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, 512, 64, 151); + } + + private void addChangeNumberButtons( + ModularWindow.Builder builder, IDrawable overlay, int addNumberShift, int addNumber, int xPos) { + int[] yPos = new int[] {4, 22, 40, 62, 80, 98}; + for (int i = 0; i < yPos.length; i++) { + final int index = i; // needed for lambda + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> numbers[index] += clickData.shift ? addNumberShift : addNumber) + .setBackground(GT_UITextures.BUTTON_STANDARD, overlay) + .setSize(18, 18) + .setPos(xPos, yPos[index])); + } + } + + @Override + public GUITextureSet getGUITextureSet() { + return new GUITextureSet().setGregTechLogo(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT_GRAY); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(113, 96)); + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } + public static class ForgeEventHandler { public ForgeEventHandler() { MinecraftForge.EVENT_BUS.register(this); diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java index dfc013fe49..d7619da823 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java @@ -16,26 +16,33 @@ import appeng.me.GridAccessException; import appeng.me.helpers.AENetworkProxy; import appeng.me.helpers.IGridProxyable; import appeng.util.item.AEItemStack; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; import gregtech.api.enums.ItemList; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.metatileentity.IConfigurationCircuitSupport; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; import gregtech.api.render.TextureFactory; -import gregtech.common.gui.GT_Container_InputBus_ME; -import gregtech.common.gui.GT_GUIContainer_InputBus_ME; +import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.widget.AESlotWidget; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch_InputBus - implements IConfigurationCircuitSupport { + implements IConfigurationCircuitSupport, IAddGregtechLogo, IAddUIWidgets { private static final int SLOT_COUNT = 16; private BaseActionSource requestSource = null; private AENetworkProxy gridProxy = null; @@ -72,16 +79,6 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_InputBus_ME(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_InputBus_ME(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) { super.onFirstTick(aBaseMetaTileEntity); getProxy().onReady(); @@ -250,10 +247,12 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch } } + @Override public void startRecipeProcessing() { processingRecipe = true; } + @Override public void endRecipeProcessing() { if (GregTech_API.mAE2) { for (int i = 0; i < SLOT_COUNT; ++i) { @@ -310,4 +309,63 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch public boolean isValidSlot(int aIndex) { return false; } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + final SlotWidget[] aeSlotWidgets = new SlotWidget[16]; + builder.widget(SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(0) + .endAtSlot(15) + .phantom(true) + .background(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_ARROW_ME) + .widgetCreator(slot -> new SlotWidget(slot) { + @Override + protected void phantomClick(ClickData clickData, ItemStack cursorStack) { + if (clickData.mouseButton != 0) return; + final int aSlotIndex = getMcSlot().getSlotIndex(); + if (cursorStack == null) { + getMcSlot().putStack(null); + } else { + if (containsSuchStack(cursorStack)) return; + getMcSlot().putStack(GT_Utility.copyAmount(1L, cursorStack)); + } + if (getBaseMetaTileEntity().isServerSide()) { + final ItemStack newInfo = updateInformationSlot(aSlotIndex, cursorStack); + aeSlotWidgets[getMcSlot().getSlotIndex()] + .getMcSlot() + .putStack(newInfo); + } + } + + private boolean containsSuchStack(ItemStack tStack) { + for (int i = 0; i < 16; ++i) { + if (GT_Utility.areStacksEqual(mInventory[i], tStack, false)) return true; + } + return false; + } + }) + .build() + .setPos(7, 9)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 4) + .startFromSlot(16) + .endAtSlot(31) + .phantom(true) + .background(GT_UITextures.SLOT_DARK_GRAY) + .widgetCreator(slot -> + aeSlotWidgets[slot.getSlotIndex() - 16] = new AESlotWidget(slot).disableInteraction()) + .build() + .setPos(97, 9)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_ARROW_DOUBLE) + .setPos(82, 40) + .setSize(12, 12)); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(80, 63)); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java index 66209fec4f..ed0ca51231 100644 --- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java +++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_OutputBus_ME.java @@ -283,4 +283,9 @@ public class GT_MetaTileEntity_Hatch_OutputBus_ME extends GT_MetaTileEntity_Hatc } return ss.toArray(new String[itemCache.size() + 2]); } + + @Override + public boolean useModularUI() { + return false; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CuringOven.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CuringOven.java index dc5c976eac..3dc9fd7b63 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CuringOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CuringOven.java @@ -1,21 +1,21 @@ package gregtech.common.tileentities.machines.basic; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; -import gregtech.api.gui.GT_Container_1by1; -import gregtech.api.gui.GT_GUIContainer_1by1; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.render.TextureFactory; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; -public class GT_MetaTileEntity_CuringOven extends GT_MetaTileEntity_BasicMachine { +public class GT_MetaTileEntity_CuringOven extends GT_MetaTileEntity_BasicMachine implements IAddUIWidgets { public GT_MetaTileEntity_CuringOven(int aID, String aName, String aNameRegional, int aTier) { super( @@ -76,16 +76,6 @@ public class GT_MetaTileEntity_CuringOven extends GT_MetaTileEntity_BasicMachine } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_1by1(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_1by1(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - - @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { for (ItemStack tStack : mInventory) @@ -120,4 +110,14 @@ public class GT_MetaTileEntity_CuringOven extends GT_MetaTileEntity_BasicMachine } } } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + getBaseMetaTileEntity().add1by1Slot(builder); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index 81e7ece86f..ff46aada64 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -605,4 +605,16 @@ public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachi && aStack.getTagCompound() != null && aStack.getTagCompound().getCompoundTag("GT.CraftingComponents") != null; } + + @Override + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes; + } + + // GUI stuff + + @Override + public boolean hasNEITransferRect() { + return false; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java index b1e6b1cc2f..557b01fbb0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_IndustrialApiary.java @@ -3,9 +3,28 @@ package gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.AuthorKuba; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.Textures.BlockIcons.*; +import static gregtech.api.metatileentity.BaseTileEntity.STALLED_STUTTERING_TOOLTIP; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; import static gregtech.api.util.GT_Utility.moveMultipleItemStacks; import com.google.common.collect.ImmutableSet; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.builder.UIInfo; +import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import com.mojang.authlib.GameProfile; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -19,7 +38,11 @@ import forestry.apiculture.genetics.Bee; import forestry.apiculture.genetics.alleles.AlleleEffectThrottled; import forestry.core.errors.EnumErrorCode; import forestry.plugins.PluginApiculture; +import gregtech.GT_Mod; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; @@ -28,27 +51,28 @@ import gregtech.api.util.GT_ApiaryModifier; import gregtech.api.util.GT_ApiaryUpgrade; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Client; -import gregtech.common.gui.GT_Container_IndustrialApiary; -import gregtech.common.gui.GT_GUIContainer_IndustrialApiary; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.lang.reflect.Field; import java.util.*; +import java.util.stream.Collectors; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraft.world.biome.BiomeGenBase; public class GT_MetaTileEntity_IndustrialApiary extends GT_MetaTileEntity_BasicMachine - implements IBeeHousing, IBeeHousingInventory, IErrorLogic, IBeeModifier, IBeeListener { + implements IBeeHousing, IBeeHousingInventory, IErrorLogic, IBeeModifier, IBeeListener, IAddUIWidgets { public static final int beeCycleLength = 550; public static final int baseEUtUsage = 37; @@ -149,13 +173,29 @@ public class GT_MetaTileEntity_IndustrialApiary extends GT_MetaTileEntity_BasicM } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_IndustrialApiary(aPlayerInventory, aBaseMetaTileEntity); + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) return true; + if (!GT_Mod.gregtechproxy.mForceFreeFace) { + openGUI(aBaseMetaTileEntity, aPlayer); + return true; + } + for (byte i = 0; i < 6; i++) { + if (aBaseMetaTileEntity.getAirAtSide(i)) { + openGUI(aBaseMetaTileEntity, aPlayer); + return true; + } + } + GT_Utility.sendChatToPlayer(aPlayer, "No free Side!"); + return true; } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_IndustrialApiary(aPlayerInventory, aBaseMetaTileEntity); + private void openGUI(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + IndustrialApiaryUI.open( + aPlayer, + aBaseMetaTileEntity.getWorld(), + aBaseMetaTileEntity.getXCoord(), + aBaseMetaTileEntity.getYCoord(), + aBaseMetaTileEntity.getZCoord()); } @Override @@ -1036,4 +1076,305 @@ public class GT_MetaTileEntity_IndustrialApiary extends GT_MetaTileEntity_BasicM @Override public void writeToNBT(NBTTagCompound nbtTagCompound) {} }; + + private static final String POWER_SOURCE_POWER = "GT5U.machines.powersource.power", + CANCEL_PROCESS_TOOLTIP = "GT5U.machines.industrialapiary.cancel.tooltip", + SPEED_TOOLTIP = "GT5U.machines.industrialapiary.speed.tooltip", + SPEED_LOCKED_TOOLTIP = "GT5U.machines.industrialapiary.speedlocked.tooltip", + INFO_TOOLTIP = "GT5U.machines.industrialapiary.info.tooltip", + INFO_WITH_BEE_TOOLTIP = "GT5U.machines.industrialapiary.infoextended.tooltip", + UPGRADE_TOOLTIP = "GT5U.machines.industrialapiary.upgradeslot.tooltip"; + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new SlotWidget(new ApiarySlot(inventoryHandler, queen)) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_BEE_QUEEN) + .setPos(36, 21)) + .widget(new SlotWidget(new ApiarySlot(inventoryHandler, drone)) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_BEE_DRONE) + .setPos(36, 41)) + .widget(SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(7) + .endAtSlot(10) + .slotCreator(i -> new ApiarySlot(inventoryHandler, i)) + .applyForWidget(widget -> widget.setGTTooltip(() -> mTooltipCache.getData(UPGRADE_TOOLTIP)) + .setTooltipShowUpDelay(TOOLTIP_DELAY)) + .build() + .setPos(61, 23)); + + super.addUIWidgets(builder, buildContext); + + builder.widget(new ProgressBar() + .setProgress(() -> (float) getProgresstime() / Math.max(maxProgresstime(), 1)) + .setTexture(GT_UITextures.PROGRESSBAR_ARROW, 20) + .setPos(70, 3) + .setSize(20, 18)) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> cancelProcess()) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_CROSS) + .setGTTooltip(() -> mTooltipCache.getData(CANCEL_PROCESS_TOOLTIP)) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(7, 26) + .setSize(18, 18)) + .widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_INFORMATION) + .setGTTooltip(() -> { + String energyreq = GT_Utility.formatNumbers( + (int) ((float) GT_MetaTileEntity_IndustrialApiary.baseEUtUsage + * getEnergyModifier() + * getAcceleration()) + + getAdditionalEnergyUsage()); + String Temp = StatCollector.translateToLocal( + getTemperature().getName()); + String Hum = + StatCollector.translateToLocal(getHumidity().getName()); + if (getUsedQueen() != null + && BeeManager.beeRoot.isMember(getUsedQueen(), EnumBeeType.QUEEN.ordinal())) { + IBee bee = BeeManager.beeRoot.getMember(getUsedQueen()); + if (bee.isAnalyzed()) { + IBeeGenome genome = bee.getGenome(); + IBeeModifier mod = BeeManager.beeRoot + .getBeekeepingMode(getWorld()) + .getBeeModifier(); + float tmod = getTerritoryModifier(null, 1f) * mod.getTerritoryModifier(null, 1f); + int[] t = Arrays.stream(genome.getTerritory()) + .map(i -> (int) ((float) i * tmod)) + .toArray(); + return mTooltipCache.getUncachedTooltipData( + INFO_WITH_BEE_TOOLTIP, + energyreq, + Temp, + Hum, + genome.getSpeed(), + getProductionModifier(null, 1f) * mod.getProductionModifier(null, 1f), + Math.round(getFloweringModifier(null, 1f) + * genome.getFlowering() + * mod.getFloweringModifier(null, 1f)), + Math.round(getLifespanModifier(null, null, 1f) + * genome.getLifespan() + * mod.getLifespanModifier(null, null, 1f)), + t[0], + t[1], + t[2]); + } + } + return mTooltipCache.getUncachedTooltipData(INFO_TOOLTIP, energyreq, Temp, Hum); + }) + .attachSyncer( + new FakeSyncWidget.ItemStackSyncer(() -> usedQueen, val -> usedQueen = val), + builder, + (widget, val) -> widget.notifyTooltipChange()) + .setPos(163, 5) + .setSize(7, 18)) + .widget(new ButtonWidget() + .setOnClick((clickData, widget) -> { + if (clickData.mouseButton == 0) { + if (mLockedSpeed) return; + if (!clickData.shift) { + mSpeed++; + if (mSpeed > getMaxSpeed()) mSpeed = 0; + } else { + mSpeed--; + if (mSpeed < 0) mSpeed = getMaxSpeed(); + } + } else if (clickData.mouseButton == 1) { + mLockedSpeed = !mLockedSpeed; + if (mLockedSpeed) mSpeed = getMaxSpeed(); + } + }) + .setGTTooltip(() -> mTooltipCache.getUncachedTooltipData( + mLockedSpeed ? SPEED_LOCKED_TOOLTIP : SPEED_TOOLTIP, + getAcceleration(), + GT_Utility.formatNumbers(getAdditionalEnergyUsage()))) + .attachSyncer( + new FakeSyncWidget.IntegerSyncer(() -> mSpeed, val -> mSpeed = val), + builder, + (widget, val) -> widget.notifyTooltipChange()) + .attachSyncer( + new FakeSyncWidget.BooleanSyncer(() -> mLockedSpeed, val -> mLockedSpeed = val), + builder, + (widget, val) -> widget.notifyTooltipChange()) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setBackground(GT_UITextures.PICTURE_SQUARE_LIGHT_GRAY) + .setPos(25, 62) + .setSize(18, 18)) + .widget(new TextWidget("x") + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(30, 63)) + .widget(TextWidget.dynamicString(() -> String.valueOf(1 << mSpeed)) + // mSpeed is already synced + .setSynced(false) + .setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(26, 72)); + } + + @Override + protected SlotWidget createItemInputSlot(int index, IDrawable[] backgrounds, Pos2d pos) { + // we have custom input slots + return null; + } + + @Override + protected CycleButtonWidget createItemAutoOutputButton() { + return (CycleButtonWidget) super.createItemAutoOutputButton().setPos(7, 62); + } + + @Override + protected CycleButtonWidget createFluidAutoOutputButton() { + return null; + } + + @Override + protected SlotWidget createChargerSlot(int x, int y, String tooltipKey, Object[] tooltipArgs) { + return (SlotWidget) + super.createChargerSlot(x, y, tooltipKey, tooltipArgs).setPos(79, 62); + } + + @Override + protected DrawableWidget createErrorStatusArea(ModularWindow.Builder builder, IDrawable picture) { + return (DrawableWidget) super.createErrorStatusArea(builder, picture) + .setPos(100, 62) + .attachSyncer( + new FakeSyncWidget.ListSyncer<>( + () -> Arrays.asList(mErrorStates.toArray(new IErrorState[0])), + val -> { + mErrorStates.clear(); + mErrorStates.addAll(new HashSet<>(val)); + }, + (buffer, val) -> buffer.writeShort(val.getID()), + buffer -> ForestryAPI.errorStateRegistry.getErrorState(buffer.readShort())), + builder, + (widget, val) -> widget.notifyTooltipChange()); + } + + @Override + protected List<String> getErrorDescriptions() { + if (!mErrorStates.isEmpty()) { + return mErrorStates.stream() + .map(state -> + EnumChatFormatting.RED + StatCollector.translateToLocal("for." + state.getDescription())) + .collect(Collectors.toList()); + } else if (mStuttering) { + return mTooltipCache.getData(STALLED_STUTTERING_TOOLTIP, StatCollector.translateToLocal(POWER_SOURCE_POWER)) + .text; + } else { + return Collections.emptyList(); + } + } + + @Override + protected List<String> getErrorDescriptionsShift() { + // Don't show shift tooltip of "Progress was lost" + // as this machine does not lose progress + return getErrorDescriptions(); + } + + private int getAcceleration() { + return 1 << mSpeed; + } + + private int getAdditionalEnergyUsage() { + int accelerated = getAcceleration(); + int energyusage = 0; + if (accelerated == 2) energyusage = 32; + else if (accelerated > 2) energyusage = 32 * accelerated << (mSpeed - 2); + return energyusage; + } + + private class ApiarySlot extends BaseSlot { + + public ApiarySlot(IItemHandlerModifiable inventory, int index) { + super(inventory, index); + } + + @Override + public boolean isItemValidPhantom(ItemStack stack) { + return super.isItemValidPhantom(stack) && getBaseMetaTileEntity().isItemValidForSlot(getSlotIndex(), stack); + } + + @Override + public void onSlotChanged() { + super.onSlotChanged(); + onInventoryUpdate(getSlotIndex()); + } + } + + private static final UIInfo<?, ?> IndustrialApiaryUI = + GT_UIInfos.GTTileEntityUIFactory.apply(GT_ModularUIContainer_IndustrialApiary::new); + + private static class GT_ModularUIContainer_IndustrialApiary extends ModularUIContainer { + + public GT_ModularUIContainer_IndustrialApiary(ModularUIContext context, ModularWindow mainWindow) { + super(context, mainWindow); + } + + private final int playerInventorySlot = 36; + + @Override + public ItemStack slotClick(int aSlotNumber, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (!(aSlotNumber >= playerInventorySlot + 2 && aSlotNumber < playerInventorySlot + 2 + 4)) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if (aShifthold == 5) return null; + if (aShifthold != 0) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if (aMouseclick > 1) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + ItemStack s = aPlayer.inventory.getItemStack(); + if (s == null) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + Slot slot = getSlot(aSlotNumber); + ItemStack slotStack = slot.getStack(); + if (slotStack != null && !GT_Utility.areStacksEqual(slotStack, s)) return null; // super would replace item + if (slotStack == null && !slot.isItemValid(s)) + return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + if (!GT_ApiaryUpgrade.isUpgrade(s)) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + int max = GT_ApiaryUpgrade.getUpgrade(s).getMaxNumber(); + if (slotStack != null) max = Math.max(0, max - slotStack.stackSize); + max = Math.min(max, s.stackSize); + if (max == 0) return null; + if (aMouseclick == 1) max = 1; + if (max == s.stackSize) return super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + ItemStack newStack = s.splitStack(s.stackSize - max); + ItemStack result = super.slotClick(aSlotNumber, aMouseclick, aShifthold, aPlayer); + aPlayer.inventory.setItemStack(newStack); + return result; + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer aPlayer, int aSlotIndex) { + Slot s = getSlot(aSlotIndex); + if (s == null) return super.transferStackInSlot(aPlayer, aSlotIndex); + if (aSlotIndex >= playerInventorySlot) return super.transferStackInSlot(aPlayer, aSlotIndex); + ItemStack aStack = s.getStack(); + if (aStack == null) return super.transferStackInSlot(aPlayer, aSlotIndex); + if (!GT_ApiaryUpgrade.isUpgrade(aStack)) return super.transferStackInSlot(aPlayer, aSlotIndex); + for (int i = playerInventorySlot + 2; i < playerInventorySlot + 2 + 4; i++) { + Slot iSlot = getSlot(i); + ItemStack iStack = iSlot.getStack(); + if (iStack == null) { + if (!iSlot.isItemValid(aStack)) continue; + } else { + if (!GT_Utility.areStacksEqual(aStack, iStack)) continue; + } + int max = GT_ApiaryUpgrade.getUpgrade(aStack).getMaxNumber(); + if (iStack == null) { + max = Math.min(max, aStack.stackSize); + ItemStack newstack = aStack.splitStack(max); + iSlot.putStack(newstack); + } else { + max = Math.max(0, max - iStack.stackSize); + max = Math.min(max, aStack.stackSize); + iStack.stackSize += max; + aStack.stackSize -= max; + iSlot.onSlotChanged(); + } + if (aStack.stackSize == 0) s.putStack(null); + else s.onSlotChanged(); + break; + } + return null; + } + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java index 8616b98fae..14a213b156 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_MicrowaveEnergyTransmitter.java @@ -7,11 +7,23 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_ACTIVE; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_GLOW; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.Materials; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IEnergyConnected; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; @@ -19,10 +31,8 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_MicrowaveEnergyTransmitter; -import gregtech.common.gui.GT_GUIContainer_MicrowaveEnergyTransmitter; +import java.util.function.Consumer; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; @@ -30,7 +40,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fluids.FluidStack; -public class GT_MetaTileEntity_MicrowaveEnergyTransmitter extends GT_MetaTileEntity_BasicTank { +public class GT_MetaTileEntity_MicrowaveEnergyTransmitter extends GT_MetaTileEntity_BasicTank + implements IAddGregtechLogo, IAddUIWidgets { private static boolean sInterDimensionalTeleportAllowed = true; private static int mMaxLoss = 50; @@ -71,21 +82,11 @@ public class GT_MetaTileEntity_MicrowaveEnergyTransmitter extends GT_MetaTileEnt public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; this.hasBlock = checkForBlock(); - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_MicrowaveEnergyTransmitter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MicrowaveEnergyTransmitter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_MicrowaveEnergyTransmitter( this.mName, this.mTier, this.mDescriptionArray, this.mTextures); @@ -415,4 +416,82 @@ public class GT_MetaTileEntity_MicrowaveEnergyTransmitter extends GT_MetaTileEnt public ITexture[][][] getTextureSet(ITexture[] aTextures) { return null; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setSize(90, 72) + .setPos(43, 4)) + .widget(TextWidget.dynamicString(() -> "X: " + GT_Utility.parseNumberToString(mTargetX)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 8)) + .widget(TextWidget.dynamicString(() -> "Y: " + GT_Utility.parseNumberToString(mTargetY)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 16)) + .widget(TextWidget.dynamicString(() -> "Z: " + GT_Utility.parseNumberToString(mTargetZ)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 24)) + .widget(TextWidget.dynamicString(() -> "Dim: " + GT_Utility.parseNumberToString(mTargetD)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 32)) + .widget(TextWidget.dynamicString( + () -> "Dim Valid: " + (GT_Utility.isRealDimension(mTargetD) ? "Yes" : "No")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> hasDimensionalTeleportCapability()) + .setPos(46, 40)) + .widget(new FakeSyncWidget.FluidStackSyncer(() -> mFluid, val -> mFluid = val)); + + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, -512, -64, 7); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, -16, -1, 25); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, 16, 1, 133); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, 512, 64, 151); + + addChangeNumberButton( + builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, val -> mTargetD += val, -16, -8, 7, 58); + addChangeNumberButton( + builder, GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, val -> mTargetD += val, -4, -1, 25, 58); + addChangeNumberButton(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, val -> mTargetD += val, 4, 1, 133, 58); + addChangeNumberButton(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, val -> mTargetD += val, 16, 8, 151, 58); + } + + private void addChangeNumberButtons( + ModularWindow.Builder builder, IDrawable overlay, int addNumberShift, int addNumber, int xPos) { + addChangeNumberButton(builder, overlay, val -> mTargetX += val, addNumberShift, addNumber, xPos, 4); + addChangeNumberButton(builder, overlay, val -> mTargetY += val, addNumberShift, addNumber, xPos, 22); + addChangeNumberButton(builder, overlay, val -> mTargetZ += val, addNumberShift, addNumber, xPos, 40); + } + + private void addChangeNumberButton( + ModularWindow.Builder builder, + IDrawable overlay, + Consumer<Integer> setter, + int addNumberShift, + int addNumber, + int xPos, + int yPos) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> setter.accept(clickData.shift ? addNumberShift : addNumber)) + .setBackground(GT_UITextures.BUTTON_STANDARD, overlay) + .setSize(18, 18) + .setPos(xPos, yPos)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return new GUITextureSet().setGregTechLogo(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT_GRAY); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(113, 56)); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java index 67ad6c3a5c..17e9e94b9c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java @@ -3,9 +3,16 @@ package gregtech.common.tileentities.machines.basic; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.debugBlockMiner; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.render.TextureFactory; @@ -28,7 +35,8 @@ import net.minecraft.world.ChunkPosition; import net.minecraftforge.common.util.FakePlayer; @SuppressWarnings("ObjectEquality") -public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine implements GT_IDrillingLogicDelegateOwner { +public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine + implements GT_IDrillingLogicDelegateOwner, IAddUIWidgets { static final int[] RADIUS = {8, 8, 16, 24, 32}; // Miner radius per tier static final int[] SPEED = {160, 160, 80, 40, 20}; // Miner cycle time per tier static final int[] ENERGY = {8, 8, 32, 128, 512}; // Miner energy consumption per tier @@ -424,4 +432,20 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine impl public GT_DrillingLogicDelegate getPipe() { return pipe; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + super.addUIWidgets(builder, buildContext); + builder.widget(createProgressBar( + GT_UITextures.PROGRESSBAR_CANNER, + 20, + ProgressBar.Direction.RIGHT, + new Pos2d(78, 24), + new Size(20, 18))); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java index 213b02e223..26eed71b41 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java @@ -4,8 +4,7 @@ import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.debugBlockPump; import gregtech.api.enums.Textures; -import gregtech.api.gui.GT_Container_BasicTank; -import gregtech.api.gui.GT_GUIContainer_BasicTank; +import gregtech.api.gui.modularui.GT_UIInfos; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -22,7 +21,6 @@ import java.util.HashSet; import java.util.Set; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -172,16 +170,6 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_BasicTank(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicTank(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - - @Override public boolean doesFillContainers() { return true; } @@ -672,8 +660,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) return true; - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -838,4 +825,9 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { + StatCollector.translateToLocal("GT5U.machines.blocks") }; } + + @Override + public boolean useModularUI() { + return true; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java index 9dc00109cf..0d09c59832 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Teleporter.java @@ -9,17 +9,28 @@ import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_GLOW; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_SIDES; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TELEPORTER_SIDES_GLOW; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.api.enums.ConfigCategories; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Config; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_Teleporter; -import gregtech.common.gui.GT_GUIContainer_Teleporter; import java.util.List; +import java.util.function.Consumer; import net.minecraft.client.particle.EntityFX; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityHanging; @@ -36,7 +47,6 @@ import net.minecraft.entity.item.EntityMinecart; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.entity.projectile.EntityFireball; import net.minecraft.entity.projectile.EntityFishHook; @@ -50,7 +60,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fluids.FluidStack; -public class GT_MetaTileEntity_Teleporter extends GT_MetaTileEntity_BasicTank { +public class GT_MetaTileEntity_Teleporter extends GT_MetaTileEntity_BasicTank + implements IAddGregtechLogo, IAddUIWidgets { private static boolean sInterDimensionalTeleportAllowed = true; private static int sPassiveEnergyDrain = 2048; @@ -164,21 +175,11 @@ public class GT_MetaTileEntity_Teleporter extends GT_MetaTileEntity_BasicTank { public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { if (aBaseMetaTileEntity.isClientSide()) return true; // this.hasEgg = checkForEgg(); - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_Teleporter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_Teleporter(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Teleporter(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); } @@ -605,4 +606,82 @@ public class GT_MetaTileEntity_Teleporter extends GT_MetaTileEntity_BasicTank { public ITexture[][][] getTextureSet(ITexture[] aTextures) { return null; } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setSize(90, 72) + .setPos(43, 4)) + .widget(TextWidget.dynamicString(() -> "X: " + GT_Utility.parseNumberToString(mTargetX)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 8)) + .widget(TextWidget.dynamicString(() -> "Y: " + GT_Utility.parseNumberToString(mTargetY)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 16)) + .widget(TextWidget.dynamicString(() -> "Z: " + GT_Utility.parseNumberToString(mTargetZ)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 24)) + .widget(TextWidget.dynamicString(() -> "Dim: " + GT_Utility.parseNumberToString(mTargetD)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(46, 32)) + .widget(TextWidget.dynamicString( + () -> "Dim Valid: " + (GT_Utility.isRealDimension(mTargetD) ? "Yes" : "No")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> hasDimensionalTeleportCapability()) + .setPos(46, 40)) + .widget(new FakeSyncWidget.FluidStackSyncer(() -> mFluid, val -> mFluid = val)); + + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, -512, -64, 7); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, -16, -1, 25); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, 16, 1, 133); + addChangeNumberButtons(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, 512, 64, 151); + + addChangeNumberButton( + builder, GT_UITextures.OVERLAY_BUTTON_MINUS_LARGE, val -> mTargetD += val, -16, -8, 7, 58); + addChangeNumberButton( + builder, GT_UITextures.OVERLAY_BUTTON_MINUS_SMALL, val -> mTargetD += val, -4, -1, 25, 58); + addChangeNumberButton(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_SMALL, val -> mTargetD += val, 4, 1, 133, 58); + addChangeNumberButton(builder, GT_UITextures.OVERLAY_BUTTON_PLUS_LARGE, val -> mTargetD += val, 16, 8, 151, 58); + } + + private void addChangeNumberButtons( + ModularWindow.Builder builder, IDrawable overlay, int addNumberShift, int addNumber, int xPos) { + addChangeNumberButton(builder, overlay, val -> mTargetX += val, addNumberShift, addNumber, xPos, 4); + addChangeNumberButton(builder, overlay, val -> mTargetY += val, addNumberShift, addNumber, xPos, 22); + addChangeNumberButton(builder, overlay, val -> mTargetZ += val, addNumberShift, addNumber, xPos, 40); + } + + private void addChangeNumberButton( + ModularWindow.Builder builder, + IDrawable overlay, + Consumer<Integer> setter, + int addNumberShift, + int addNumber, + int xPos, + int yPos) { + builder.widget(new ButtonWidget() + .setOnClick((clickData, widget) -> setter.accept(clickData.shift ? addNumberShift : addNumber)) + .setBackground(GT_UITextures.BUTTON_STANDARD, overlay) + .setSize(18, 18) + .setPos(xPos, yPos)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return new GUITextureSet().setGregTechLogo(GT_UITextures.PICTURE_GT_LOGO_17x17_TRANSPARENT_GRAY); + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(113, 56)); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java index 68aab6ee00..e5b7110659 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java @@ -20,7 +20,6 @@ import gregtech.api.enums.ItemList; import gregtech.api.enums.SoundResource; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -38,7 +37,6 @@ import gregtech.api.util.IGT_HatchAdder; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -195,12 +193,6 @@ public class GT_MetaTileEntity_AssemblyLine } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "AssemblyLine.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return null; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BrickedBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BrickedBlastFurnace.java index bec9072c80..7536735634 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BrickedBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BrickedBlastFurnace.java @@ -2,6 +2,7 @@ package gregtech.common.tileentities.machines.multi; import gregtech.GT_Mod; import gregtech.api.GregTech_API; +import gregtech.api.enums.SteamVariant; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; import gregtech.api.interfaces.ISecondaryDescribable; @@ -111,6 +112,11 @@ public class GT_MetaTileEntity_BrickedBlastFurnace extends GT_MetaTileEntity_Pri } @Override + public SteamVariant getSteamVariant() { + return SteamVariant.PRIMITIVE; + } + + @Override public String[] getStructureDescription(ItemStack stackSize) { return getTooltip().getStructureHint(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BronzeBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BronzeBlastFurnace.java index 3a50f69c5e..734d11e4c8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BronzeBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_BronzeBlastFurnace.java @@ -6,6 +6,7 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBLASTFURNACE_ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEPLATEDBRICKS; import gregtech.api.GregTech_API; +import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -72,6 +73,11 @@ public class GT_MetaTileEntity_BronzeBlastFurnace extends GT_MetaTileEntity_Prim } @Override + public SteamVariant getSteamVariant() { + return SteamVariant.BRONZE; + } + + @Override public String[] getStructureDescription(ItemStack stackSize) { return new String[0]; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java index 2f5ba5681e..0006c8b7d5 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java @@ -7,7 +7,6 @@ import com.gtnewhorizon.structurelib.StructureLibAPI; import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ISecondaryDescribable; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMachineCallback; @@ -22,7 +21,6 @@ import gregtech.api.util.GT_Recipe; import java.util.HashMap; import java.util.Map; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -348,12 +346,6 @@ public class GT_MetaTileEntity_Cleanroom extends GT_MetaTileEntity_TooltipMultiB } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return null; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java index 8c146ed4f9..de477af9e4 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ConcreteBackfillerBase.java @@ -6,13 +6,11 @@ import static gregtech.api.enums.GT_Values.VN; import com.google.common.collect.ImmutableList; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; import java.util.List; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public abstract class GT_MetaTileEntity_ConcreteBackfillerBase extends GT_MetaTileEntity_DrillerBase { @@ -52,12 +50,6 @@ public abstract class GT_MetaTileEntity_ConcreteBackfillerBase extends GT_MetaTi return tt; } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DrillingRig.png"); - } - protected abstract int getRadius(); @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java index 491adf1a18..d6fd5deca4 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DieselEngine.java @@ -21,7 +21,6 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -34,7 +33,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -157,12 +155,6 @@ public class GT_MetaTileEntity_DieselEngine return getMaxEfficiency(aStack) > 0; } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeDieselEngine.png"); - } - // can't use getRecipeMap() or else the fluid hatch will reject oxygen protected GT_Recipe.GT_Recipe_Map_Fuel getFuelMap() { return GT_Recipe.GT_Recipe_Map.sDieselFuels; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java index 7600cac94c..275c1c43a5 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java @@ -21,7 +21,6 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -34,7 +33,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import java.util.List; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -204,12 +202,6 @@ public class GT_MetaTileEntity_DistillationTower } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DistillationTower.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sDistillationRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 18fea79cb5..15f04c5fda 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -16,7 +16,6 @@ import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Materials; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -27,7 +26,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -162,12 +160,6 @@ public class GT_MetaTileEntity_ElectricBlastFurnace } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "ElectricBlastFurnace.png"); - } - - @Override public int getPollutionPerSecond(ItemStack aStack) { return GT_Mod.gregtechproxy.mPollutionEBFPerSecond; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java index 5c7321144f..ca711d3866 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ExtremeDieselEngine.java @@ -9,7 +9,6 @@ import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.Materials; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -20,7 +19,6 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; @@ -107,12 +105,6 @@ public class GT_MetaTileEntity_ExtremeDieselEngine extends GT_MetaTileEntity_Die } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeExtremeDieselEngine.png"); - } - - @Override public Block getCasingBlock() { return GregTech_API.sBlockCasings4; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java index 87271bf9a7..adfefee6c1 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_FusionComputer.java @@ -17,12 +17,22 @@ import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructa import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; -import gregtech.api.gui.GT_Container_MultiMachine; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.*; @@ -31,10 +41,8 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_GUIContainer_FusionReactor; import java.util.ArrayList; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -43,7 +51,7 @@ import net.minecraftforge.fluids.FluidStack; public abstract class GT_MetaTileEntity_FusionComputer extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_MetaTileEntity_FusionComputer> - implements ISurvivalConstructable { + implements ISurvivalConstructable, IAddUIWidgets { public static final String STRUCTURE_PIECE_MAIN = "main"; private static final ClassValue<IStructureDefinition<GT_MetaTileEntity_FusionComputer>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GT_MetaTileEntity_FusionComputer>>() { @@ -160,21 +168,6 @@ public abstract class GT_MetaTileEntity_FusionComputer public abstract long maxEUStore(); @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_FusionReactor( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "FusionComputer.png", - GT_Recipe.GT_Recipe_Map.sFusionRecipes.mNEIName); - } - - @Override public abstract MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity); @Override @@ -559,4 +552,84 @@ public abstract class GT_MetaTileEntity_FusionComputer if (mMachine) return -1; return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 7, 1, 12, elementBudget, env, false, true); } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget(new DrawableWidget() + .setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(155, 145)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return new GUITextureSet().setMainBackground(GT_UITextures.BACKGROUND_FUSION_COMPUTER); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new TextWidget(GT_Utility.trans("138", "Incomplete Structure.")) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setEnabled(widget -> !mMachine) + .setPos(10, 8)) + .widget(new FakeSyncWidget.BooleanSyncer(() -> mMachine, val -> mMachine = val)) + .widget(new TextWidget("Hit with Soft Mallet to (re-)start the Machine if it doesn't start.") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setTextAlignment(Alignment.Center) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && !getBaseMetaTileEntity().isActive()) + .setPos(-getGUIWidth() / 2, 170) + .setSize(getGUIWidth() * 2, 9)) + .widget(new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val))) + .widget(new FakeSyncWidget.BooleanSyncer( + () -> getBaseMetaTileEntity().isActive(), + val -> getBaseMetaTileEntity().setActive(val))) + .widget(new TextWidget("Running perfectly.") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setTextAlignment(Alignment.Center) + .setEnabled(widget -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + && getBaseMetaTileEntity().isActive()) + .setPos(0, 170) + .setSize(getGUIWidth(), 9)) + .widget(new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val))) + .widget(new ProgressBar() + .setProgress(() -> (float) getBaseMetaTileEntity().getStoredEU() + / getBaseMetaTileEntity().getEUCapacity()) + .setDirection(ProgressBar.Direction.RIGHT) + .setTexture(GT_UITextures.PROGRESSBAR_STORED_EU, 147) + .setPos(5, 156) + .setSize(147, 5)) + .widget(TextWidget.dynamicString(() -> { + long energy = getBaseMetaTileEntity().getStoredEU(); + if (energy > 160_000_000L && energy < 160_010_000L) { + energy = 160_000_000L; + } + if (energy > 320_000_000L && energy < 320_010_000L) { + energy = 320_000_000L; + } + if (energy > 640_000_000L && energy < 640_010_000L) { + energy = 640_000_000L; + } + if (energy > 5_120_000_000L && energy < 5_120_080_000L) { + energy = 5_120_000_000L; + } + return GT_Utility.formatNumbers(energy) + " EU"; + }) + .setDefaultColor(COLOR_TEXT_RED.get()) + .setPos(50, 155)) + .widget(new ButtonWidget() + .setNEITransferRect(GT_Recipe.GT_Recipe_Map.sFusionRecipes.mNEIName) + .setBackground(GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_NEI) + .setPos(154, 4) + .setSize(18, 18)); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java index 291641f9c6..6c35a3e9c2 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_HeatExchanger.java @@ -14,7 +14,6 @@ import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -27,7 +26,6 @@ import gregtech.api.util.GT_Log; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -169,12 +167,6 @@ public class GT_MetaTileEntity_HeatExchanger } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeHeatExchanger.png"); - } - - @Override public boolean isCorrectMachinePart(ItemStack aStack) { return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java index 6f55e3c9a3..1b2c690a57 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ImplosionCompressor.java @@ -10,7 +10,6 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.SoundResource; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -20,7 +19,6 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_ImplosionCompressor @@ -104,12 +102,6 @@ public class GT_MetaTileEntity_ImplosionCompressor } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "ImplosionCompressor.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sImplosionRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java index 784e81f1ba..b0c9e55a81 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java @@ -23,7 +23,6 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; @@ -36,7 +35,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidRegistry; @@ -211,12 +209,6 @@ public abstract class GT_MetaTileEntity_LargeBoiler } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeBoiler.png"); - } - - @Override public boolean isCorrectMachinePart(ItemStack aStack) { return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java index 539b114868..ce1031e284 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java @@ -13,7 +13,6 @@ import com.gtnewhorizon.structurelib.structure.*; import com.gtnewhorizon.structurelib.util.ItemStackPredicate; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -30,7 +29,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; @@ -150,12 +148,6 @@ public class GT_MetaTileEntity_LargeChemicalReactor } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeChemicalReactor.png"); - } - - @Override public boolean isCorrectMachinePart(ItemStack aStack) { return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java index 9838076440..978456c435 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeTurbine.java @@ -11,7 +11,6 @@ import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.IStructureElementCheckOnly; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; @@ -21,7 +20,6 @@ import gregtech.api.util.GT_Utility; import gregtech.common.items.GT_MetaGenerated_Tool_01; import java.util.ArrayList; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -96,12 +94,6 @@ public abstract class GT_MetaTileEntity_LargeTurbine } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "LargeTurbine.png"); - } - - @Override public IStructureDefinition<GT_MetaTileEntity_LargeTurbine> getStructureDefinition() { return STRUCTURE_DEFINITION.get(getClass()); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index e44308b5ae..466e741fed 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -18,7 +18,6 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -34,7 +33,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_StructureUtility; import gregtech.api.util.GT_Utility; import java.util.ArrayList; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; @@ -145,12 +143,6 @@ public class GT_MetaTileEntity_MultiFurnace } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiFurnace.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sFurnaceRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java index f338da2f88..30ee782cf7 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java @@ -18,7 +18,6 @@ import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -32,7 +31,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import java.util.List; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -173,12 +171,6 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_EnhancedMult } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "OilCrackingUnit.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sCrackingRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java index 04a7e1d770..72741573fd 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrillBase.java @@ -11,7 +11,6 @@ import static gregtech.common.GT_UndergroundOil.undergroundOil; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; import com.google.common.collect.ImmutableList; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -24,7 +23,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -129,12 +127,6 @@ public abstract class GT_MetaTileEntity_OilDrillBase extends GT_MetaTileEntity_D return tt; } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "DrillingRig.png"); - } - protected abstract int getRangeInChunks(); @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java index 064dd05f60..80b3660eb3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OreDrillingPlantBase.java @@ -9,9 +9,7 @@ import com.google.common.collect.ImmutableList; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; -import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.objects.GT_ChunkManager; import gregtech.api.objects.ItemData; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; @@ -27,7 +25,6 @@ import java.util.HashSet; import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -70,12 +67,6 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "OreDrillingPlant.png"); - } - - @Override public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ); if (aPlayer.isSneaking()) { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java index ae7f35d942..ad60853d50 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PlasmaForge.java @@ -15,7 +15,6 @@ import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Materials; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -29,7 +28,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import java.util.ArrayList; import java.util.List; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -1066,12 +1064,6 @@ public class GT_MetaTileEntity_PlasmaForge extends GT_MetaTileEntity_AbstractMul } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "PlasmaForge.png"); - } - - @Override public int getPollutionPerSecond(ItemStack aStack) { return 0; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java index bd1638780a..40754c14c5 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PrimitiveBlastFurnace.java @@ -11,11 +11,21 @@ import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructa import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ParticleFX; +import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.modularui.IGetTitleColor; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.objects.GT_ItemStack; @@ -24,18 +34,15 @@ import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; import gregtech.common.GT_Pollution; -import gregtech.common.gui.GT_Container_PrimitiveBlastFurnace; -import gregtech.common.gui.GT_GUIContainer_PrimitiveBlastFurnace; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEntity - implements IAlignment, ISurvivalConstructable { + implements IAlignment, ISurvivalConstructable, IAddUIWidgets, IGetTitleColor { public static final int INPUT_SLOTS = 3, OUTPUT_SLOTS = 3; private static final ClassValue<IStructureDefinition<GT_MetaTileEntity_PrimitiveBlastFurnace>> STRUCTURE_DEFINITION = new ClassValue<IStructureDefinition<GT_MetaTileEntity_PrimitiveBlastFurnace>>() { @@ -184,28 +191,11 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (aBaseMetaTileEntity.isClientSide()) { - return true; - } - aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_PrimitiveBlastFurnace(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_PrimitiveBlastFurnace( - aPlayerInventory, - aBaseMetaTileEntity, - getName(), - GT_Recipe.GT_Recipe_Map.sPrimitiveBlastRecipes.mNEIName); - } - - @Override public ExtendedFacing getExtendedFacing() { return ExtendedFacing.of( ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing())); @@ -380,6 +370,10 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn return GT_MetaTileEntity_Cleanroom.class; } + protected GT_Recipe.GT_Recipe_Map getRecipeMap() { + return GT_Recipe.GT_Recipe_Map.sPrimitiveBlastRecipes; + } + private void addOutputProducts() { if (this.mOutputItems == null) { return; @@ -413,8 +407,7 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn } ItemStack[] inputs = new ItemStack[INPUT_SLOTS]; System.arraycopy(mInventory, 0, inputs, 0, INPUT_SLOTS); - GT_Recipe recipe = GT_Recipe.GT_Recipe_Map.sPrimitiveBlastRecipes.findRecipe( - getBaseMetaTileEntity(), false, 0, null, inputs); + GT_Recipe recipe = getRecipeMap().findRecipe(getBaseMetaTileEntity(), false, 0, null, inputs); if (recipe == null) { this.mOutputItems = null; return false; @@ -508,4 +501,62 @@ public abstract class GT_MetaTileEntity_PrimitiveBlastFurnace extends MetaTileEn 0, hintsOnly); } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new SlotWidget(inventoryHandler, 0) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_INGOT_STEAM.get(getSteamVariant())) + .setPos(33, 15)) + .widget(new SlotWidget(inventoryHandler, 1) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_DUST_STEAM.get(getSteamVariant())) + .setPos(33, 33)) + .widget(new SlotWidget(inventoryHandler, 2) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_FURNACE_STEAM.get(getSteamVariant())) + .setPos(33, 51)) + .widget(new SlotWidget(inventoryHandler, 3) + .setAccess(true, false) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_INGOT_STEAM.get(getSteamVariant())) + .setPos(85, 24)) + .widget(new SlotWidget(inventoryHandler, 4) + .setAccess(true, false) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_DUST_STEAM.get(getSteamVariant())) + .setPos(103, 24)) + .widget(new SlotWidget(inventoryHandler, 5) + .setAccess(true, false) + .setBackground( + getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_DUST_STEAM.get(getSteamVariant())) + .setPos(121, 24)) + .widget(new ProgressBar() + .setTexture(GT_UITextures.PROGRESSBAR_ARROW_2_STEAM.get(getSteamVariant()), 20) + .setProgress(() -> (float) mProgresstime / mMaxProgresstime) + .setNEITransferRect(getRecipeMap().mNEIName) + .setPos(58, 24) + .setSize(20, 18)); + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.STEAM.apply(getSteamVariant()); + } + + @Override + public int getTitleColor() { + return getSteamVariant() == SteamVariant.BRONZE ? COLOR_TITLE.get() : COLOR_TITLE_WHITE.get(); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java index 7ab1f4e813..62d5fefc0d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java @@ -19,7 +19,6 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.IHatchElement; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -40,7 +39,6 @@ import java.util.List; import java.util.Objects; import java.util.stream.Stream; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; @@ -143,12 +141,6 @@ public class GT_MetaTileEntity_ProcessingArray return new ITexture[] {Textures.BlockIcons.casingTexturePages[0][48]}; } - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "ProcessingArray.png"); - } - // TODO: Expand so it also does the non recipe map recipes /* public void remoteRecipeCheck() { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index 8871e575ef..5212dc9195 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -24,7 +24,6 @@ import gregtech.api.GregTech_API; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Textures; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -34,7 +33,6 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Single_Recipe_Check; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -163,12 +161,6 @@ public class GT_MetaTileEntity_PyrolyseOven } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "PyrolyseOven.png"); - } - - @Override public boolean supportsSingleRecipeLocking() { return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java index 5bbed8951c..f942123109 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_VacuumFreezer.java @@ -9,7 +9,6 @@ import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages; import com.gtnewhorizon.structurelib.structure.IStructureElement; import com.gtnewhorizon.structurelib.structure.StructureUtility; import gregtech.api.GregTech_API; -import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -18,7 +17,6 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -101,12 +99,6 @@ public class GT_MetaTileEntity_VacuumFreezer } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_MultiMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "VacuumFreezer.png"); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sVacuumRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Bronze.java index 129af9dc27..3aefd2d16f 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Bronze.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_AlloySmelter_Bronze extends GT_MetaTileEntity_BasicMachine_Bronze { public GT_MetaTileEntity_AlloySmelter_Bronze(int aID, String aName, String aNameRegional) { @@ -37,16 +35,6 @@ public class GT_MetaTileEntity_AlloySmelter_Bronze extends GT_MetaTileEntity_Bas } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "BronzeAlloySmelter.png", - GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes.mUnlocalizedName); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeList() { return GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Steel.java index 2ad1a2ff01..9926c8a5e7 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_AlloySmelter_Steel.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_AlloySmelter_Steel extends GT_MetaTileEntity_BasicMachine_Steel { public GT_MetaTileEntity_AlloySmelter_Steel(int aID, String aName, String aNameRegional) { @@ -37,16 +35,6 @@ public class GT_MetaTileEntity_AlloySmelter_Steel extends GT_MetaTileEntity_Basi } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "SteelAlloySmelter.png", - GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes.mUnlocalizedName); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeList() { return GT_Recipe.GT_Recipe_Map.sAlloySmelterRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Bronze.java index 9fe3586790..5706345c3b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Bronze.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Compressor_Bronze extends GT_MetaTileEntity_BasicMachine_Bronze { public GT_MetaTileEntity_Compressor_Bronze(int aID, String aName, String aNameRegional) { @@ -27,16 +25,6 @@ public class GT_MetaTileEntity_Compressor_Bronze extends GT_MetaTileEntity_Basic } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "BronzeCompressor.png", - GT_Recipe.GT_Recipe_Map.sCompressorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Compressor_Bronze(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Steel.java index e3781e91a8..693f5abdbc 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Compressor_Steel.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Compressor_Steel extends GT_MetaTileEntity_BasicMachine_Steel { public GT_MetaTileEntity_Compressor_Steel(int aID, String aName, String aNameRegional) { @@ -27,16 +25,6 @@ public class GT_MetaTileEntity_Compressor_Steel extends GT_MetaTileEntity_BasicM } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "SteelCompressor.png", - GT_Recipe.GT_Recipe_Map.sCompressorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Compressor_Steel(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Bronze.java index 17fda5fc8d..7fa8358974 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Bronze.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Extractor_Bronze extends GT_MetaTileEntity_BasicMachine_Bronze { public GT_MetaTileEntity_Extractor_Bronze(int aID, String aName, String aNameRegional) { @@ -27,16 +25,6 @@ public class GT_MetaTileEntity_Extractor_Bronze extends GT_MetaTileEntity_BasicM } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "BronzeExtractor.png", - GT_Recipe.GT_Recipe_Map.sExtractorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Extractor_Bronze(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Steel.java index c7ebeee12b..c18a7e8a51 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Extractor_Steel.java @@ -3,7 +3,6 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -11,7 +10,6 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachin import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; public class GT_MetaTileEntity_Extractor_Steel extends GT_MetaTileEntity_BasicMachine_Steel { public GT_MetaTileEntity_Extractor_Steel(int aID, String aName, String aNameRegional) { @@ -27,16 +25,6 @@ public class GT_MetaTileEntity_Extractor_Steel extends GT_MetaTileEntity_BasicMa } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "SteelExtractor.png", - GT_Recipe.GT_Recipe_Map.sExtractorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Extractor_Steel(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Bronze.java index a22d1cb3e3..9709207ab3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Bronze.java @@ -7,7 +7,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -17,7 +16,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_ForgeHammer_Bronze extends GT_MetaTileEntity_BasicMachine_Bronze { @@ -39,18 +37,6 @@ public class GT_MetaTileEntity_ForgeHammer_Bronze extends GT_MetaTileEntity_Basi } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "BronzeHammer.png", - GT_Recipe.GT_Recipe_Map.sHammerRecipes.mUnlocalizedName, - (byte) 6, - (byte) 3); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeList() { return GT_Recipe.GT_Recipe_Map.sHammerRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Steel.java index dd233aa6f2..d34cf2efb9 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_ForgeHammer_Steel.java @@ -7,7 +7,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -17,7 +16,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraftforge.common.util.ForgeDirection; public class GT_MetaTileEntity_ForgeHammer_Steel extends GT_MetaTileEntity_BasicMachine_Steel { @@ -39,18 +37,6 @@ public class GT_MetaTileEntity_ForgeHammer_Steel extends GT_MetaTileEntity_Basic } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "SteelHammer.png", - GT_Recipe.GT_Recipe_Map.sHammerRecipes.mUnlocalizedName, - (byte) 6, - (byte) 3); - } - - @Override public GT_Recipe.GT_Recipe_Map getRecipeList() { return GT_Recipe.GT_Recipe_Map.sHammerRecipes; } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Bronze.java index cd99dda2e2..15d971a0fb 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Bronze.java @@ -3,15 +3,14 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Bronze; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Furnace_Bronze extends GT_MetaTileEntity_BasicMachine_Bronze { @@ -33,14 +32,13 @@ public class GT_MetaTileEntity_Furnace_Bronze extends GT_MetaTileEntity_BasicMac } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "BronzeFurnace.png", "smelting"); + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Furnace_Bronze(this.mName, this.mDescriptionArray, this.mTextures); } @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Furnace_Bronze(this.mName, this.mDescriptionArray, this.mTextures); + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GT_Recipe.GT_Recipe_Map.sFurnaceRecipes; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Steel.java index 3bc35d8c47..85142dbd98 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Furnace_Steel.java @@ -3,15 +3,14 @@ package gregtech.common.tileentities.machines.steam; import static gregtech.api.enums.Textures.BlockIcons.*; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Steel; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; public class GT_MetaTileEntity_Furnace_Steel extends GT_MetaTileEntity_BasicMachine_Steel { @@ -33,14 +32,13 @@ public class GT_MetaTileEntity_Furnace_Steel extends GT_MetaTileEntity_BasicMach } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "SteelFurnace.png", "smelting"); + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Furnace_Steel(this.mName, this.mDescriptionArray, this.mTextures); } @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Furnace_Steel(this.mName, this.mDescriptionArray, this.mTextures); + public GT_Recipe.GT_Recipe_Map getRecipeList() { + return GT_Recipe.GT_Recipe_Map.sFurnaceRecipes; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Bronze.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Bronze.java index f6f5bf8477..e06a179fa7 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Bronze.java @@ -6,7 +6,6 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -16,7 +15,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -35,16 +33,6 @@ public class GT_MetaTileEntity_Macerator_Bronze extends GT_MetaTileEntity_BasicM } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "BronzeMacerator.png", - GT_Recipe_Map.sMaceratorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Macerator_Bronze(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Steel.java b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Steel.java index 14acdb9b45..13270b9a83 100644 --- a/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Steel.java +++ b/src/main/java/gregtech/common/tileentities/machines/steam/GT_MetaTileEntity_Macerator_Steel.java @@ -6,7 +6,6 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; import gregtech.api.enums.ParticleFX; import gregtech.api.enums.SoundResource; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -16,7 +15,6 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gregtech.api.util.WorldSpawnedEventBuilder; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; @@ -35,16 +33,6 @@ public class GT_MetaTileEntity_Macerator_Steel extends GT_MetaTileEntity_BasicMa } @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_BasicMachine( - aPlayerInventory, - aBaseMetaTileEntity, - getLocalName(), - "SteelMacerator.png", - GT_Recipe_Map.sMaceratorRecipes.mUnlocalizedName); - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Macerator_Steel(this.mName, this.mDescriptionArray, this.mTextures); } diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java index 28ff39315e..747116400a 100644 --- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java +++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalChestBase.java @@ -4,17 +4,23 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCHEST; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SCHEST_GLOW; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; import cpw.mods.fml.common.Optional; import gregtech.api.GregTech_API; import gregtech.api.enums.GT_Values; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.AE2DigitalChestHandler; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; -import gregtech.common.gui.GT_Container_QuantumChest; -import gregtech.common.gui.GT_GUIContainer_QuantumChest; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,7 +28,6 @@ import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -33,7 +38,7 @@ import net.minecraftforge.common.util.Constants; @Optional.Interface(iface = "appeng.api.storage.IMEMonitor", modid = "appliedenergistics2", striprefs = true) public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEntity_TieredMachineBlock - implements appeng.api.storage.IMEMonitor<appeng.api.storage.data.IAEItemStack> { + implements appeng.api.storage.IMEMonitor<appeng.api.storage.data.IAEItemStack>, IAddUIWidgets { protected boolean mVoidOverflow = false; protected boolean mDisableFilter; public boolean voidBreak; @@ -194,16 +199,6 @@ public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEnti } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_QuantumChest(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_QuantumChest(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - - @Override public ITexture[][][] getTextureSet(ITexture[] aTextures) { return new ITexture[0][0][0]; } @@ -360,7 +355,7 @@ public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEnti @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (!aBaseMetaTileEntity.isClientSide()) aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -543,4 +538,37 @@ public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEnti tag.setInteger("itemCount", realItemCount); tag.setTag("itemType", is.writeToNBT(new NBTTagCompound())); } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 16) + .setSize(71, 45)) + .widget(new SlotWidget(inventoryHandler, 0) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_IN) + .setPos(79, 16)) + .widget(new SlotWidget(inventoryHandler, 1) + .setAccess(true, false) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_OUT) + .setPos(79, 52)) + .widget(SlotWidget.phantom(inventoryHandler, 2) + .disableInteraction() + .setBackground(GT_UITextures.TRANSPARENT) + .setPos(59, 42)) + .widget(new TextWidget("Item Amount") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 20)) + .widget(TextWidget.dynamicString(() -> GT_Utility.parseNumberToString( + this instanceof GT_MetaTileEntity_QuantumChest + ? ((GT_MetaTileEntity_QuantumChest) this).mItemCount + : 0)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 30)); + } } diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java index 2a996e050a..a4d1f1113f 100644 --- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java +++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_DigitalTankBase.java @@ -1,21 +1,31 @@ package gregtech.common.tileentities.storage; import static gregtech.api.enums.Textures.BlockIcons.*; - -import gregtech.api.gui.GT_Container_DigitalTank; -import gregtech.api.gui.GT_GUIContainer_DigitalTank; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.IFluidAccess; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IFluidLockable; +import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget; import java.util.List; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -28,7 +38,8 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntity_BasicTank implements IFluidLockable { +public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntity_BasicTank + implements IFluidLockable, IAddUIWidgets { public boolean mOutputFluid = false, mVoidFluidPart = false, mVoidFluidFull = false, mLockFluid = false; protected String lockedFluidName = null; private boolean voidBreak; @@ -235,7 +246,7 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - if (!aBaseMetaTileEntity.isClientSide()) aBaseMetaTileEntity.openGUI(aPlayer); + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); return true; } @@ -273,16 +284,6 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit } @Override - public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_Container_DigitalTank(aPlayerInventory, aBaseMetaTileEntity); - } - - @Override - public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { - return new GT_GUIContainer_DigitalTank(aPlayerInventory, aBaseMetaTileEntity, getLocalName()); - } - - @Override public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { if (aBaseMetaTileEntity.isServerSide()) { if (isFluidChangingAllowed() && getFillableStack() != null && getFillableStack().amount <= 0) @@ -476,4 +477,174 @@ public abstract class GT_MetaTileEntity_DigitalTankBase extends GT_MetaTileEntit if (fluid != null) tag.setTag("mFluid", fluid.writeToNBT(new NBTTagCompound())); else if (tag.hasKey("mFluid")) tag.removeTag("mFluid"); } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new DrawableWidget() + .setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 16) + .setSize(71, 45)) + .widget(new SlotWidget(inventoryHandler, getInputSlot()) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_IN) + .setPos(79, 16)) + .widget(new SlotWidget(inventoryHandler, getOutputSlot()) + .setAccess(true, false) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_OUT) + .setPos(79, 43)) + .widget(new FluidDisplaySlotWidget(inventoryHandler, getStackDisplaySlot()) + .setFluidAccessConstructor(() -> constructFluidAccess(false)) + .setIHasFluidDisplay(this) + .setCanDrain(true) + .setCanFill(!isDrainableStackSeparate()) + .setActionRealClick(FluidDisplaySlotWidget.Action.TRANSFER) + .setActionDragAndDrop(FluidDisplaySlotWidget.Action.LOCK) + .setBeforeRealClick((clickData, widget) -> { + if (NetworkUtils.isClient()) { + // propagate display item content to actual fluid stored in this tank + setDrainableStack(GT_Utility.getFluidFromDisplayStack( + widget.getMcSlot().getStack())); + } + return true; + }) + .setBackground(GT_UITextures.TRANSPARENT) + .setPos(58, 41)) + .widget(new TextWidget("Liquid Amount") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 20)) + .widget(TextWidget.dynamicString( + () -> GT_Utility.parseNumberToString(mFluid != null ? mFluid.amount : 0)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 30)) + .widget(new CycleButtonWidget() + .setToggle(() -> mOutputFluid, val -> { + mOutputFluid = val; + if (!mOutputFluid) { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), + GT_Utility.trans("262", "Fluid Auto Output Disabled")); + } else { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), GT_Utility.trans("263", "Fluid Auto Output Enabled")); + } + }) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_AUTOOUTPUT_FLUID) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.digitaltank.autooutput.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(7, 63) + .setSize(18, 18)) + .widget(new CycleButtonWidget() + .setToggle(() -> mLockFluid, val -> { + mLockFluid = val; + + String inBrackets; + if (mLockFluid) { + if (mFluid == null) { + setLockedFluidName(null); + inBrackets = GT_Utility.trans( + "264", "currently none, will be locked to the next that is put in"); + } else { + setLockedFluidName( + getDrainableStack().getFluid().getName()); + inBrackets = getDrainableStack().getLocalizedName(); + } + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), + String.format( + "%s (%s)", GT_Utility.trans("265", "1 specific Fluid"), inBrackets)); + } else { + setLockedFluidName(null); + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), GT_Utility.trans("266", "Lock Fluid Mode Disabled")); + } + }) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_LOCK) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.digitaltank.lockfluid.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(25, 63) + .setSize(18, 18)) + .widget(new CycleButtonWidget() + .setToggle(() -> mAllowInputFromOutputSide, val -> { + mAllowInputFromOutputSide = val; + if (!mAllowInputFromOutputSide) { + GT_Utility.sendChatToPlayer(buildContext.getPlayer(), GT_Utility.getTrans("096")); + } else { + GT_Utility.sendChatToPlayer(buildContext.getPlayer(), GT_Utility.getTrans("095")); + } + }) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_INPUT_FROM_OUTPUT_SIDE) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.digitaltank.inputfromoutput.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(43, 63) + .setSize(18, 18)) + .widget(new CycleButtonWidget() + .setToggle(() -> mVoidFluidPart, val -> { + mVoidFluidPart = val; + if (!mVoidFluidPart) { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), + GT_Utility.trans("267", "Overflow Voiding Mode Disabled")); + } else { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), + GT_Utility.trans("268", "Overflow Voiding Mode Enabled")); + } + }) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_VOID_EXCESS) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.digitaltank.voidoverflow.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(151, 7) + .setSize(18, 18)) + .widget(new CycleButtonWidget() + .setToggle(() -> mVoidFluidFull, val -> { + mVoidFluidFull = val; + if (!mVoidFluidFull) { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), GT_Utility.trans("269", "Void Full Mode Disabled")); + } else { + GT_Utility.sendChatToPlayer( + buildContext.getPlayer(), GT_Utility.trans("270", "Void Full Mode Enabled")); + } + }) + .setVariableBackground(GT_UITextures.BUTTON_STANDARD_TOGGLE) + .setStaticTexture(GT_UITextures.OVERLAY_BUTTON_VOID_ALL) + .setGTTooltip(() -> mTooltipCache.getData("GT5U.machines.digitaltank.voidfull.tooltip")) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(151, 25) + .setSize(18, 18)); + } + + @Override + protected IFluidAccess constructFluidAccess(boolean aIsFillableStack) { + return new DigitalTankFluidAccess(this, aIsFillableStack); + } + + static class DigitalTankFluidAccess extends BasicTankFluidAccess { + + public DigitalTankFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) { + super(aTank, aIsFillableStack); + } + + @Override + public void set(FluidStack stack) { + super.set(stack); + ((GT_MetaTileEntity_DigitalTankBase) mTank).onEmptyingContainerWhenEmpty(); + } + + @Override + public int getRealCapacity() { + return ((GT_MetaTileEntity_DigitalTankBase) mTank).getRealCapacity(); + } + + @Override + public void verifyFluidStack() {} + } } diff --git a/src/main/java/gregtech/loaders/postload/GT_PostLoad.java b/src/main/java/gregtech/loaders/postload/GT_PostLoad.java index 6b59de3709..3d38488393 100644 --- a/src/main/java/gregtech/loaders/postload/GT_PostLoad.java +++ b/src/main/java/gregtech/loaders/postload/GT_PostLoad.java @@ -352,7 +352,10 @@ public class GT_PostLoad { 0); GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes.addFakeRecipe( false, - new ItemStack[] {GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L)}, + new ItemStack[] { + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L), + GT_Utility.getIntegratedCircuit(1) + }, new ItemStack[] {new ItemStack(Blocks.obsidian, 1)}, null, null, diff --git a/src/main/java/gregtech/loaders/preload/GT_PreLoad.java b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java index 1b8faab242..d6818d1ac5 100644 --- a/src/main/java/gregtech/loaders/preload/GT_PreLoad.java +++ b/src/main/java/gregtech/loaders/preload/GT_PreLoad.java @@ -955,17 +955,21 @@ public class GT_PreLoad { GregTech_API.sClientDataFile.get("render", "RenderDirtParticles", true); GT_Mod.gregtechproxy.mRenderPollutionFog = GregTech_API.sClientDataFile.get("render", "RenderPollutionFog", true); + GT_Mod.gregtechproxy.mCoverTabsVisible = GregTech_API.sClientDataFile.get("interface", "DisplayCoverTabs", true); GT_Mod.gregtechproxy.mCoverTabsFlipped = GregTech_API.sClientDataFile.get("interface", "FlipCoverTabs", false); GT_Mod.gregtechproxy.mTooltipVerbosity = GregTech_API.sClientDataFile.get("interface", "TooltipVerbosity", 2); GT_Mod.gregtechproxy.mTooltipShiftVerbosity = GregTech_API.sClientDataFile.get("interface", "TooltipShiftVerbosity", 3); + GT_Mod.gregtechproxy.mTitleTabStyle = GregTech_API.sClientDataFile.get("interface", "TitleTabStyle", 0); + GT_Mod.gregtechproxy.mNEIRecipeSecondMode = GregTech_API.sClientDataFile.get("nei", "RecipeSecondMode", true); GT_Mod.gregtechproxy.mNEIRecipeOwner = GregTech_API.sClientDataFile.get("nei", "RecipeOwner", false); GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace = GregTech_API.sClientDataFile.get("nei", "RecipeOwnerStackTrace", false); GT_Mod.gregtechproxy.mNEIOriginalVoltage = GregTech_API.sClientDataFile.get("nei", "OriginalVoltage", false); + GT_Mod.gregtechproxy.mWailaTransformerVoltageTier = GregTech_API.sClientDataFile.get("waila", "WailaTransformerVoltageTier", true); diff --git a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java index 90b0532bbc..bb14a02618 100644 --- a/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_AssLineHandler.java @@ -1,559 +1,21 @@ package gregtech.nei; -import static gregtech.api.util.GT_Utility.trans; - -import codechicken.lib.gui.GuiDraw; -import codechicken.nei.NEIClientUtils; -import codechicken.nei.PositionedStack; -import codechicken.nei.guihook.GuiContainerManager; -import codechicken.nei.guihook.IContainerInputHandler; -import codechicken.nei.guihook.IContainerTooltipHandler; -import codechicken.nei.recipe.GuiCraftingRecipe; -import codechicken.nei.recipe.GuiRecipe; -import codechicken.nei.recipe.GuiUsageRecipe; -import codechicken.nei.recipe.TemplateRecipeHandler; -import gregtech.GT_Mod; -import gregtech.api.enums.GT_Values; -import gregtech.api.enums.OrePrefixes; -import gregtech.api.gui.GT_GUIContainer_BasicMachine; -import gregtech.api.objects.ItemData; -import gregtech.api.util.GT_LanguageManager; -import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; -import gregtech.api.util.GT_Recipe.GT_Recipe_WithAlt; -import gregtech.api.util.GT_Utility; -import java.awt.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import org.lwjgl.opengl.GL11; +@Deprecated public class GT_NEI_AssLineHandler extends RecipeMapHandler { - public static final int sOffsetX = 5; - public static final int sOffsetY = 11; - - /** - * Static version of {@link TemplateRecipeHandler#cycleticks}. - * Can be referenced from cached recipes. - */ - public static int cycleTicksStatic = Math.abs((int) System.currentTimeMillis()); - - private String mRecipeName; - - static { - GuiContainerManager.addInputHandler(new GT_RectHandler()); - GuiContainerManager.addTooltipHandler(new GT_RectHandler()); - } - public GT_NEI_AssLineHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) { // this is called when recipes should be shown + public GT_NEI_AssLineHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) { super(aRecipeMap); - this.transferRects.add(new RecipeTransferRect(new Rectangle(138, 18, 18, 18), getOverlayIdentifier())); - } - - public List<GT_Recipe> getSortedRecipes() { - List<GT_Recipe> result = new ArrayList<>(this.mRecipeMap.mRecipeList); - Collections.sort(result); - return result; - } - - @Override - public TemplateRecipeHandler newInstance() { - NEI_GT_Config.ALH = new GT_NEI_AssLineHandler(this.mRecipeMap); - return NEI_GT_Config.ALH; - } - - @Override - public void loadCraftingRecipes(String outputId, Object... results) { - if (outputId.equals(getOverlayIdentifier())) { - for (GT_Recipe tRecipe : getSortedRecipes()) { - if (!tRecipe.mHidden) { - this.arecipes.add(new CachedDefaultRecipe(tRecipe)); - } else { - this.arecipes.remove(new CachedDefaultRecipe(tRecipe)); - } - } - } else { - super.loadCraftingRecipes(outputId, results); - } - } - - @Override - public void loadCraftingRecipes(ItemStack aResult) { - ItemData tPrefixMaterial = GT_OreDictUnificator.getAssociation(aResult); - - ArrayList<ItemStack> tResults = new ArrayList(); - tResults.add(aResult); - tResults.add(GT_OreDictUnificator.get(true, aResult)); - if ((tPrefixMaterial != null) - && (!tPrefixMaterial.mBlackListed) - && (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) { - for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) { - tResults.add(GT_OreDictUnificator.get(tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L)); - } - } - FluidStack tFluid = GT_Utility.getFluidForFilledItem(aResult, true); - if (tFluid != null) { - tResults.add(GT_Utility.getFluidDisplayStack(tFluid, false)); - for (FluidContainerRegistry.FluidContainerData tData : - FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (tData.fluid.isFluidEqual(tFluid)) { - tResults.add(GT_Utility.copyOrNull(tData.filledContainer)); - } - } - } - for (GT_Recipe tRecipe : getSortedRecipes()) { - if (!tRecipe.mHidden) { - CachedDefaultRecipe tNEIRecipe = new CachedDefaultRecipe(tRecipe); - for (ItemStack tStack : tResults) { - if (tNEIRecipe.contains(tNEIRecipe.mOutputs, tStack)) { - this.arecipes.add(tNEIRecipe); - break; - } - } - } else { - CachedDefaultRecipe tNEIRecipe = new CachedDefaultRecipe(tRecipe); - for (ItemStack tStack : tResults) { - if (tNEIRecipe.contains(tNEIRecipe.mOutputs, tStack)) { - this.arecipes.remove(tNEIRecipe); - break; - } - } - } - } - } - - @Override - public void loadUsageRecipes(ItemStack aInput) { - ItemData tPrefixMaterial = GT_OreDictUnificator.getAssociation(aInput); - - ArrayList<ItemStack> tInputs = new ArrayList(); - tInputs.add(aInput); - tInputs.add(GT_OreDictUnificator.get(false, aInput)); - if ((tPrefixMaterial != null) && (!tPrefixMaterial.mPrefix.mFamiliarPrefixes.isEmpty())) { - for (OrePrefixes tPrefix : tPrefixMaterial.mPrefix.mFamiliarPrefixes) { - tInputs.add(GT_OreDictUnificator.get(tPrefix, tPrefixMaterial.mMaterial.mMaterial, 1L)); - } - } - FluidStack tFluid = GT_Utility.getFluidForFilledItem(aInput, true); - if (tFluid != null) { - tInputs.add(GT_Utility.getFluidDisplayStack(tFluid, false)); - for (FluidContainerRegistry.FluidContainerData tData : - FluidContainerRegistry.getRegisteredFluidContainerData()) { - if (tData.fluid.isFluidEqual(tFluid)) { - tInputs.add(GT_Utility.copyOrNull(tData.filledContainer)); - } - } - } - for (GT_Recipe tRecipe : this.mRecipeMap.mRecipeList) { - if (!tRecipe.mHidden) { - CachedDefaultRecipe tNEIRecipe = new CachedDefaultRecipe(tRecipe); - for (ItemStack tStack : tInputs) { - if (tNEIRecipe.contains(tNEIRecipe.mInputs, tStack)) { - this.arecipes.add(tNEIRecipe); - break; - } - } - } else { - CachedDefaultRecipe tNEIRecipe = new CachedDefaultRecipe(tRecipe); - for (ItemStack tStack : tInputs) { - if (tNEIRecipe.contains(tNEIRecipe.mInputs, tStack)) { - this.arecipes.remove(tNEIRecipe); - break; - } - } - } - } - CachedDefaultRecipe tNEIRecipe; - } - - @Override - public String getOverlayIdentifier() { - return this.mRecipeMap.mNEIName; - } - - @Override - public void drawBackground(int recipe) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiDraw.changeTexture(getGuiTexture()); - GuiDraw.drawTexturedModalRect(-4, -8, 1, 3, 174, 79); - } - - @Override - public void onUpdate() { - super.onUpdate(); - if (!NEIClientUtils.shiftKey()) cycleTicksStatic++; - } - - @Override - public int recipiesPerPage() { - return 1; - } - - @Override - public String getRecipeName() { - if (mRecipeName == null) { - mRecipeName = GT_LanguageManager.getTranslation(this.mRecipeMap.mUnlocalizedName); - updateOverrideTextColor(); - } - return mRecipeName; } @Override public String getGuiTexture() { - return this.mRecipeMap.mNEIGUIPath; - } - - @Override - public List<String> handleItemTooltip( - GuiRecipe<?> gui, ItemStack aStack, List<String> currenttip, int aRecipeIndex) { - CachedRecipe tObject = (CachedRecipe) this.arecipes.get(aRecipeIndex); - if ((tObject instanceof CachedDefaultRecipe)) { - CachedDefaultRecipe tRecipe = (CachedDefaultRecipe) tObject; - for (PositionedStack tStack : tRecipe.mOutputs) { - if (aStack == tStack.item) { - if ((!(tStack instanceof FixedPositionedStack)) - || (((FixedPositionedStack) tStack).mChance <= 0) - || (((FixedPositionedStack) tStack).mChance == 10000)) { - break; - } - currenttip.add("Chance: " + ((FixedPositionedStack) tStack).mChance / 100 + "." - + (((FixedPositionedStack) tStack).mChance % 100 < 10 - ? "0" + ((FixedPositionedStack) tStack).mChance % 100 - : Integer.valueOf(((FixedPositionedStack) tStack).mChance % 100)) - + "%"); - break; - } - } - for (PositionedStack tStack : tRecipe.mInputs) { - if (aStack == tStack.item) { - if ((gregtech.api.enums.ItemList.Display_Fluid.isStackEqual(tStack.item, true, true)) - || (tStack.item.stackSize != 0)) { - break; - } - currenttip.add("Does not get consumed in the process"); - break; - } - } - } - return currenttip; + return null; } @Override - public void drawExtras(int aRecipeIndex) { - GT_Recipe recipe = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe; - int tEUt = recipe.mEUt; - int tDuration = recipe.mDuration; - String[] recipeDesc = recipe.getNeiDesc(); - if (recipeDesc == null) { - if (tEUt != 0) { - drawText( - 10, - 73, - trans("152", "Total: ") + GT_Utility.formatNumbers((long) tDuration * tEUt) + " EU", - 0xFF000000); - drawText(10, 83, trans("153", "Usage: ") + GT_Utility.formatNumbers(tEUt) + " EU/t", 0xFF000000); - if (this.mRecipeMap.mShowVoltageAmperageInNEI) { - int voltage = tEUt / this.mRecipeMap.mAmperage; - byte tier = GT_Utility.getTier(voltage); - if (tier < 0 || tier >= 16) { - drawText( - 10, - 93, - trans("154", "Voltage: ") + GT_Utility.formatNumbers(voltage) + " EU", - 0xFF000000); - } else { - drawText( - 10, - 93, - trans("154", "Voltage: ") + GT_Utility.formatNumbers(voltage) + " EU (" - + GT_Values.VN[tier] + ")", - 0xFF000000); - } - drawText( - 10, - 103, - trans("155", "Amperage: ") + GT_Utility.formatNumbers(this.mRecipeMap.mAmperage), - 0xFF000000); - } else { - drawText(10, 93, trans("156", "Voltage: unspecified"), 0xFF000000); - drawText(10, 103, trans("157", "Amperage: unspecified"), 0xFF000000); - } - } - if (tDuration > 0) { - drawText( - 10, - 113, - trans("158", "Time: ") + GT_Utility.formatNumbers(0.05d * tDuration) + trans("161", " secs"), - 0xFF000000); - } - int tSpecial = ((CachedDefaultRecipe) this.arecipes.get(aRecipeIndex)).mRecipe.mSpecialValue; - boolean specialDrew = false; - if (tSpecial == -100 && GT_Mod.gregtechproxy.mLowGravProcessing) { - drawText(10, 123, trans("159", "Needs Low Gravity"), 0xFF000000); - specialDrew = true; - } else if (tSpecial == -200 && GT_Mod.gregtechproxy.mEnableCleanroom) { - drawText(10, 123, trans("160", "Needs Cleanroom"), 0xFF000000); - specialDrew = true; - } else if (tSpecial == -201) { - drawText(10, 123, trans("206", "Scan for Assembly Line"), 0xFF000000); - specialDrew = true; - } else if ((GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePre)) - || (GT_Utility.isStringValid(this.mRecipeMap.mNEISpecialValuePost))) { - drawText( - 10, - 123, - this.mRecipeMap.mNEISpecialValuePre - + GT_Utility.formatNumbers(tSpecial * this.mRecipeMap.mNEISpecialValueMultiplier) - + this.mRecipeMap.mNEISpecialValuePost, - 0xFF000000); - specialDrew = true; - } - int y = 123 + (specialDrew ? 10 : 0); - if (GT_Mod.gregtechproxy.mNEIRecipeOwner) { - if (recipe.owners.size() > 1) { - drawText( - 10, - y, - EnumChatFormatting.ITALIC - + GT_Utility.trans("273", "Original Recipe by: ") - + recipe.owners.get(0).getName(), - 0xFF000000); - y += 10; - for (int i = 1; i < recipe.owners.size(); i++) { - drawText( - 10, - y, - EnumChatFormatting.ITALIC - + GT_Utility.trans("274", "Modified by: ") - + recipe.owners.get(i).getName(), - 0xFF000000); - y += 10; - } - } else if (recipe.owners.size() > 0) { - drawText( - 10, - y, - EnumChatFormatting.ITALIC - + GT_Utility.trans("272", "Recipe by: ") - + recipe.owners.get(0).getName(), - 0xFF000000); - y += 10; - } - } - if (GT_Mod.gregtechproxy.mNEIRecipeOwnerStackTrace - && recipe.stackTraces != null - && !recipe.stackTraces.isEmpty()) { - drawText(10, y, "stackTrace:", 0xFF000000); - y += 10; - for (StackTraceElement stackTrace : recipe.stackTraces.get(0)) { - drawText(10, y, stackTrace.toString(), 0xFF000000); - y += 10; - } - } - } else { - int i = 0; - for (String descLine : recipeDesc) { - drawText(10, 73 + 10 * i, descLine, 0xFF000000); - i++; - } - } - } - - public static class GT_RectHandler implements IContainerInputHandler, IContainerTooltipHandler { - @Override - public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) { - - return false; - } - - @Override - public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) { - return false; - } - - public boolean canHandle(GuiContainer gui) { - return false; - // return (((gui instanceof GT_GUIContainer_BasicMachine)) && - // (GT_Utility.isStringValid(((GT_GUIContainer_BasicMachine) gui).mNEI))); - } - - @Override - public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) { - return currenttip; - } - - private boolean transferRect(GuiContainer gui, boolean usage) { - return (canHandle(gui)) - && (new Rectangle(138, 18, 18, 18) - .contains(new Point( - GuiDraw.getMousePosition().x - - ((GT_GUIContainer_BasicMachine) gui).getLeft() - - codechicken.nei.recipe.RecipeInfo.getGuiOffset(gui)[0], - GuiDraw.getMousePosition().y - - ((GT_GUIContainer_BasicMachine) gui).getTop() - - codechicken.nei.recipe.RecipeInfo.getGuiOffset(gui)[1]))) - && (usage - ? GuiUsageRecipe.openRecipeGui(((GT_GUIContainer_BasicMachine) gui).mNEI, new Object[0]) - : GuiCraftingRecipe.openRecipeGui( - ((GT_GUIContainer_BasicMachine) gui).mNEI, new Object[0])); - } - - @Override - public List<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip) { - return currenttip; - } - - @Override - public List<String> handleItemTooltip( - GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) { - return currenttip; - } - - @Override - public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode) { - return false; - } - - @Override - public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {} - - @Override - public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {} - - @Override - public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {} - - @Override - public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) { - return false; - } - - @Override - public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {} - - @Override - public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {} - } - - public class FixedPositionedStack extends PositionedStack { - public final int mChance; - public boolean permutated = false; - - public FixedPositionedStack(Object object, int x, int y) { - this(object, x, y, 0); - } - - public FixedPositionedStack(Object object, int x, int y, int aChance) { - super(object, x, y, true); - this.mChance = aChance; - } - - @Override - public void generatePermutations() { - if (this.permutated) { - return; - } - ArrayList<ItemStack> tDisplayStacks = new ArrayList(); - for (ItemStack tStack : this.items) { - if (GT_Utility.isStackValid(tStack)) { - if (tStack.getItemDamage() == 32767) { - List<ItemStack> permutations = codechicken.nei.ItemList.itemMap.get(tStack.getItem()); - if (!permutations.isEmpty()) { - ItemStack stack; - for (Iterator i$ = permutations.iterator(); - i$.hasNext(); - tDisplayStacks.add(GT_Utility.copyAmount(tStack.stackSize, new Object[] {stack}))) { - stack = (ItemStack) i$.next(); - } - } else { - ItemStack base = new ItemStack(tStack.getItem(), tStack.stackSize); - base.stackTagCompound = tStack.stackTagCompound; - tDisplayStacks.add(base); - } - } else { - tDisplayStacks.add(GT_Utility.copyOrNull(tStack)); - } - } - } - this.items = ((ItemStack[]) tDisplayStacks.toArray(new ItemStack[0])); - if (this.items.length == 0) { - this.items = new ItemStack[] {new ItemStack(Blocks.fire)}; - } - this.permutated = true; - setPermutationToRender(0); - } - } - - public class CachedDefaultRecipe extends CachedRecipe { - public final GT_Recipe mRecipe; - public final List<PositionedStack> mOutputs = new ArrayList(); - public final List<PositionedStack> mInputs = new ArrayList(); - - public CachedDefaultRecipe(GT_Recipe aRecipe) { - super(); - this.mRecipe = aRecipe; - - for (int i = 0; i < 16; i++) { - Object obj = aRecipe instanceof GT_Recipe_WithAlt - ? ((GT_Recipe_WithAlt) aRecipe).getAltRepresentativeInput(i) - : aRecipe.getRepresentativeInput(i); - if (obj != null) { - this.mInputs.add(new FixedPositionedStack(obj, 18 * (i % 4) + 12, 18 * (i / 4))); - } - } - - if (aRecipe.mSpecialItems != null) { - this.mInputs.add(new FixedPositionedStack(aRecipe.mSpecialItems, 138, 36)); - } - if (aRecipe.getOutput(0) != null) { - this.mOutputs.add(new FixedPositionedStack(aRecipe.getOutput(0), 138, 0, aRecipe.getOutputChance(0))); - } - if ((aRecipe.mFluidInputs.length > 0) - && (aRecipe.mFluidInputs[0] != null) - && (aRecipe.mFluidInputs[0].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[0], true), 102, 0)); - if ((aRecipe.mFluidInputs.length > 1) - && (aRecipe.mFluidInputs[1] != null) - && (aRecipe.mFluidInputs[1].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[1], true), 102, 18)); - if ((aRecipe.mFluidInputs.length > 2) - && (aRecipe.mFluidInputs[2] != null) - && (aRecipe.mFluidInputs[2].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[2], true), 102, 36)); - if ((aRecipe.mFluidInputs.length > 3) - && (aRecipe.mFluidInputs[3] != null) - && (aRecipe.mFluidInputs[3].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[3], true), 102, 54)); - } - } - } - } - } - - @Override - public List<PositionedStack> getIngredients() { - return getCycledIngredients(cycleTicksStatic / 10, this.mInputs); - } - - @Override - public PositionedStack getResult() { - return null; - } - - @Override - public List<PositionedStack> getOtherStacks() { - return this.mOutputs; - } + public String getRecipeName() { + return null; } } diff --git a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java index d5c59c61c6..2ff5142ace 100644 --- a/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java +++ b/src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java @@ -15,10 +15,19 @@ import codechicken.nei.recipe.ICraftingHandler; import codechicken.nei.recipe.IUsageHandler; import codechicken.nei.recipe.RecipeCatalysts; import codechicken.nei.recipe.TemplateRecipeHandler; +import com.gtnewhorizons.modularui.api.GlStateManager; +import com.gtnewhorizons.modularui.api.UIInfos; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.GT_Mod; import gregtech.api.enums.GT_Values; import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SteamVariant; import gregtech.api.gui.GT_GUIContainer; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; @@ -29,6 +38,7 @@ import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.blocks.GT_Item_Machines; +import gregtech.common.gui.modularui.UIHelper; import gregtech.common.power.EUPower; import gregtech.common.power.Power; import gregtech.common.power.UnspecifiedEUPower; @@ -77,6 +87,20 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { * Can be referenced from cached recipes. */ public static int cycleTicksStatic = Math.abs((int) System.currentTimeMillis()); + /** + * Basically {@link #cycleTicksStatic} but always updated even while holding shift + */ + private static int drawTicks; + + protected static final int PROGRESSBAR_CYCLE_TICKS = 200; + + protected final ModularWindow modularWindow; + protected final ItemStackHandler itemInputsInventory; + protected final ItemStackHandler itemOutputsInventory; + protected final ItemStackHandler specialSlotInventory; + protected final ItemStackHandler fluidInputsInventory; + protected final ItemStackHandler fluidOutputsInventory; + protected static final Pos2d WINDOW_OFFSET = new Pos2d(-sOffsetX, -sOffsetY); static { GuiContainerManager.addInputHandler(new GT_RectHandler()); @@ -85,10 +109,25 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public GT_NEI_DefaultHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) { super(aRecipeMap); - if ("gt.recipe.complexfusionreactor".equals(aRecipeMap.mUnlocalizedName)) { - this.transferRects.add(new RecipeTransferRect(new Rectangle(74, 23, 18, 18), getOverlayIdentifier())); + Rectangle transferRect = new Rectangle(aRecipeMap.neiTransferRect); + transferRect.translate(WINDOW_OFFSET.x, WINDOW_OFFSET.y); + this.transferRects.add(new RecipeTransferRect(transferRect, getOverlayIdentifier())); + + if (mRecipeMap.useModularUI) { + ModularWindow.Builder builder = mRecipeMap.createNEITemplate( + itemInputsInventory = new ItemStackHandler(mRecipeMap.mUsualInputCount), + itemOutputsInventory = new ItemStackHandler(mRecipeMap.mUsualOutputCount), + specialSlotInventory = new ItemStackHandler(1), + fluidInputsInventory = new ItemStackHandler(mRecipeMap.getUsualFluidInputCount()), + fluidOutputsInventory = new ItemStackHandler(mRecipeMap.getUsualFluidOutputCount()), + () -> ((float) getDrawTicks() % PROGRESSBAR_CYCLE_TICKS) / PROGRESSBAR_CYCLE_TICKS, + WINDOW_OFFSET); + modularWindow = builder.build(); + UIInfos.initializeWindow(Minecraft.getMinecraft().thePlayer, modularWindow); } else { - this.transferRects.add(new RecipeTransferRect(new Rectangle(65, 13, 36, 18), getOverlayIdentifier())); + itemInputsInventory = + itemOutputsInventory = specialSlotInventory = fluidInputsInventory = fluidOutputsInventory = null; + modularWindow = null; } } @@ -238,15 +277,31 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { @Override public void drawBackground(int recipe) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GuiDraw.changeTexture(getGuiTexture()); - GuiDraw.drawTexturedModalRect(-4, -8, 1, 3, 174, 78); + if (modularWindow != null) { + drawUI(modularWindow); + } else { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GuiDraw.changeTexture(getGuiTexture()); + GuiDraw.drawTexturedModalRect(-4, -8, 1, 3, 174, 78); + } + } + + @Override + public void drawForeground(int recipe) { + if (mRecipeMap.useModularUI) { + GL11.glColor4f(1, 1, 1, 1); + GL11.glDisable(GL11.GL_LIGHTING); + drawExtras(recipe); + } else { + super.drawForeground(recipe); + } } @Override public void onUpdate() { super.onUpdate(); if (!NEIClientUtils.shiftKey()) cycleTicksStatic++; + drawTicks++; } @Override @@ -577,7 +632,35 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { } protected int getDescriptionYOffset() { - return 73; + return mRecipeMap.neiBackgroundSize.height + mRecipeMap.neiBackgroundOffset.y + WINDOW_OFFSET.y + 3; + } + + protected void drawUI(ModularWindow window) { + for (IDrawable background : window.getBackground()) { + GlStateManager.pushMatrix(); + GlStateManager.translate( + WINDOW_OFFSET.x + mRecipeMap.neiBackgroundOffset.x, + WINDOW_OFFSET.y + mRecipeMap.neiBackgroundOffset.y, + 0); + GlStateManager.color(1f, 1f, 1f, 1f); + background.draw(Pos2d.ZERO, window.getSize(), 0); + GlStateManager.popMatrix(); + } + for (Widget widget : window.getChildren()) { + // NEI already did translation, so we can't use Widget#drawInternal here + GlStateManager.pushMatrix(); + GlStateManager.translate(widget.getPos().x, widget.getPos().y, 0); + GlStateManager.color(1, 1, 1, window.getAlpha()); + GlStateManager.enableBlend(); + // maybe we can use Minecraft#timer but none of the IDrawables use partialTicks + widget.drawBackground(0); + widget.draw(0); + GlStateManager.popMatrix(); + } + } + + public static int getDrawTicks() { + return drawTicks; } public static class GT_RectHandler implements IContainerInputHandler, IContainerTooltipHandler { @@ -730,70 +813,6 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { public final List<PositionedStack> mOutputs; public final List<PositionedStack> mInputs; - // Draw a grid of fluids and items (in that order). - @SuppressWarnings("unused") // Public API method - public void drawNEIItemAndFluidGrid( - ItemStack[] ItemArray, - FluidStack[] FluidArray, - int x_coord_origin, - int y_coord_origin, - int x_dir_max_items, - int y_max_dir_max_items, - GT_Recipe Recipe, - boolean is_input) { - if (ItemArray.length + FluidArray.length > x_dir_max_items * y_max_dir_max_items) { - GT_Log.err.println("Recipe cannot be properly displayed in NEI due to too many items/fluids."); - } - - int x_max = x_coord_origin + x_dir_max_items * 18; - - int x_coord = x_coord_origin; - int y_coord = y_coord_origin; - - for (FluidStack fluid : FluidArray) { - if (fluid != GT_Values.NF) { - if (is_input) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(fluid, true), x_coord, y_coord, true)); - } else { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(fluid, true), - x_coord, - y_coord, - GT_NEI_DefaultHandler.this.mRecipeMap.mNEIUnificateOutput)); - } - x_coord += 18; - if (x_coord == x_max) { - x_coord = x_coord_origin; - y_coord += 18; - } - } - } - - // Iterate over all items in array and display them. - int special_counter = 0; - for (ItemStack item : ItemArray) { - if (item != GT_Values.NI) { - if (is_input) { - mInputs.add(new FixedPositionedStack(item, x_coord, y_coord, true)); - } else { - mOutputs.add(new FixedPositionedStack( - item, - x_coord, - y_coord, - Recipe.getOutputChance(special_counter), - GT_NEI_DefaultHandler.this.mRecipeMap.mNEIUnificateOutput)); - special_counter++; - } - x_coord += 18; - if (x_coord == x_max) { - x_coord = x_coord_origin; - y_coord += 18; - } - } - } - } - // Draws a grid of items for NEI rendering. private void drawNEIItemGrid( ItemStack[] ItemArray, @@ -890,103 +909,207 @@ public class GT_NEI_DefaultHandler extends RecipeMapHandler { mOutputs = new ArrayList<>(); mInputs = new ArrayList<>(); - // Default GT NEI handler for drawing fluids/items on screen. - switch (GT_NEI_DefaultHandler.this.mRecipeMap.mUsualInputCount) { - case 0: - break; - case 1: // 1x1 - drawNEIItemGrid(aRecipe.mInputs, 48, 14, 1, 1, aRecipe, true); - break; - case 2: // 2x1 - drawNEIItemGrid(aRecipe.mInputs, 30, 14, 2, 1, aRecipe, true); - break; - case 3: // - drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 1, aRecipe, true); - break; - case 4: - case 5: - drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 2, aRecipe, true); - break; - case 6: - drawNEIItemGrid(aRecipe.mInputs, 12, 5, 3, 2, aRecipe, true); - break; - default: - drawNEIItemGrid(aRecipe.mInputs, 12, -4, 3, 3, aRecipe, true); - } - - switch (GT_NEI_DefaultHandler.this.mRecipeMap.mUsualOutputCount) { - case 0: - break; - case 1: - drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 1, 1, aRecipe, false); - break; - case 2: - drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 2, 1, aRecipe, false); - break; - case 3: - drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 3, 1, aRecipe, false); - break; - case 4: - drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 2, 2, aRecipe, false); - break; - case 5: - case 6: - drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 3, 2, aRecipe, false); - break; - default: - drawNEIItemGrid(aRecipe.mOutputs, 102, -4, 3, 3, aRecipe, false); - } - - // ??? No idea what this does. Leaving it alone. - if (aRecipe.mSpecialItems != null) { - this.mInputs.add(new FixedPositionedStack(aRecipe.mSpecialItems, 120, 52)); - } - - if ((aRecipe.mFluidInputs.length > 0) - && (aRecipe.mFluidInputs[0] != null) - && (aRecipe.mFluidInputs[0].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[0], true), 48, 52)); - if ((aRecipe.mFluidInputs.length > 1) - && (aRecipe.mFluidInputs[1] != null) - && (aRecipe.mFluidInputs[1].getFluid() != null)) { - this.mInputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[1], true), 30, 52)); + if (GT_NEI_DefaultHandler.this.mRecipeMap.useModularUI) { + for (Widget child : modularWindow.getChildren()) { + if (child instanceof SlotWidget) { + SlotWidget widget = (SlotWidget) child; + if (widget.getMcSlot().getItemHandler() == itemInputsInventory) { + int i = widget.getMcSlot().getSlotIndex(); + Object input = aRecipe instanceof GT_Recipe.GT_Recipe_WithAlt + ? ((GT_Recipe.GT_Recipe_WithAlt) aRecipe).getAltRepresentativeInput(i) + : aRecipe.getRepresentativeInput(i); + if (input != null) { + mInputs.add(new FixedPositionedStack( + input, widget.getPos().x + 1, widget.getPos().y + 1, true)); + } + } else if (widget.getMcSlot().getItemHandler() == itemOutputsInventory) { + int i = widget.getMcSlot().getSlotIndex(); + if (aRecipe.mOutputs.length > i && aRecipe.mOutputs[i] != null) { + mOutputs.add(new FixedPositionedStack( + aRecipe.mOutputs[i], + widget.getPos().x + 1, + widget.getPos().y + 1, + aRecipe.getOutputChance(i), + GT_NEI_DefaultHandler.this.mRecipeMap.mNEIUnificateOutput)); + } + } else if (widget.getMcSlot().getItemHandler() == specialSlotInventory) { + if (aRecipe.mSpecialItems != null) { + mInputs.add(new FixedPositionedStack( + aRecipe.mSpecialItems, widget.getPos().x + 1, widget.getPos().y + 1)); + } + } else if (widget.getMcSlot().getItemHandler() == fluidInputsInventory) { + int i = widget.getMcSlot().getSlotIndex(); + if (aRecipe.mFluidInputs.length > i + && aRecipe.mFluidInputs[i] != null + && aRecipe.mFluidInputs[i].getFluid() != null) { + mInputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[i], true), + widget.getPos().x + 1, + widget.getPos().y + 1)); + } + } else if (widget.getMcSlot().getItemHandler() == fluidOutputsInventory) { + int i = widget.getMcSlot().getSlotIndex(); + if (aRecipe.mFluidOutputs.length > i + && aRecipe.mFluidOutputs[i] != null + && aRecipe.mFluidOutputs[i].getFluid() != null) { + mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[i], true), + widget.getPos().x + 1, + widget.getPos().y + 1)); + } + } + } } - } - if (aRecipe.mFluidOutputs.length > 1) { - if (aRecipe.mFluidOutputs[0] != null && (aRecipe.mFluidOutputs[0].getFluid() != null)) { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[0], true), 120, 5)); + // items and fluids that exceed usual count + UIHelper.forEachSlots( + (i, backgrounds, pos) -> { + if (i >= GT_NEI_DefaultHandler.this.mRecipeMap.mUsualInputCount + && aRecipe.mInputs[i] != null) { + mInputs.add(new FixedPositionedStack(aRecipe.mInputs[i], pos.x + 1, pos.y + 1, true)); + } + }, + (i, backgrounds, pos) -> { + if (i >= GT_NEI_DefaultHandler.this.mRecipeMap.mUsualOutputCount + && aRecipe.mOutputs[i] != null) { + mOutputs.add(new FixedPositionedStack( + aRecipe.mOutputs[i], + pos.x + 1, + pos.y + 1, + aRecipe.getOutputChance(i), + GT_NEI_DefaultHandler.this.mRecipeMap.mNEIUnificateOutput)); + } + }, + (i, backgrounds, pos) -> {}, + (i, backgrounds, pos) -> { + if (i >= GT_NEI_DefaultHandler.this.mRecipeMap.getUsualFluidInputCount() + && aRecipe.mFluidInputs[i] != null + && aRecipe.mFluidInputs[i].getFluid() != null) { + mInputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[i], true), + pos.x + 1, + pos.y + 1)); + } + }, + (i, backgrounds, pos) -> { + if (i >= GT_NEI_DefaultHandler.this.mRecipeMap.getUsualFluidOutputCount() + && aRecipe.mFluidOutputs[i] != null + && aRecipe.mFluidOutputs[i].getFluid() != null) { + mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[i], true), + pos.x + 1, + pos.y + 1)); + } + }, + null, + null, + GT_NEI_DefaultHandler.this.mRecipeMap, + aRecipe.mInputs.length, + aRecipe.mOutputs.length, + aRecipe.mFluidInputs.length, + aRecipe.mFluidOutputs.length, + SteamVariant.NONE, + WINDOW_OFFSET); + } else { + // todo remove after all the migrations are done + // Default GT NEI handler for drawing fluids/items on screen. + switch (GT_NEI_DefaultHandler.this.mRecipeMap.mUsualInputCount) { + case 0: + break; + case 1: // 1x1 + drawNEIItemGrid(aRecipe.mInputs, 48, 14, 1, 1, aRecipe, true); + break; + case 2: // 2x1 + drawNEIItemGrid(aRecipe.mInputs, 30, 14, 2, 1, aRecipe, true); + break; + case 3: // + drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 1, aRecipe, true); + break; + case 4: + case 5: + drawNEIItemGrid(aRecipe.mInputs, 12, 14, 3, 2, aRecipe, true); + break; + case 6: + drawNEIItemGrid(aRecipe.mInputs, 12, 5, 3, 2, aRecipe, true); + break; + default: + drawNEIItemGrid(aRecipe.mInputs, 12, -4, 3, 3, aRecipe, true); } - if (aRecipe.mFluidOutputs[1] != null && (aRecipe.mFluidOutputs[1].getFluid() != null)) { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[1], true), 138, 5)); + + switch (GT_NEI_DefaultHandler.this.mRecipeMap.mUsualOutputCount) { + case 0: + break; + case 1: + drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 1, 1, aRecipe, false); + break; + case 2: + drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 2, 1, aRecipe, false); + break; + case 3: + drawNEIItemGrid(aRecipe.mOutputs, 102, 14, 3, 1, aRecipe, false); + break; + case 4: + drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 2, 2, aRecipe, false); + break; + case 5: + case 6: + drawNEIItemGrid(aRecipe.mOutputs, 102, 5, 3, 2, aRecipe, false); + break; + default: + drawNEIItemGrid(aRecipe.mOutputs, 102, -4, 3, 3, aRecipe, false); } - if (aRecipe.mFluidOutputs.length > 2 - && aRecipe.mFluidOutputs[2] != null - && (aRecipe.mFluidOutputs[2].getFluid() != null)) { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[2], true), 102, 23)); + + // ??? No idea what this does. Leaving it alone. + if (aRecipe.mSpecialItems != null) { + this.mInputs.add(new FixedPositionedStack(aRecipe.mSpecialItems, 120, 52)); } - if (aRecipe.mFluidOutputs.length > 3 - && aRecipe.mFluidOutputs[3] != null - && (aRecipe.mFluidOutputs[3].getFluid() != null)) { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[3], true), 120, 23)); + + if ((aRecipe.mFluidInputs.length > 0) + && (aRecipe.mFluidInputs[0] != null) + && (aRecipe.mFluidInputs[0].getFluid() != null)) { + this.mInputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[0], true), 48, 52)); + if ((aRecipe.mFluidInputs.length > 1) + && (aRecipe.mFluidInputs[1] != null) + && (aRecipe.mFluidInputs[1].getFluid() != null)) { + this.mInputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidInputs[1], true), 30, 52)); + } } - if (aRecipe.mFluidOutputs.length > 4 - && aRecipe.mFluidOutputs[4] != null - && (aRecipe.mFluidOutputs[4].getFluid() != null)) { + + if (aRecipe.mFluidOutputs.length > 1) { + if (aRecipe.mFluidOutputs[0] != null && (aRecipe.mFluidOutputs[0].getFluid() != null)) { + this.mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[0], true), 120, 5)); + } + if (aRecipe.mFluidOutputs[1] != null && (aRecipe.mFluidOutputs[1].getFluid() != null)) { + this.mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[1], true), 138, 5)); + } + if (aRecipe.mFluidOutputs.length > 2 + && aRecipe.mFluidOutputs[2] != null + && (aRecipe.mFluidOutputs[2].getFluid() != null)) { + this.mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[2], true), 102, 23)); + } + if (aRecipe.mFluidOutputs.length > 3 + && aRecipe.mFluidOutputs[3] != null + && (aRecipe.mFluidOutputs[3].getFluid() != null)) { + this.mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[3], true), 120, 23)); + } + if (aRecipe.mFluidOutputs.length > 4 + && aRecipe.mFluidOutputs[4] != null + && (aRecipe.mFluidOutputs[4].getFluid() != null)) { + this.mOutputs.add(new FixedPositionedStack( + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[4], true), 138, 23)); + } + } else if ((aRecipe.mFluidOutputs.length > 0) + && (aRecipe.mFluidOutputs[0] != null) + && (aRecipe.mFluidOutputs[0].getFluid() != null)) { this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[4], true), 138, 23)); + GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[0], true), 102, 52)); } - } else if ((aRecipe.mFluidOutputs.length > 0) - && (aRecipe.mFluidOutputs[0] != null) - && (aRecipe.mFluidOutputs[0].getFluid() != null)) { - this.mOutputs.add(new FixedPositionedStack( - GT_Utility.getFluidDisplayStack(aRecipe.mFluidOutputs[0], true), 102, 52)); } } diff --git a/src/main/java/gregtech/nei/IMCForNEI.java b/src/main/java/gregtech/nei/IMCForNEI.java index 8f52f4ba97..ca0b0daf34 100644 --- a/src/main/java/gregtech/nei/IMCForNEI.java +++ b/src/main/java/gregtech/nei/IMCForNEI.java @@ -10,7 +10,7 @@ public class IMCForNEI { return; } - sendHandler("gt.recipe.plasmaforge", "gregtech:gt.blockmachines:1004"); + sendHandler("gt.recipe.plasmaforge", "gregtech:gt.blockmachines:1004", 1); sendCatalyst("gt.recipe.plasmaforge", "gregtech:gt.blockmachines:1004"); sendHandler("gt.recipe.complexfusionreactor", "gregtech:gt.blockmachines:1193"); @@ -19,9 +19,12 @@ public class IMCForNEI { sendCatalyst("gt.recipe.complexfusionreactor", "gregtech:gt.blockmachines:1195"); sendCatalyst("gt.recipe.gasturbinefuel", "gregtech:gt.blockmachines:1005", -1); + + // overwrite yShift to 6 + sendHandler("gt.recipe.fakeAssemblylineProcess", "gregtech:gt.blockmachines:1170"); } - private static void sendHandler(String aName, String aBlock) { + private static void sendHandler(String aName, String aBlock, int aMaxRecipesPerPage) { NBTTagCompound aNBT = new NBTTagCompound(); aNBT.setString("handler", aName); aNBT.setString("modName", "GregTech"); @@ -30,11 +33,15 @@ public class IMCForNEI { aNBT.setString("itemName", aBlock); aNBT.setInteger("handlerHeight", 135); aNBT.setInteger("handlerWidth", 166); - aNBT.setInteger("maxRecipesPerPage", 2); + aNBT.setInteger("maxRecipesPerPage", aMaxRecipesPerPage); aNBT.setInteger("yShift", 6); FMLInterModComms.sendMessage("NotEnoughItems", "registerHandlerInfo", aNBT); } + private static void sendHandler(String aName, String aBlock) { + sendHandler(aName, aBlock, 2); + } + private static void sendCatalyst(String aName, String aStack, int aPriority) { NBTTagCompound aNBT = new NBTTagCompound(); aNBT.setString("handlerID", aName); diff --git a/src/main/java/gregtech/nei/NEI_GT_Config.java b/src/main/java/gregtech/nei/NEI_GT_Config.java index 150b434e6b..2a85b788ab 100644 --- a/src/main/java/gregtech/nei/NEI_GT_Config.java +++ b/src/main/java/gregtech/nei/NEI_GT_Config.java @@ -31,7 +31,6 @@ public class NEI_GT_Config implements IConfigureNEI { Comparator.comparingInt(handler -> RECIPE_MAP_ORDERING.getOrDefault(handler.getRecipeMap(), 0)); public static boolean sIsAdded = true; - public static GT_NEI_AssLineHandler ALH; private static void addHandler(TemplateRecipeHandler handler) { FMLInterModComms.sendRuntimeMessage( @@ -49,9 +48,6 @@ public class NEI_GT_Config implements IConfigureNEI { if (FMLCommonHandler.instance().getEffectiveSide().isClient()) { List<RecipeMapHandler> handlers = new ArrayList<>(); - ALH = new GT_NEI_AssLineHandler(GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes); - handlers.add(ALH); - for (GT_Recipe.GT_Recipe_Map tMap : GT_Recipe.GT_Recipe_Map.sMappings) { if (tMap.mNEIAllowed) { handlers.add(new GT_NEI_DefaultHandler(tMap)); |