Skip to content

Commit

Permalink
Large Combustion improvements (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syrcan authored Feb 26, 2022
1 parent ba534a3 commit 428f8f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gregtech.common.metatileentities.multi.electric.generator;

import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.capability.impl.MultiblockFuelRecipeLogic;
import gregtech.api.metatileentity.MetaTileEntity;
Expand All @@ -11,6 +13,7 @@
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.unification.material.Materials;
import gregtech.client.renderer.ICubeRenderer;
Expand All @@ -31,7 +34,6 @@
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -41,6 +43,7 @@ public class MetaTileEntityLargeCombustionEngine extends FuelMultiblockControlle

private final int tier;
private final boolean isExtreme;
private boolean boostAllowed;

public MetaTileEntityLargeCombustionEngine(ResourceLocation metaTileEntityId, int tier) {
super(metaTileEntityId, RecipeMaps.COMBUSTION_GENERATOR_FUELS, tier);
Expand All @@ -66,23 +69,28 @@ protected void addDisplayText(List<ITextComponent> textList) {
FluidStack liquidOxygenStack = getInputFluidInventory().drain(Materials.LiquidOxygen.getFluid(Integer.MAX_VALUE), false);
int lubricantAmount = lubricantStack == null ? 0 : lubricantStack.amount;
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.lubricant_amount", lubricantAmount));
if (!isExtreme) {
if (((LargeCombustionEngineWorkableHandler) recipeMapWorkable).isOxygenBoosted) {
int oxygenAmount = oxygenStack == null ? 0 : oxygenStack.amount;
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.oxygen_amount", oxygenAmount));
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.oxygen_boosted"));
} else {
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.supply_oxygen_to_boost"));
if (boostAllowed) {
if (!isExtreme) {
if (((LargeCombustionEngineWorkableHandler) recipeMapWorkable).isOxygenBoosted) {
int oxygenAmount = oxygenStack == null ? 0 : oxygenStack.amount;
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.oxygen_amount", oxygenAmount));
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.oxygen_boosted"));
} else {
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.supply_oxygen_to_boost"));
}
}
else {
if (((LargeCombustionEngineWorkableHandler) recipeMapWorkable).isOxygenBoosted) {
int liquidOxygenAmount = liquidOxygenStack == null ? 0 : liquidOxygenStack.amount;
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.liquid_oxygen_amount", liquidOxygenAmount));
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.liquid_oxygen_boosted"));
} else {
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.supply_liquid_oxygen_to_boost"));
}
}
}
else {
if (((LargeCombustionEngineWorkableHandler) recipeMapWorkable).isOxygenBoosted) {
int liquidOxygenAmount = liquidOxygenStack == null ? 0 : liquidOxygenStack.amount;
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.liquid_oxygen_amount", liquidOxygenAmount));
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.liquid_oxygen_boosted"));
} else {
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.supply_liquid_oxygen_to_boost"));
}
textList.add(new TextComponentTranslation("gregtech.multiblock.large_combustion_engine.boost_disallowed"));
}
}

Expand Down Expand Up @@ -113,7 +121,13 @@ protected BlockPattern createStructurePattern() {
.where('X', states(getCasingState()))
.where('G', states(getGearboxState()))
.where('C', states(getCasingState()).setMinGlobalLimited(3).or(autoAbilities(false, true, true, true, true, true, true)))
.where('D', abilities(MultiblockAbility.OUTPUT_ENERGY))
.where('D', metaTileEntities(MultiblockAbility.REGISTRY.get(MultiblockAbility.OUTPUT_ENERGY).stream()
.filter(mte -> {
IEnergyContainer container = mte.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, null);
return container != null && container.getOutputVoltage() * container.getOutputAmperage() >= GTValues.V[tier];
})
.toArray(MetaTileEntity[]::new))
.addTooltip("gregtech.multiblock.pattern.error.limited.1", GTValues.VN[tier]))
.where('A', states(getIntakeState()).addTooltips("gregtech.multiblock.pattern.clear_amount_1"))
.where('Y', selfPredicate())
.build();
Expand Down Expand Up @@ -155,6 +169,13 @@ public boolean isStructureObstructed() {
return checkIntakesObstructed();
}

@Override
protected void formStructure(PatternMatchContext context) {
super.formStructure(context);
IEnergyContainer energyContainer = getEnergyContainer();
this.boostAllowed = energyContainer != null && energyContainer.getOutputVoltage() >= GTValues.V[this.tier + 1];
}

private boolean checkIntakesObstructed() {
EnumFacing facing = this.getFrontFacing();
boolean permuteXZ = facing.getAxis() == EnumFacing.Axis.Z;
Expand All @@ -178,10 +199,15 @@ protected boolean shouldShowVoidingModeButton() {
return false;
}

public boolean isBoostAllowed() {
return boostAllowed;
}

private static class LargeCombustionEngineWorkableHandler extends MultiblockFuelRecipeLogic {

private boolean isOxygenBoosted = false;

private final MetaTileEntityLargeCombustionEngine combustionEngine;
private final boolean isExtreme;
private final int tier;

Expand All @@ -191,6 +217,7 @@ private static class LargeCombustionEngineWorkableHandler extends MultiblockFuel

public LargeCombustionEngineWorkableHandler(RecipeMapMultiblockController tileEntity, boolean isExtreme) {
super(tileEntity);
this.combustionEngine = (MetaTileEntityLargeCombustionEngine) tileEntity;
this.isExtreme = isExtreme;
this.tier = isExtreme ? GTValues.IV : GTValues.EV;
}
Expand All @@ -201,7 +228,7 @@ protected void updateRecipeProgress() {

//drain lubricant and invalidate if it fails
if (totalContinuousRunningTime == 1 || totalContinuousRunningTime % 72 == 0) {
IMultipleTankHandler inputTank = ((RecipeMapMultiblockController) metaTileEntity).getInputFluidInventory();
IMultipleTankHandler inputTank = combustionEngine.getInputFluidInventory();
if (LUBRICANT_STACK.isFluidStackIdentical(inputTank.drain(LUBRICANT_STACK, false))) {
inputTank.drain(LUBRICANT_STACK, true);
} else {
Expand All @@ -210,9 +237,9 @@ protected void updateRecipeProgress() {
}
}

//drain oxygen if present to boost production
if (totalContinuousRunningTime == 1 || totalContinuousRunningTime % 20 == 0) {
IMultipleTankHandler inputTank = ((RecipeMapMultiblockController) metaTileEntity).getInputFluidInventory();
//drain oxygen if present to boost production, and if the dynamo hatch supports it
if (combustionEngine.isBoostAllowed() && (totalContinuousRunningTime == 1 || totalContinuousRunningTime % 20 == 0)) {
IMultipleTankHandler inputTank = combustionEngine.getInputFluidInventory();
FluidStack boosterStack = isExtreme ? LIQUID_OXYGEN_STACK : OXYGEN_STACK;
if (boosterStack.isFluidStackIdentical(inputTank.drain(boosterStack, false))) {
isOxygenBoosted = true;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -4338,6 +4338,7 @@ gregtech.multiblock.large_combustion_engine.oxygen_amount=Oxygen Amount: %sL
gregtech.multiblock.large_combustion_engine.liquid_oxygen_amount=Liquid Oxygen Amount: %sL
gregtech.multiblock.large_combustion_engine.oxygen_boosted=§bOxygen boosted.
gregtech.multiblock.large_combustion_engine.liquid_oxygen_boosted=§bLiquid Oxygen boosted.
gregtech.multiblock.large_combustion_engine.boost_disallowed=§bUpgrade the Dynamo Hatch to enable Oxygen Boosting.
gregtech.multiblock.large_combustion_engine.supply_oxygen_to_boost=Supply Oxygen to boost.
gregtech.multiblock.large_combustion_engine.supply_liquid_oxygen_to_boost=Supply Liquid Oxygen to boost.
gregtech.multiblock.large_combustion_engine.obstructed=Engine Intakes Obstructed.
Expand Down

0 comments on commit 428f8f9

Please sign in to comment.