|
1 | 1 | package com.gregtechceu.gtceu.common.machine.multiblock.steam; |
2 | 2 |
|
3 | 3 | import com.gregtechceu.gtceu.api.GTValues; |
4 | | -import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability; |
5 | | -import com.gregtechceu.gtceu.api.capability.recipe.IO; |
6 | | -import com.gregtechceu.gtceu.api.capability.recipe.IRecipeHandler; |
| 4 | +import com.gregtechceu.gtceu.api.capability.recipe.*; |
7 | 5 | import com.gregtechceu.gtceu.api.gui.GuiTextures; |
8 | 6 | import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; |
9 | 7 | import com.gregtechceu.gtceu.api.machine.MetaMachine; |
10 | 8 | import com.gregtechceu.gtceu.api.machine.TickableSubscription; |
11 | 9 | import com.gregtechceu.gtceu.api.machine.feature.IExplosionMachine; |
| 10 | +import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine; |
12 | 11 | import com.gregtechceu.gtceu.api.machine.feature.multiblock.IDisplayUIMachine; |
13 | 12 | import com.gregtechceu.gtceu.api.machine.multiblock.WorkableMultiblockMachine; |
| 13 | +import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; |
14 | 14 | import com.gregtechceu.gtceu.api.recipe.GTRecipe; |
15 | 15 | import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient; |
16 | 16 | import com.gregtechceu.gtceu.api.recipe.modifier.ModifierFunction; |
|
21 | 21 | import com.lowdragmc.lowdraglib.gui.texture.IGuiTexture; |
22 | 22 | import com.lowdragmc.lowdraglib.gui.util.ClickData; |
23 | 23 | import com.lowdragmc.lowdraglib.gui.widget.ComponentPanelWidget; |
| 24 | +import com.lowdragmc.lowdraglib.syncdata.annotation.DescSynced; |
24 | 25 | import com.lowdragmc.lowdraglib.syncdata.annotation.Persisted; |
25 | 26 | import com.lowdragmc.lowdraglib.syncdata.field.ManagedFieldHolder; |
26 | 27 |
|
|
39 | 40 | import org.jetbrains.annotations.NotNull; |
40 | 41 | import org.jetbrains.annotations.Nullable; |
41 | 42 |
|
42 | | -import java.util.ArrayList; |
43 | | -import java.util.List; |
| 43 | +import java.util.*; |
44 | 44 |
|
45 | 45 | import javax.annotation.ParametersAreNonnullByDefault; |
46 | 46 |
|
@@ -73,9 +73,15 @@ public ManagedFieldHolder getFieldHolder() { |
73 | 73 | return MANAGED_FIELD_HOLDER; |
74 | 74 | } |
75 | 75 |
|
76 | | - ////////////////////////////////////// |
77 | | - // ****** Recipe Logic ******// |
78 | | - ////////////////////////////////////// |
| 76 | + @Override |
| 77 | + protected RecipeLogic createRecipeLogic(Object... args) { |
| 78 | + return new LargeBoilerMachine.LargeBoilerRecipeLogic(this); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public LargeBoilerMachine.LargeBoilerRecipeLogic getRecipeLogic() { |
| 83 | + return (LargeBoilerMachine.LargeBoilerRecipeLogic) super.getRecipeLogic(); |
| 84 | + } |
79 | 85 |
|
80 | 86 | @Override |
81 | 87 | public void onStructureFormed() { |
@@ -193,21 +199,16 @@ public boolean onWorking() { |
193 | 199 | /** |
194 | 200 | * Recipe Modifier for <b>Large Boiler Machines</b> - can be used as a valid {@link RecipeModifier} |
195 | 201 | * <p> |
196 | | - * Duration is multiplied by {@code 100 / throttle} if throttle is less than 100 |
| 202 | + * Does not modify recipe. Real recipe duration is determined by |
| 203 | + * {@link LargeBoilerRecipeLogic#modifyFuelBurnTime(int)} |
197 | 204 | * </p> |
198 | 205 | * |
199 | 206 | * @param machine a {@link LargeBoilerMachine} |
200 | 207 | * @param recipe recipe |
201 | 208 | * @return A {@link ModifierFunction} for the given Large Boiler and recipe |
202 | 209 | */ |
203 | 210 | public static ModifierFunction recipeModifier(@NotNull MetaMachine machine, @NotNull GTRecipe recipe) { |
204 | | - if (!(machine instanceof LargeBoilerMachine largeBoilerMachine)) { |
205 | | - return RecipeModifier.nullWrongType(LargeBoilerMachine.class, machine); |
206 | | - } |
207 | | - if (largeBoilerMachine.throttle == 100) return ModifierFunction.IDENTITY; |
208 | | - return ModifierFunction.builder() |
209 | | - .durationMultiplier(100.0 / largeBoilerMachine.throttle) |
210 | | - .build(); |
| 211 | + return ModifierFunction.IDENTITY; |
211 | 212 | } |
212 | 213 |
|
213 | 214 | public void addDisplayText(List<Component> textList) { |
@@ -237,11 +238,43 @@ public void handleDisplayClick(String componentData, ClickData clickData) { |
237 | 238 | if (!clickData.isRemote) { |
238 | 239 | int result = componentData.equals("add") ? 5 : -5; |
239 | 240 | this.throttle = Mth.clamp(throttle + result, 25, 100); |
| 241 | + this.getRecipeLogic().modifyFuelBurnTime(this.throttle); |
240 | 242 | } |
241 | 243 | } |
242 | 244 |
|
243 | 245 | @Override |
244 | 246 | public IGuiTexture getScreenTexture() { |
245 | 247 | return GuiTextures.DISPLAY_STEAM.get(maxTemperature > 800); |
246 | 248 | } |
| 249 | + |
| 250 | + public static class LargeBoilerRecipeLogic extends RecipeLogic { |
| 251 | + |
| 252 | + @Persisted |
| 253 | + @DescSynced |
| 254 | + @Getter |
| 255 | + int currentThrottle; |
| 256 | + |
| 257 | + public LargeBoilerRecipeLogic(IRecipeLogicMachine machine) { |
| 258 | + super(machine); |
| 259 | + currentThrottle = 100; |
| 260 | + } |
| 261 | + |
| 262 | + @Override |
| 263 | + public void setupRecipe(GTRecipe recipe) { |
| 264 | + super.setupRecipe(recipe); |
| 265 | + if (lastRecipe != null) { |
| 266 | + currentThrottle = ((LargeBoilerMachine) machine).getThrottle(); |
| 267 | + duration = (int) Math.round(lastRecipe.duration / (currentThrottle / 100.0)); |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + public void modifyFuelBurnTime(int newThrottle) { |
| 272 | + if (lastRecipe != null) { |
| 273 | + double newThrottleMultiplier = (double) currentThrottle / newThrottle; |
| 274 | + duration = (int) Math.round(lastRecipe.duration / (newThrottle / 100.0)); |
| 275 | + progress = (int) Math.round(newThrottleMultiplier * progress); |
| 276 | + } |
| 277 | + currentThrottle = newThrottle; |
| 278 | + } |
| 279 | + } |
247 | 280 | } |
0 commit comments