aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity/implementations
diff options
context:
space:
mode:
authorGlodBlock <1356392126@qq.com>2021-10-09 15:03:51 +0800
committerGlodBlock <1356392126@qq.com>2021-10-09 15:03:51 +0800
commite2ad60c325be21de9b6f4c8e906603d8caf7381f (patch)
tree4edf20a8de630b4ea6ed9f5f6989ea559f2e9772 /src/main/java/gregtech/api/metatileentity/implementations
parent3528df84828a6d237d3a29674a465c3ba806a0cb (diff)
downloadGT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.tar.gz
GT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.tar.bz2
GT5-Unofficial-e2ad60c325be21de9b6f4c8e906603d8caf7381f.zip
add GUI for output hatch fluid lock
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity/implementations')
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java139
1 files changed, 90 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