Skip to content

Commit

Permalink
Add Custom Tank Scaling for Machines (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Sep 29, 2021
1 parent afefbc9 commit 941077f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import gregtech.api.recipes.RecipeMap;
import gregtech.api.render.OrientedOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.common.ConfigHolder;
import gregtech.api.util.GTUtility;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand All @@ -39,6 +39,7 @@

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Function;

public class SimpleMachineMetaTileEntity extends WorkableTieredMetaTileEntity implements IActiveOutputSide {

Expand All @@ -56,24 +57,22 @@ public class SimpleMachineMetaTileEntity extends WorkableTieredMetaTileEntity im
protected IItemHandler outputItemInventory;
protected IFluidHandler outputFluidInventory;

private static final int inputTankCapacity = ConfigHolder.U.GT5u.customMachineTankSizes[0];
private static final int outputTankCapacity = ConfigHolder.U.GT5u.customMachineTankSizes[1];
private static final int FONT_HEIGHT = 9; // Minecraft's FontRenderer FONT_HEIGHT value

public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier) {
this(metaTileEntityId, recipeMap, renderer, tier, true);
public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier, boolean hasFrontFacing) {
this(metaTileEntityId, recipeMap, renderer, tier, hasFrontFacing, GTUtility.defaultTankSizeFunction);
}

public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier, boolean hasFrontFacing) {
super(metaTileEntityId, recipeMap, renderer, tier);
public SimpleMachineMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier, boolean hasFrontFacing,
Function<Integer, Integer> tankScalingFunction) {
super(metaTileEntityId, recipeMap, renderer, tier, tankScalingFunction);
this.hasFrontFacing = hasFrontFacing;
this.chargerInventory = new ItemStackHandler(1);

}

@Override
public MetaTileEntity createMetaTileEntity(MetaTileEntityHolder holder) {
return new SimpleMachineMetaTileEntity(metaTileEntityId, workable.recipeMap, renderer, getTier(), hasFrontFacing);
return new SimpleMachineMetaTileEntity(metaTileEntityId, workable.recipeMap, renderer, getTier(), hasFrontFacing, getTankScalingFunction());
}

@Override
Expand Down Expand Up @@ -443,14 +442,4 @@ public void addInformation(ItemStack stack, @Nullable World player, List<String>
String key = this.metaTileEntityId.getPath().split("\\.")[0];
tooltip.add(1, I18n.format(String.format("gregtech.machine.%s.tooltip", key)));
}

@Override
protected int getInputTankCapacity(int index) {
return inputTankCapacity;
}

@Override
protected int getOutputTankCapacity(int index) {
return outputTankCapacity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

public abstract class WorkableTieredMetaTileEntity extends TieredMetaTileEntity {

protected final RecipeLogicEnergy workable;
protected final OrientedOverlayRenderer renderer;

public WorkableTieredMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier) {
private final Function<Integer, Integer> tankScalingFunction;

public WorkableTieredMetaTileEntity(ResourceLocation metaTileEntityId, RecipeMap<?> recipeMap, OrientedOverlayRenderer renderer, int tier,
Function<Integer, Integer> tankScalingFunction) {
super(metaTileEntityId, tier);
this.renderer = renderer;
this.workable = createWorkable(recipeMap);
this.tankScalingFunction = tankScalingFunction;
initializeInventory();
reinitializeEnergyContainer();
}
Expand Down Expand Up @@ -85,7 +90,7 @@ protected FluidTankList createImportFluidHandler() {
if (workable == null) return new FluidTankList(false);
FilteredFluidHandler[] fluidImports = new FilteredFluidHandler[workable.recipeMap.getMaxFluidInputs()];
for (int i = 0; i < fluidImports.length; i++) {
NotifiableFilteredFluidHandler filteredFluidHandler = new NotifiableFilteredFluidHandler(getInputTankCapacity(i), this, false);
NotifiableFilteredFluidHandler filteredFluidHandler = new NotifiableFilteredFluidHandler(this.tankScalingFunction.apply(this.getTier()), this, false);
filteredFluidHandler.setFillPredicate(this::canInputFluid);
fluidImports[i] = filteredFluidHandler;
}
Expand All @@ -97,7 +102,7 @@ protected FluidTankList createExportFluidHandler() {
if (workable == null) return new FluidTankList(false);
FluidTank[] fluidExports = new FluidTank[workable.recipeMap.getMaxFluidOutputs()];
for (int i = 0; i < fluidExports.length; i++) {
fluidExports[i] = new NotifiableFluidTank(getOutputTankCapacity(i), this, true);
fluidExports[i] = new NotifiableFluidTank(this.tankScalingFunction.apply(this.getTier()), this, true);
}
return new FluidTankList(false, fluidExports);
}
Expand Down Expand Up @@ -128,18 +133,15 @@ protected boolean canInputFluid(FluidStack inputFluid) {
}
}

protected int getInputTankCapacity(int index) {
return 64000;
}

protected int getOutputTankCapacity(int index) {
return 64000;
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
tooltip.add(I18n.format("gregtech.universal.tooltip.voltage_in", energyContainer.getInputVoltage(), GTValues.VN[getTier()]));
tooltip.add(I18n.format("gregtech.universal.tooltip.energy_storage_capacity", energyContainer.getEnergyCapacity()));
tooltip.add(I18n.format("gregtech.universal.tooltip.fluid_storage_capacity", this.tankScalingFunction.apply(getTier())));
}

public Function<Integer, Integer> getTankScalingFunction() {
return tankScalingFunction;
}
}
30 changes: 30 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -911,4 +911,34 @@ public static AxisAlignedBB rotateAroundYAxis(AxisAlignedBB aabb, EnumFacing fro
}
return rotatedAABB;
}

/**
* Default function for tank sizes, takes a tier input and returns the corresponding size
*/
public static final Function<Integer, Integer> defaultTankSizeFunction = tier -> {
if (tier <= GTValues.LV)
return 8000;
if (tier == GTValues.MV)
return 12000;
if (tier == GTValues.HV)
return 16000;
if (tier == GTValues.EV)
return 32000;
// IV+
return 64000;
};

/**
* Alternative function for tank sizes, takes a tier input and returns the corresponding size
*
* This function scales the same as the default function except it stops scaling past HV
*/
public static final Function<Integer, Integer> hvCappedTankSizeFunction = tier -> {
if (tier <= GTValues.LV)
return 8000;
if (tier == GTValues.MV)
return 12000;
// HV+
return 16000;
};
}
5 changes: 0 additions & 5 deletions src/main/java/gregtech/common/ConfigHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ public static class UnofficialOptions {

public static class GT5U {

@Config.Comment("Changes the size of input and output tanks in nearly all single block machine. The first value will be used for the input tank size, the second for the output tank size. Units are millibuckets. Default: {64000, 64000}")
@Config.RangeInt(min = 1)
@Config.RequiresMcRestart
public int[] customMachineTankSizes = new int[]{64000, 64000};

@Config.Comment("Require Wrench to break machines? Default: false")
public boolean requireWrenchForMachines = false;

Expand Down
Loading

0 comments on commit 941077f

Please sign in to comment.