-
Notifications
You must be signed in to change notification settings - Fork 176
/
MultiblockFuelRecipeLogic.java
168 lines (139 loc) · 5.68 KB
/
MultiblockFuelRecipeLogic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package gregtech.api.capability.impl;
import gregtech.api.capability.IRotorHolder;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.MultiblockWithDisplayBase;
import gregtech.api.metatileentity.multiblock.ParallelLogicType;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.recipeproperties.IRecipePropertyStorage;
import gregtech.api.util.TextFormattingUtil;
import net.minecraft.util.Tuple;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.FluidStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class MultiblockFuelRecipeLogic extends MultiblockRecipeLogic {
protected long totalContinuousRunningTime;
public MultiblockFuelRecipeLogic(RecipeMapMultiblockController tileEntity) {
super(tileEntity);
}
@Override
protected void modifyOverclockPre(@NotNull int[] values, @NotNull IRecipePropertyStorage storage) {
// apply maintenance bonuses
Tuple<Integer, Double> maintenanceValues = getMaintenanceValues();
// duration bonus
if (maintenanceValues.getSecond() != 1.0) {
values[1] = (int) Math.round(values[1] / maintenanceValues.getSecond());
}
}
@Override
protected void modifyOverclockPost(int[] overclockResults, @NotNull IRecipePropertyStorage storage) {
// apply maintenance penalties
Tuple<Integer, Double> maintenanceValues = getMaintenanceValues();
// duration penalty
if (maintenanceValues.getFirst() > 0) {
overclockResults[1] = (int) (overclockResults[1] * (1 - 0.1 * maintenanceValues.getFirst()));
}
// make EUt negative so it is consumed
overclockResults[0] = -overclockResults[0];
}
@NotNull
@Override
public ParallelLogicType getParallelLogicType() {
return ParallelLogicType.MULTIPLY; // TODO APPEND_FLUIDS
}
@Override
protected boolean hasEnoughPower(@NotNull int[] resultOverclock) {
// generators always have enough power to run recipes
return true;
}
@Override
public void update() {
super.update();
if (workingEnabled && isActive && progressTime > 0) {
totalContinuousRunningTime++;
} else {
totalContinuousRunningTime = 0;
}
}
@Override
public int getParallelLimit() {
// parallel is limited by voltage
return Integer.MAX_VALUE;
}
@Override
protected long getMaxParallelVoltage() {
return getMaxVoltage();
}
/**
* Boost the energy production.
* Should not change the state of the workable logic. Only read current values.
*
* @param production the energy amount to boost
* @return the boosted energy amount
*/
protected long boostProduction(long production) {
return production;
}
@Override
protected boolean drawEnergy(int recipeEUt, boolean simulate) {
long euToDraw = boostProduction(recipeEUt);
long resultEnergy = getEnergyStored() - euToDraw;
if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity()) {
if (!simulate) getEnergyContainer().changeEnergy(-euToDraw);
return true;
} else return false;
}
@Override
public int getInfoProviderEUt() {
return (int) boostProduction(super.getInfoProviderEUt());
}
@Override
public boolean consumesEnergy() {
return false;
}
@Override
public void invalidate() {
super.invalidate();
totalContinuousRunningTime = 0;
}
public String getRecipeFluidInputInfo() {
IRotorHolder rotorHolder = null;
if (metaTileEntity instanceof MultiblockWithDisplayBase multiblockWithDisplayBase) {
List<IRotorHolder> abilities = multiblockWithDisplayBase.getAbilities(MultiblockAbility.ROTOR_HOLDER);
rotorHolder = abilities.size() > 0 ? abilities.get(0) : null;
}
// Previous Recipe is always null on first world load, so try to acquire a new recipe
Recipe recipe;
if (previousRecipe == null) {
recipe = findRecipe(Integer.MAX_VALUE, getInputInventory(), getInputTank());
if (recipe == null) return null;
} else {
recipe = previousRecipe;
}
FluidStack requiredFluidInput = recipe.getFluidInputs().get(0).getInputFluidStack();
int ocAmount = (int) (getMaxVoltage() / recipe.getEUt());
int neededAmount = ocAmount * requiredFluidInput.amount;
if (rotorHolder != null && rotorHolder.hasRotor()) {
neededAmount /= (rotorHolder.getTotalEfficiency() / 100f);
} else if (rotorHolder != null && !rotorHolder.hasRotor()) {
return null;
}
return TextFormatting.RED + TextFormattingUtil.formatNumbers(neededAmount) + "L";
}
public FluidStack getInputFluidStack() {
// Previous Recipe is always null on first world load, so try to acquire a new recipe
if (previousRecipe == null) {
Recipe recipe = findRecipe(Integer.MAX_VALUE, getInputInventory(), getInputTank());
return recipe == null ? null : getInputTank().drain(
new FluidStack(recipe.getFluidInputs().get(0).getInputFluidStack().getFluid(), Integer.MAX_VALUE),
false);
}
FluidStack fuelStack = previousRecipe.getFluidInputs().get(0).getInputFluidStack();
return getInputTank().drain(new FluidStack(fuelStack.getFluid(), Integer.MAX_VALUE), false);
}
@Override
public boolean isAllowOverclocking() {
return false;
}
}