Skip to content

Commit

Permalink
Tiered hatches
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron committed Nov 23, 2024
1 parent e942d14 commit 7969c3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.zorbatron.zbgt.common.metatileentities.storage.MetaTileEntityCreativeComputationProvider;

import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;

public class ZBGTMetaTileEntities {

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,20 +51,22 @@ 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();
}

@Override
public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {
return new MetaTileEntityRFEnergyHatch(metaTileEntityId, isExportHatch);
return new MetaTileEntityRFEnergyHatch(metaTileEntityId, getTier(), isExportHatch);
}

@Override
Expand All @@ -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
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 7969c3f

Please sign in to comment.