diff options
author | GlodBlock <1356392126@qq.com> | 2021-10-09 15:03:51 +0800 |
---|---|---|
committer | GlodBlock <1356392126@qq.com> | 2021-10-09 15:03:51 +0800 |
commit | e2ad60c325be21de9b6f4c8e906603d8caf7381f (patch) | |
tree | 4edf20a8de630b4ea6ed9f5f6989ea559f2e9772 /src | |
parent | 3528df84828a6d237d3a29674a465c3ba806a0cb (diff) | |
download | GT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.tar.gz GT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.tar.bz2 GT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.zip |
add GUI for output hatch fluid lock
Diffstat (limited to 'src')
4 files changed, 252 insertions, 49 deletions
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 bb23452220..eb75094a02 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 @@ -6,39 +6,39 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Utility; +import gregtech.common.gui.GT_Container_OutputHatch; +import gregtech.common.gui.GT_GUIContainer_OutputHatch; 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.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.*; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { - private String lockedFluidName = null; - private EntityPlayer playerThatLockedfluid = null; + private String lockedFluidName = null; + private EntityPlayer playerThatLockedfluid = null; public byte mMode = 0; public GT_MetaTileEntity_Hatch_Output(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, 3, new String[]{ - "Fluid Output for Multiblocks", - "Capacity: " + GT_Utility.formatNumbers(8000+8000*(aTier*(aTier+1)>>1)) + "L", - "Right click with screwdriver to restrict output", - "Can be restricted to put out Items and/or Steam/No Steam/1 specific Fluid", - "Restricted Output Hatches are given priority for Multiblock Fluid output"}); + super(aID, aName, aNameRegional, aTier, 4, new String[]{ + "Fluid Output for Multiblocks", + "Capacity: " + GT_Utility.formatNumbers(8000+8000*(aTier*(aTier+1)>>1)) + "L", + "Right click with screwdriver to restrict output", + "Can be restricted to put out Items and/or Steam/No Steam/1 specific Fluid", + "Restricted Output Hatches are given priority for Multiblock Fluid output"}); } public GT_MetaTileEntity_Hatch_Output(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); + super(aName, aTier, 4, aDescription, aTextures); } public GT_MetaTileEntity_Hatch_Output(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, 3, aDescription, aTextures); + super(aName, aTier, 4, aDescription, aTextures); } @Override @@ -151,6 +151,39 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { } @Override + public void updateFluidDisplayItem() { + super.updateFluidDisplayItem(); + if (lockedFluidName == null || mMode < 8) mInventory[3] = null; + else { + FluidStack tLockedFluid = FluidRegistry.getFluidStack(lockedFluidName.replace("fluid.", "") + .replace(".name", "").replace("ic2.fluid", "ic2").toLowerCase(), 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); + } + else { + mInventory[3] = null; + } + } + } + + @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()); + } + + @Override public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return aSide == aBaseMetaTileEntity.getFrontFacing() && aIndex == 1; } @@ -170,9 +203,9 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) return; if (aPlayer.isSneaking()) { - mMode = (byte) ((mMode + 9) % 10); + mMode = (byte) ((mMode + 9) % 10); } else { - mMode = (byte) ((mMode + 1) % 10); + mMode = (byte) ((mMode + 1) % 10); } String inBrackets; switch (mMode) { @@ -209,29 +242,30 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { this.setLockedFluidName(null); break; case 8: - playerThatLockedfluid = aPlayer; - if (mFluid == null) { + playerThatLockedfluid = aPlayer; + if (mFluid == null) { this.setLockedFluidName(null); - inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); - } else { - this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); - inBrackets = this.getDrainableStack().getLocalizedName(); - } + inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); + } else { + this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); + inBrackets = this.getDrainableStack().getLocalizedName(); + } GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.1", "Outputs items and 1 specific Fluid"), inBrackets)); break; case 9: - playerThatLockedfluid = aPlayer; - if (mFluid == null) { + playerThatLockedfluid = aPlayer; + if (mFluid == null) { this.setLockedFluidName(null); - inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); - } else { - this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); - inBrackets = this.getDrainableStack().getLocalizedName(); - } + inBrackets = trans("115.3","currently none, will be locked to the next that is put in (or use fluid cell to lock)"); + } else { + this.setLockedFluidName(this.getDrainableStack().getUnlocalizedName()); + inBrackets = this.getDrainableStack().getLocalizedName(); + } GT_Utility.sendChatToPlayer(aPlayer, String.format("%s (%s)", trans("151.2", "Outputs 1 specific Fluid"), inBrackets)); break; } } + private boolean tryToLockHatch(EntityPlayer aPlayer, byte aSide) { if (!getBaseMetaTileEntity().getCoverBehaviorAtSide(aSide).isGUIClickable(aSide, getBaseMetaTileEntity().getCoverIDAtSide(aSide), getBaseMetaTileEntity().getCoverDataAtSide(aSide), getBaseMetaTileEntity())) return false; @@ -260,6 +294,11 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { } return false; } + + public byte getMode() { + return mMode; + } + @Override public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, byte aSide, float aX, float aY, float aZ) { if (tryToLockHatch(aPlayer, aSide)) @@ -269,7 +308,7 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { @Override public String trans(String aKey, String aEnglish){ - return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); + return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_"+aKey, aEnglish, false); } public boolean outputsSteam() { @@ -283,44 +322,46 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch { public boolean outputsItems() { return mMode % 4 < 2 && mMode != 9; } - + public boolean isFluidLocked(){ - return mMode == 8 || mMode == 9; + return mMode == 8 || mMode == 9; } - + public String getLockedFluidName() { - return lockedFluidName; + return lockedFluidName; } - + public void setLockedFluidName(String lockedFluidName) { - this.lockedFluidName = lockedFluidName; + this.lockedFluidName = lockedFluidName; } @Override public int getTankPressure() { return +100; } - + @Override protected void onEmptyingContainerWhenEmpty() { - if (this.lockedFluidName == null && this.mFluid != null) { - this.setLockedFluidName(this.mFluid.getUnlocalizedName()); - GT_Utility.sendChatToPlayer(playerThatLockedfluid, String.format(trans("151.4","Sucessfully locked Fluid to %s"), mFluid.getLocalizedName())); - } + if (this.lockedFluidName == null && this.mFluid != null) { + this.setLockedFluidName(this.mFluid.getUnlocalizedName()); + GT_Utility.sendChatToPlayer(playerThatLockedfluid, String.format(trans("151.4","Sucessfully locked Fluid to %s"), mFluid.getLocalizedName())); + } } + @Override public boolean isGivingInformation() { return true; } + @Override public String[] getInfoData() { return new String[]{ - EnumChatFormatting.BLUE + "Output Hatch" + EnumChatFormatting.RESET, - "Stored Fluid:", - EnumChatFormatting.GOLD + (mFluid == null ? "No Fluid" : mFluid.getLocalizedName()) + EnumChatFormatting.RESET, - EnumChatFormatting.GREEN + GT_Utility.formatNumbers(mFluid == null ? 0 : mFluid.amount) + " L" + EnumChatFormatting.RESET + " " + - EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(getCapacity()) + " L"+ EnumChatFormatting.RESET, - lockedFluidName == null ? "Not Locked" : ("Locked to " + StatCollector.translateToLocal(getLockedFluidName())) + EnumChatFormatting.BLUE + "Output Hatch" + EnumChatFormatting.RESET, + "Stored Fluid:", + EnumChatFormatting.GOLD + (mFluid == null ? "No Fluid" : mFluid.getLocalizedName()) + EnumChatFormatting.RESET, + EnumChatFormatting.GREEN + GT_Utility.formatNumbers(mFluid == null ? 0 : mFluid.amount) + " L" + EnumChatFormatting.RESET + " " + + EnumChatFormatting.YELLOW + GT_Utility.formatNumbers(getCapacity()) + " L"+ EnumChatFormatting.RESET, + lockedFluidName == null ? "Not Locked" : ("Locked to " + StatCollector.translateToLocal(getLockedFluidName())) }; } -} +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java b/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java new file mode 100644 index 0000000000..1006acebf1 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_Container_OutputHatch.java @@ -0,0 +1,123 @@ +package gregtech.common.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +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.ICrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import java.nio.ByteBuffer; + +public class GT_Container_OutputHatch extends GT_Container_BasicTank { + + private ByteBuffer buffer; + private String fluidName = ""; + private byte mMode; + + 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.getUnlocalizedName().equals(tHatch.getLockedFluidName()))) { + tHatch.setLockedFluidName(null); + GT_Utility.sendChatToPlayer(aPlayer, trans("300", "Fluid Lock Cleared.")); + tHatch.mMode = 0; + fluidName = ""; + } + else { + tHatch.setLockedFluidName(tReadyLockFluid.getUnlocalizedName()); + GT_Utility.sendChatToPlayer(aPlayer, String.format(trans("151.4", "Sucessfully locked Fluid to %s"), tReadyLockFluid.getLocalizedName())); + tHatch.mMode = 9; + fluidName = tReadyLockFluid.getUnlocalizedName(); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void addCraftingToCrafters(ICrafting clientHandle) { + buffer.putInt(0, fluidName.length()); + buffer.put(Integer.BYTES, mMode); + for (int i = 0; i < fluidName.length(); i++) { + buffer.putChar(Integer.BYTES + Character.BYTES * i + 1, fluidName.charAt(i)); + } + sendStateUpdate(clientHandle); + super.addCraftingToCrafters(clientHandle); + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (buffer == null) { + buffer = ByteBuffer.allocate(256); + } + if(mTileEntity.isServerSide()) { + GT_MetaTileEntity_Hatch_Output tile = (GT_MetaTileEntity_Hatch_Output) mTileEntity.getMetaTileEntity(); + if (tile == null) return; + fluidName = tile.getLockedFluidName() == null ? "" : tile.getLockedFluidName(); + mMode = tile.getMode(); + buffer.putInt(0, fluidName.length()); + buffer.put(Integer.BYTES, mMode); + for (int i = 0; i < fluidName.length(); i++) { + buffer.putChar(Integer.BYTES + Character.BYTES * i + 1, fluidName.charAt(i)); + } + for (Object clientHandle : this.crafters) { + sendStateUpdate((ICrafting) clientHandle); + } + } + } + + private void sendStateUpdate(ICrafting clientHandle) { + final int bytes = Character.BYTES * fluidName.length() + Integer.BYTES + 1; + for (int i = 0; i < bytes; i++) { + clientHandle.sendProgressBarUpdate(this, i + 110, buffer.get(i)); + } + } + + @SideOnly(Side.CLIENT) + public void updateProgressBar(int index, int value) { + super.updateProgressBar(index, value); + index = index - 110; + if(index >= 0 && index < buffer.capacity()) { + buffer.put(index, (byte) value); + } + } + + @SideOnly(Side.CLIENT) + public String getFluidName() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < buffer.getInt(0); ++i) { + sb.append(buffer.getChar(i * Character.BYTES + Integer.BYTES + 1)); + } + byte mode = buffer.get(Integer.BYTES); + FluidStack tFluid = FluidRegistry.getFluidStack(sb.toString().replace("fluid.", "") + .replace(".name", "").replace("ic2.fluid", "ic2").toLowerCase(), 1); + if (tFluid == null || mode < 8) return "Empty"; + else return tFluid.getLocalizedName().replace("fluid.", ""); + } +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java b/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java new file mode 100644 index 0000000000..1adf66c1b7 --- /dev/null +++ b/src/main/java/gregtech/common/gui/GT_GUIContainer_OutputHatch.java @@ -0,0 +1,39 @@ +package gregtech.common.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; + +import static gregtech.api.enums.GT_Values.RES_PATH_GUI; + +public class GT_GUIContainer_OutputHatch extends GT_GUIContainerMetaTile_Machine { + + private final String mName; + + 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 par1, int par2) { + fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752); + fontRendererObj.drawString(mName, 8, 6, 4210752); + if (mContainer != null) { + fontRendererObj.drawString("Liquid Amount", 10, 20, 16448255); + fontRendererObj.drawString(GT_Utility.parseNumberToString(((GT_Container_OutputHatch) mContainer).mContent), 10, 30, 16448255); + fontRendererObj.drawString("Locked Fluid", 101, 20, 16448255); + fontRendererObj.drawString(((GT_Container_OutputHatch) mContainer).getFluidName(), 101, 30, 16448255); + } + } + + @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); + } +}
\ No newline at end of file diff --git a/src/main/resources/assets/gregtech/textures/gui/OutputHatch.png b/src/main/resources/assets/gregtech/textures/gui/OutputHatch.png Binary files differnew file mode 100644 index 0000000000..e0fd3f527e --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/OutputHatch.png |