From 7969c3fe1cd1a37c445adba4ef314e6284097377 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:10:40 -0500 Subject: [PATCH] Tiered hatches --- .../ZBGTMetaTileEntities.java | 14 +++++++--- .../MetaTileEntityRFEnergyHatch.java | 27 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/ZBGTMetaTileEntities.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/ZBGTMetaTileEntities.java index ed4611b..996ae13 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/ZBGTMetaTileEntities.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/ZBGTMetaTileEntities.java @@ -13,6 +13,7 @@ import com.zorbatron.zbgt.common.metatileentities.storage.MetaTileEntityCreativeComputationProvider; import gregtech.api.GTValues; +import gregtech.api.GregTechAPI; public class ZBGTMetaTileEntities { @@ -102,10 +103,15 @@ public static void init() { STERILE_CLEANING_HATCH = registerMetaTileEntity(18018, new MetaTileEntitySterileCleaningHatch(zbgtId("sterile_cleaning_hatch"))); - RF_ENERGY_HATCH_INPUT = registerMetaTileEntity(18019, - new MetaTileEntityRFEnergyHatch(zbgtId("rf_input_hatch"), false)); - RF_ENERGY_HATCH_OUTPUT = registerMetaTileEntity(18020, - new MetaTileEntityRFEnergyHatch(zbgtId("rf_output_hatch"), true)); + for (int i = 0; i <= (GregTechAPI.isHighTier() ? GTValues.OpV : GTValues.UHV); i++) { + RF_ENERGY_HATCH_INPUT = registerMetaTileEntity(18019 + i, new MetaTileEntityRFEnergyHatch( + zbgtId(String.format("rf_input_hatch_%s", GTValues.VN[i].toLowerCase())), i, false)); + } + + for (int i = 0; i <= (GregTechAPI.isHighTier() ? GTValues.OpV : GTValues.UHV); i++) { + RF_ENERGY_HATCH_OUTPUT = registerMetaTileEntity(18033 + i, new MetaTileEntityRFEnergyHatch( + zbgtId(String.format("rf_output_hatch_%s", GTValues.VN[i].toLowerCase())), i, true)); + } // 18050-18099 (50) reserved for multiblocks MEGA_EBF = registerMetaTileEntity(18050, diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityRFEnergyHatch.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityRFEnergyHatch.java index 2e6502d..6951eb5 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityRFEnergyHatch.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityRFEnergyHatch.java @@ -39,7 +39,6 @@ import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.client.renderer.texture.Textures; -import gregtech.client.utils.PipelineUtil; import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart; public class MetaTileEntityRFEnergyHatch extends MetaTileEntityMultiblockPart @@ -52,12 +51,14 @@ public class MetaTileEntityRFEnergyHatch extends MetaTileEntityMultiblockPart private final FEContainer feContainer; private long storedEU = 0; - private final long maxStoredEU = 10_000_000; + private final long maxStoredEU; + + public MetaTileEntityRFEnergyHatch(ResourceLocation metaTileEntityId, int tier, boolean isExportHatch) { + super(metaTileEntityId, tier); - public MetaTileEntityRFEnergyHatch(ResourceLocation metaTileEntityId, boolean isExportHatch) { - super(metaTileEntityId, GTValues.LV); this.isExportHatch = isExportHatch; this.allSideAccess = true; + this.maxStoredEU = GTValues.V[tier]; euContainer = new EUContainer(); feContainer = new FEContainer(); @@ -65,7 +66,7 @@ public MetaTileEntityRFEnergyHatch(ResourceLocation metaTileEntityId, boolean is @Override public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { - return new MetaTileEntityRFEnergyHatch(metaTileEntityId, isExportHatch); + return new MetaTileEntityRFEnergyHatch(metaTileEntityId, getTier(), isExportHatch); } @Override @@ -88,7 +89,17 @@ private void pushEnergy(EnumFacing direction) { if (te == null) return; IEnergyStorage energyStorage = te.getCapability(CapabilityEnergy.ENERGY, direction.getOpposite()); if (energyStorage == null) return; - euContainer.removeEnergy(FeCompat.insertEu(energyStorage, storedEU)); + euContainer.removeEnergy(insertEuBounded(energyStorage, storedEU, Integer.MAX_VALUE)); + } + + /** + * Copied from {@link FeCompat#insertEu(IEnergyStorage, long)} but with {@link FeCompat#toFeBounded(long, int, int)} + * instead of {@link FeCompat#toFe(long, int)}. + */ + private long insertEuBounded(IEnergyStorage storage, long amountEU, int max) { + int euToFeRatio = ratio(false); + int feSent = storage.receiveEnergy(toFeBounded(amountEU, euToFeRatio, max), true); + return toEu(storage.receiveEnergy(feSent - (feSent % euToFeRatio), false), euToFeRatio); } @Override @@ -107,8 +118,8 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, if (shouldRenderOverlay()) { for (EnumFacing facing : EnumFacing.values()) { if (!allSideAccess && facing != getFrontFacing()) continue; - (isExportHatch ? Textures.CONVERTER_FE_OUT : Textures.CONVERTER_FE_IN).renderSided(facing, renderState, - translation, PipelineUtil.color(pipeline, GTValues.VC[getTier()])); + (isExportHatch ? Textures.CONVERTER_FE_OUT : Textures.CONVERTER_FE_IN) + .renderSided(facing, renderState, translation, pipeline); } } }