Skip to content

Commit

Permalink
Added uplink stocking hatch support (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple authored Jan 20, 2025
1 parent c54a1a4 commit d122c09
Showing 1 changed file with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -47,13 +48,19 @@
import gregtech.api.util.IGTHatchAdder;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.shutdown.ShutDownReason;
import gregtech.common.tileentities.machines.MTEHatchInputME;

import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.me.GridAccessException;
import appeng.util.item.AEFluidStack;

import com.google.common.collect.ImmutableList;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
Expand Down Expand Up @@ -258,7 +265,7 @@ protected MultiblockTooltipBuilder createTooltip() {
)
);

tt.toolTipFinisher(AuthorPineapple);
tt.toolTipFinisher(EnumChatFormatting.WHITE, 0, AuthorPineapple);

return tt;
}
Expand Down Expand Up @@ -640,35 +647,79 @@ private boolean consumePlasmaEU(long euToConsume) {
}
}

private static final Function<MTEHatchInputME, FluidStack[]> ME_HATCH_STORED_FLUIDS = MMUtils
.exposeFieldGetterLambda(MTEHatchInputME.class, "storedFluids");

/**
* Converts plasma in hatches to EU.
*/
private void generatePlasmaEU(long euToGenerate) {
FuelBackend fuels = RecipeMaps.plasmaFuels.getBackend();

for (MTEHatchInput input : mInputHatches) {
for (FluidTankInfo tank : input.getTankInfo(ForgeDirection.UNKNOWN)) {
if (tank.fluid == null) continue;
if (input instanceof MTEHatchInputME me) {
try {
var inv = me.getProxy().getStorage().getFluidInventory();
var energy = me.getProxy().getEnergy();

FluidStack[] fluids = ME_HATCH_STORED_FLUIDS.apply(me);

for (FluidStack fluid : fluids) {
if (fluid == null) continue;

GTRecipe fuel = fuels.findFuel(fluid);

GTRecipe fuel = fuels.findFuel(tank.fluid);
if (fuel != null) {
long euPerLitre = fuel.mSpecialValue;

if (fuel != null) {
long euPerLitre = fuel.mSpecialValue;
int litresToConsume = (int) Math.min(Integer.MAX_VALUE, MMUtils.ceilDiv(euToGenerate, euPerLitre));

int litresToConsume = (int) Math
.min(Integer.MAX_VALUE, MMUtils.ceilDiv(euToGenerate, euPerLitre));
FluidStack toConsume = fluid.copy();
toConsume.amount = litresToConsume;

FluidStack toConsume = tank.fluid.copy();
toConsume.amount = litresToConsume;
IAEFluidStack drained = inv.extractItems(
AEFluidStack.create(toConsume),
Actionable.MODULATE,
new MachineSource((IActionHost) me.getBaseMetaTileEntity())
);

FluidStack drained = input.drain(ForgeDirection.UNKNOWN, toConsume, true);
if (drained == null) continue;

long generated = drained.amount * euPerLitre;
euToGenerate -= generated;
pendingPlasmaEU += generated;
energy.extractAEPower(drained.getStackSize(), Actionable.MODULATE, PowerMultiplier.CONFIG);

long generated = drained.getStackSize() * euPerLitre;
euToGenerate -= generated;
pendingPlasmaEU += generated;
}

if (euToGenerate <= 0) { return; }
}
} catch (GridAccessException e) {
// :P
}
} else {
for (FluidTankInfo tank : input.getTankInfo(ForgeDirection.UNKNOWN)) {
if (tank.fluid == null) continue;

if (euToGenerate <= 0) { return; }
GTRecipe fuel = fuels.findFuel(tank.fluid);

if (fuel != null) {
long euPerLitre = fuel.mSpecialValue;

int litresToConsume = (int) Math.min(Integer.MAX_VALUE, MMUtils.ceilDiv(euToGenerate, euPerLitre));

FluidStack toConsume = tank.fluid.copy();
toConsume.amount = litresToConsume;

FluidStack drained = input.drain(ForgeDirection.UNKNOWN, toConsume, true);

long generated = drained.amount * euPerLitre;
euToGenerate -= generated;
pendingPlasmaEU += generated;
}

if (euToGenerate <= 0) { return; }
}
}
}
}
Expand Down

0 comments on commit d122c09

Please sign in to comment.