aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorYang Xizhi <60341015+GlodBlock@users.noreply.github.com>2022-10-17 18:40:06 +0800
committerGitHub <noreply@github.com>2022-10-17 12:40:06 +0200
commit4bcf8abf671020ff1ed07632af010c367509ab31 (patch)
tree47d3fa25406b8d2e0fa2028337b35bdda49a56ca /src/main
parentbc463793934ad1d9c32c34f37c40e66a5107ebed (diff)
downloadGT5-Unofficial-4bcf8abf671020ff1ed07632af010c367509ab31.tar.gz
GT5-Unofficial-4bcf8abf671020ff1ed07632af010c367509ab31.tar.bz2
GT5-Unofficial-4bcf8abf671020ff1ed07632af010c367509ab31.zip
me output hatch (#1473)
* me input hacth * sa
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/gregtech/api/enums/ItemList.java1
-rw-r--r--src/main/java/gregtech/api/enums/Textures.java2
-rw-r--r--src/main/java/gregtech/api/interfaces/metatileentity/IFluidLockable.java2
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Output.java10
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Output_ME.java293
-rw-r--r--src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java3
-rw-r--r--src/main/resources/assets/gregtech/lang/en_US.lang2
-rw-r--r--src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH.pngbin0 -> 187 bytes
-rw-r--r--src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH_ACTIVE.pngbin0 -> 187 bytes
9 files changed, 312 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/enums/ItemList.java b/src/main/java/gregtech/api/enums/ItemList.java
index 626f97e817..b263219304 100644
--- a/src/main/java/gregtech/api/enums/ItemList.java
+++ b/src/main/java/gregtech/api/enums/ItemList.java
@@ -1549,6 +1549,7 @@ public enum ItemList implements IItemContainer {
Long_Distance_Pipeline_Item_Pipe,
Hatch_Output_Bus_ME,
+ Hatch_Output_ME,
NULL,
Cover_AdvancedRedstoneTransmitterExternal,
diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java
index 176841dc0c..7350921441 100644
--- a/src/main/java/gregtech/api/enums/Textures.java
+++ b/src/main/java/gregtech/api/enums/Textures.java
@@ -1277,6 +1277,8 @@ public class Textures {
OVERLAY_ME_INPUT_HATCH_ACTIVE,
OVERLAY_ME_CRAFTING_HATCH,
OVERLAY_ME_CRAFTING_HATCH_ACTIVE,
+ OVERLAY_ME_FLUID_HATCH,
+ OVERLAY_ME_FLUID_HATCH_ACTIVE,
STRUCTURE_MARK;
diff --git a/src/main/java/gregtech/api/interfaces/metatileentity/IFluidLockable.java b/src/main/java/gregtech/api/interfaces/metatileentity/IFluidLockable.java
index 688a85b521..bac9cffba0 100644
--- a/src/main/java/gregtech/api/interfaces/metatileentity/IFluidLockable.java
+++ b/src/main/java/gregtech/api/interfaces/metatileentity/IFluidLockable.java
@@ -5,7 +5,7 @@ import net.minecraftforge.fluids.Fluid;
/**
* Implement this interface if your MetaTileEntity supports fluid lock mechanism.
*/
-@SuppressWarnings({"BooleanMethodIsAlwaysInverted", "unused"})
+@SuppressWarnings({"BooleanMethodIsAlwaysInverted"})
public interface IFluidLockable {
/**
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 4d281f72b5..dabdd7dbb8 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
@@ -46,6 +46,16 @@ public class GT_MetaTileEntity_Hatch_Output extends GT_MetaTileEntity_Hatch impl
super(aName, aTier, 4, aDescription, aTextures);
}
+ public GT_MetaTileEntity_Hatch_Output(
+ int aID, String aName, String aNameRegional, int aTier, String[] aDescription, int inventorySize) {
+ super(aID, aName, aNameRegional, aTier, inventorySize, aDescription);
+ }
+
+ public GT_MetaTileEntity_Hatch_Output(
+ String name, int tier, int slots, String[] description, ITexture[][][] textures) {
+ super(name, tier, slots, description, textures);
+ }
+
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return GT_Mod.gregtechproxy.mRenderIndicatorsOnHatch
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Output_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Output_ME.java
new file mode 100644
index 0000000000..434c78fdc8
--- /dev/null
+++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Output_ME.java
@@ -0,0 +1,293 @@
+package gregtech.common.tileentities.machines;
+
+import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_FLUID_HATCH;
+import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_ME_FLUID_HATCH_ACTIVE;
+
+import appeng.api.AEApi;
+import appeng.api.networking.GridFlags;
+import appeng.api.networking.security.BaseActionSource;
+import appeng.api.networking.security.IActionHost;
+import appeng.api.networking.security.MachineSource;
+import appeng.api.storage.IMEMonitor;
+import appeng.api.storage.data.IAEFluidStack;
+import appeng.api.storage.data.IItemList;
+import appeng.api.util.AECableType;
+import appeng.me.GridAccessException;
+import appeng.me.helpers.AENetworkProxy;
+import appeng.me.helpers.IGridProxyable;
+import appeng.util.IWideReadableNumberConverter;
+import appeng.util.Platform;
+import appeng.util.ReadableNumberConverter;
+import cpw.mods.fml.common.Optional;
+import gregtech.GT_Mod;
+import gregtech.api.GregTech_API;
+import gregtech.api.enums.GT_Values;
+import gregtech.api.enums.ItemList;
+import gregtech.api.interfaces.ITexture;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
+import gregtech.api.render.TextureFactory;
+import gregtech.api.util.GT_Utility;
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.nbt.NBTBase;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.FluidStack;
+
+public class GT_MetaTileEntity_Hatch_Output_ME extends GT_MetaTileEntity_Hatch_Output {
+ private BaseActionSource requestSource = null;
+ private AENetworkProxy gridProxy = null;
+ IItemList<IAEFluidStack> fluidCache =
+ GregTech_API.mAE2 ? AEApi.instance().storage().createFluidList() : null;
+ long lastOutputTick = 0;
+ long tickCounter = 0;
+ boolean lastOutputFailed = false;
+ boolean infiniteCache = true;
+
+ public GT_MetaTileEntity_Hatch_Output_ME(int aID, String aName, String aNameRegional) {
+ super(
+ aID,
+ aName,
+ aNameRegional,
+ 1,
+ new String[] {
+ "Fluid Output for Multiblocks", "Stores directly into ME",
+ "To use in GT++ multiblocks", " turn off overflow control",
+ " with a soldering iron."
+ },
+ 0);
+ }
+
+ public GT_MetaTileEntity_Hatch_Output_ME(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
+ super(aName, aTier, 0, aDescription, aTextures);
+ }
+
+ @Override
+ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
+ return new GT_MetaTileEntity_Hatch_Output_ME(mName, mTier, mDescriptionArray, mTextures);
+ }
+
+ @Override
+ public ITexture[] getTexturesActive(ITexture aBaseTexture) {
+ return new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_ME_FLUID_HATCH)};
+ }
+
+ @Override
+ public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
+ return new ITexture[] {aBaseTexture, TextureFactory.of(OVERLAY_ME_FLUID_HATCH_ACTIVE)};
+ }
+
+ @Override
+ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
+ super.onFirstTick(aBaseMetaTileEntity);
+ getProxy().onReady();
+ }
+
+ @Override
+ public int fill(FluidStack aFluid, boolean doFill) {
+ if (!GregTech_API.mAE2) return 0;
+ if (doFill) {
+ return tryFillAE(aFluid);
+ } else {
+ if ((!infiniteCache && lastOutputFailed) || aFluid == null) return 0;
+ return aFluid.amount;
+ }
+ }
+
+ /**
+ * Attempt to store fluid in connected ME network. Returns how much fluid is accepted (if the network was down e.g.)
+ *
+ * @param aFluid input fluid
+ * @return amount of fluid filled
+ */
+ @Optional.Method(modid = "appliedenergistics2")
+ public int tryFillAE(final FluidStack aFluid) {
+ if ((!infiniteCache && lastOutputFailed) || aFluid == null) return 0;
+ fluidCache.add(AEApi.instance().storage().createFluidStack(aFluid));
+ return aFluid.amount;
+ }
+
+ @Optional.Method(modid = "appliedenergistics2")
+ private BaseActionSource getRequest() {
+ if (requestSource == null) requestSource = new MachineSource((IActionHost) getBaseMetaTileEntity());
+ return requestSource;
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public AECableType getCableConnectionType(ForgeDirection forgeDirection) {
+ return isOutputFacing((byte) forgeDirection.ordinal()) ? AECableType.SMART : AECableType.NONE;
+ }
+
+ @Override
+ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ return false;
+ }
+
+ @Override
+ public boolean isValidSlot(int aIndex) {
+ return true;
+ }
+
+ @Override
+ public boolean doesFillContainers() {
+ return false;
+ }
+
+ @Override
+ public void updateFluidDisplayItem() {}
+
+ @Override
+ public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
+ // Don't allow to lock fluid in me fluid hatch
+ if (!getBaseMetaTileEntity()
+ .getCoverBehaviorAtSideNew(aSide)
+ .isGUIClickable(
+ aSide,
+ getBaseMetaTileEntity().getCoverIDAtSide(aSide),
+ getBaseMetaTileEntity().getComplexCoverDataAtSide(aSide),
+ getBaseMetaTileEntity())) return;
+ infiniteCache = !infiniteCache;
+ GT_Utility.sendChatToPlayer(
+ aPlayer, StatCollector.translateToLocal("GT5U.hatch.infiniteCacheFluid." + infiniteCache));
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public AENetworkProxy getProxy() {
+ if (gridProxy == null) {
+ if (getBaseMetaTileEntity() instanceof IGridProxyable) {
+ gridProxy = new AENetworkProxy(
+ (IGridProxyable) getBaseMetaTileEntity(), "proxy", ItemList.Hatch_Output_ME.get(1), true);
+ gridProxy.setFlags(GridFlags.REQUIRE_CHANNEL);
+ if (getBaseMetaTileEntity().getWorld() != null)
+ gridProxy.setOwner(getBaseMetaTileEntity()
+ .getWorld()
+ .getPlayerEntityByName(getBaseMetaTileEntity().getOwnerName()));
+ }
+ }
+ return this.gridProxy;
+ }
+
+ @Override
+ @Optional.Method(modid = "appliedenergistics2")
+ public void gridChanged() {}
+
+ @Optional.Method(modid = "appliedenergistics2")
+ private void flushCachedStack() {
+ lastOutputFailed = false;
+ AENetworkProxy proxy = getProxy();
+ if (proxy == null) {
+ lastOutputFailed = true;
+ return;
+ }
+ try {
+ IMEMonitor<IAEFluidStack> sg = proxy.getStorage().getFluidInventory();
+ for (IAEFluidStack s : fluidCache) {
+ if (s.getStackSize() == 0) continue;
+ IAEFluidStack rest = Platform.poweredInsert(proxy.getEnergy(), sg, s, getRequest());
+ if (rest != null && rest.getStackSize() > 0) {
+ lastOutputFailed = true;
+ s.setStackSize(rest.getStackSize());
+ break;
+ }
+ s.setStackSize(0);
+ }
+ } catch (final GridAccessException ignored) {
+ lastOutputFailed = true;
+ }
+ lastOutputTick = tickCounter;
+ }
+
+ @Override
+ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ if (GT_Values.GT.isServerSide()) {
+ tickCounter = aTick;
+ if (tickCounter > (lastOutputTick + 40)) flushCachedStack();
+ }
+ super.onPostTick(aBaseMetaTileEntity, aTick);
+ }
+
+ @Override
+ public void saveNBTData(NBTTagCompound aNBT) {
+ super.saveNBTData(aNBT);
+ if (GregTech_API.mAE2) {
+ NBTTagList fluids = new NBTTagList();
+ for (IAEFluidStack s : fluidCache) {
+ if (s.getStackSize() == 0) continue;
+ NBTTagCompound tag = new NBTTagCompound();
+ NBTTagCompound tagFluidStack = new NBTTagCompound();
+ s.getFluidStack().writeToNBT(tagFluidStack);
+ tag.setTag("fluidStack", tagFluidStack);
+ tag.setLong("size", s.getStackSize());
+ fluids.appendTag(tag);
+ }
+ aNBT.setTag("cachedFluids", fluids);
+ gridProxy.writeToNBT(aNBT);
+ }
+ }
+
+ @Override
+ public void loadNBTData(NBTTagCompound aNBT) {
+ super.loadNBTData(aNBT);
+ if (GregTech_API.mAE2) {
+ NBTBase t = aNBT.getTag("cachedFluids");
+ if (t instanceof NBTTagList) {
+ NBTTagList l = (NBTTagList) t;
+ for (int i = 0; i < l.tagCount(); ++i) {
+ NBTTagCompound tag = l.getCompoundTagAt(i);
+ NBTTagCompound tagFluidStack = tag.getCompoundTag("fluidStack");
+ final IAEFluidStack s =
+ AEApi.instance().storage().createFluidStack(GT_Utility.loadFluid(tagFluidStack));
+ if (s != null) {
+ s.setStackSize(tag.getLong("size"));
+ fluidCache.add(s);
+ } else {
+ GT_Mod.GT_FML_LOGGER.warn(
+ "An error occurred while loading contents of ME Output Hatch, some fluids have been voided");
+ }
+ }
+ }
+ getProxy().readFromNBT(aNBT);
+ }
+ }
+
+ public boolean isLastOutputFailed() {
+ return lastOutputFailed;
+ }
+
+ @Override
+ public boolean isGivingInformation() {
+ return true;
+ }
+
+ @Override
+ public String[] getInfoData() {
+ if (!GregTech_API.mAE2) return new String[] {};
+ List<String> ss = new ArrayList<>();
+ ss.add("The hatch is "
+ + ((getProxy() != null && getProxy().isActive())
+ ? EnumChatFormatting.GREEN + "online"
+ : EnumChatFormatting.RED + "offline" + getAEDiagnostics())
+ + EnumChatFormatting.RESET);
+ if (fluidCache.isEmpty()) {
+ ss.add("The bus has no cached fluids");
+ } else {
+ IWideReadableNumberConverter nc = ReadableNumberConverter.INSTANCE;
+ ss.add(String.format("The hatch contains %d cached fluids: ", fluidCache.size()));
+ int counter = 0;
+ for (IAEFluidStack s : fluidCache) {
+ ss.add(s.getFluidStack().getLocalizedName() + ": " + EnumChatFormatting.GOLD
+ + nc.toWideReadableForm(s.getStackSize()) + " mB" + EnumChatFormatting.RESET);
+ if (++counter > 100) break;
+ }
+ }
+ return ss.toArray(new String[fluidCache.size() + 2]);
+ }
+}
diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java b/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java
index 8b36d2a132..3ae4e51cd6 100644
--- a/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java
+++ b/src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java
@@ -1467,6 +1467,9 @@ public class GT_Loader_MetaTileEntities implements Runnable { // TODO CHECK CIRC
.getStackForm(1L));
// ItemList.Hatch_CraftingInput_Bus_ME.set(new GT_MetaTileEntity_Hatch_CraftingInputBus_ME(2712,
// "hatch.crafting_input_bus.me", "Crafting Input Bus (ME)").getStackForm(1L));
+ ItemList.Hatch_Output_ME.set(
+ new GT_MetaTileEntity_Hatch_Output_ME(2713, "hatch.output.me", "Output Hatch (ME)")
+ .getStackForm(1L));
}
ItemList.Hatch_Input_Bus_ULV.set(
diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang
index 0931e767e8..5a09d4968e 100644
--- a/src/main/resources/assets/gregtech/lang/en_US.lang
+++ b/src/main/resources/assets/gregtech/lang/en_US.lang
@@ -227,6 +227,8 @@ GT5U.hatch.disableLimited.true=Limiting mode §cOff§r
GT5U.hatch.disableLimited.false=Limiting mode §aOn§r
GT5U.hatch.infiniteCache.true=ME Output bus will infinitely cache item, until you connect it to ME
GT5U.hatch.infiniteCache.false=ME Output bus will stop accepting items when offline for more than 2 seconds
+GT5U.hatch.infiniteCacheFluid.true=ME Output hatch will infinitely cache fluid, until you connect it to ME
+GT5U.hatch.infiniteCacheFluid.false=ME Output hatch will stop accepting fluid when offline for more than 2 seconds
GT5U.multiblock.pollution=Pollution reduced to
GT5U.multiblock.energy=Stored Energy
diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH.png b/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH.png
new file mode 100644
index 0000000000..4e1c1963e2
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH.png
Binary files differ
diff --git a/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH_ACTIVE.png b/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH_ACTIVE.png
new file mode 100644
index 0000000000..4e1c1963e2
--- /dev/null
+++ b/src/main/resources/assets/gregtech/textures/blocks/iconsets/OVERLAY_ME_FLUID_HATCH_ACTIVE.png
Binary files differ