Fixed Thermal boiler and few bugs

Closes #86
This commit is contained in:
TheDarkDnKTv 2021-03-25 09:48:09 +02:00
parent 36ef74f9dd
commit d73bde2694
8 changed files with 163 additions and 68 deletions

View file

@ -326,7 +326,7 @@ public abstract class MetaTileEntityMultiblock extends MetaTileEntity {
List<FluidStack> input = this.getFluidInputs(); List<FluidStack> input = this.getFluidInputs();
int[] itemAmountInSlots = new int[input.size()]; int[] itemAmountInSlots = new int[input.size()];
int amount = fluid.amount; int amount = fluid.amount;
for (int i = 0; i < input.size() && amount > 0; i++) { for (int i = 0; i < input.size(); i++) {
FluidStack fluidInSlot = input.get(i); FluidStack fluidInSlot = input.get(i);
if (fluidInSlot == null) { if (fluidInSlot == null) {

View file

@ -13,6 +13,7 @@ import gregtechmod.api.util.GT_Utility;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
/** /**
@ -211,8 +212,10 @@ public class RecipeLogic {
} }
} }
if (amount > 0) if (amount > 0) {
GT_Log.log.error(String.format("Output overflow detected for machine (%s) left amount: %s, stack: %s", getMachine().getClass(), amount, recipeOut)); GT_Log.log.error(String.format("Output overflow detected for machine (%s) left amount: %s, stack: %s", getMachine().getClass().getName(), amount, recipeOut));
getMachine().getBaseMetaTileEntity().disableWorking();
}
} }
List<FluidStack> fluidOutputs = getMachine().getFluidOutputs(); List<FluidStack> fluidOutputs = getMachine().getFluidOutputs();
@ -229,6 +232,11 @@ public class RecipeLogic {
amount = 0; amount = 0;
} }
} }
if (amount > 0) {
GT_Log.log.error(String.format("Output overflow detected for machine (%s) left amount: %s, fluid: %s", getMachine().getClass().getName(), amount, FluidRegistry.getFluidName(fluid)));
getMachine().getBaseMetaTileEntity().disableWorking();
}
} }
stuttering = false; stuttering = false;

View file

@ -24,10 +24,10 @@ import net.minecraftforge.fluids.FluidStack;
*/ */
public class RecipeMap<F extends RecipeFactory<F>> { public class RecipeMap<F extends RecipeFactory<F>> {
private final transient Map<Integer, List<Recipe>> MAPPINGS = new HashMap<>(); protected final transient Map<Integer, List<Recipe>> MAPPINGS = new HashMap<>();
private final F factory; protected final F factory;
private final List<Recipe> recipeList; protected final List<Recipe> recipeList;
public final int minInputs; public final int minInputs;
public final int maxInputs; public final int maxInputs;
@ -72,27 +72,7 @@ public class RecipeMap<F extends RecipeFactory<F>> {
return result != null && result.enabled ? result : null; return result != null && result.enabled ? result : null;
} }
public Recipe findRecipe(List<ItemStack> input, List<FluidStack> fluidInputs) { protected Recipe findRecipe(Collection<Recipe> recipes, List<ItemStack> input, List<FluidStack> fluidInputs, Predicate<Recipe> metaChecker) {
Set<Recipe> recipesTotal = this.getMappedRecipes(input, fluidInputs);
Recipe result = null;
if (!recipesTotal.isEmpty())
result = findRecipe(recipesTotal, input, fluidInputs);
return result != null && result.enabled ? result : null;
}
private Recipe findRecipe(Collection<Recipe> recipes, List<ItemStack> input, List<FluidStack> fluidInputs) {
if (recipes != null) {
for (Recipe recipe : recipes) {
if (recipe.matches(false, input, fluidInputs)) {
return recipe;
}
}
}
return null;
}
private Recipe findRecipe(Collection<Recipe> recipes, List<ItemStack> input, List<FluidStack> fluidInputs, Predicate<Recipe> metaChecker) {
if (recipes != null) { if (recipes != null) {
for (Recipe recipe : recipes) { for (Recipe recipe : recipes) {
if (metaChecker.test(recipe) && recipe.matches(false, input, fluidInputs)) { if (metaChecker.test(recipe) && recipe.matches(false, input, fluidInputs)) {
@ -104,7 +84,7 @@ public class RecipeMap<F extends RecipeFactory<F>> {
return null; return null;
} }
private Set<Recipe> getMappedRecipes(List<ItemStack> input, List<FluidStack> fluidInputs) { public Set<Recipe> getMappedRecipes(List<ItemStack> input, List<FluidStack> fluidInputs) {
Set<Recipe> recipesTotal = new HashSet<>(); Set<Recipe> recipesTotal = new HashSet<>();
for (FluidStack fluid : fluidInputs) { for (FluidStack fluid : fluidInputs) {
if (GT_Utility.isFluidStackValid(fluid)) { if (GT_Utility.isFluidStackValid(fluid)) {
@ -133,7 +113,7 @@ public class RecipeMap<F extends RecipeFactory<F>> {
* @param recipe * @param recipe
* @throws GT_RecipeException * @throws GT_RecipeException
*/ */
private void assertValidRecipe(Recipe recipe) { protected void assertValidRecipe(Recipe recipe) {
String error = ""; String error = "";
if (recipe.getInputs().size() < minInputs) error += " - Inputs size less than minimum required(" + minInputs + "), current: " + recipe.getInputs().size(); if (recipe.getInputs().size() < minInputs) error += " - Inputs size less than minimum required(" + minInputs + "), current: " + recipe.getInputs().size();
@ -150,7 +130,7 @@ public class RecipeMap<F extends RecipeFactory<F>> {
if (!error.isEmpty()) throw new GT_RecipeException(recipe.toString() + " thrown exception on registeration for RecipeMap:\n" + error); if (!error.isEmpty()) throw new GT_RecipeException(recipe.toString() + " thrown exception on registeration for RecipeMap:\n" + error);
} }
private void createMappings(Recipe toMap) { protected void createMappings(Recipe toMap) {
IntConsumer addToMap = value -> { IntConsumer addToMap = value -> {
List<Recipe> recipes = MAPPINGS.get(value); List<Recipe> recipes = MAPPINGS.get(value);
recipes = recipes == null ? new ArrayList<>() : recipes; recipes = recipes == null ? new ArrayList<>() : recipes;

View file

@ -5,6 +5,7 @@ import gregtechmod.api.util.GT_ModHandler;
import gregtechmod.common.recipe.factory.BlastFurnanceRecipeFactory; import gregtechmod.common.recipe.factory.BlastFurnanceRecipeFactory;
import gregtechmod.common.recipe.factory.GeneratorRecipeFactory; import gregtechmod.common.recipe.factory.GeneratorRecipeFactory;
import gregtechmod.common.recipe.factory.SimpleRecipeFactory; import gregtechmod.common.recipe.factory.SimpleRecipeFactory;
import gregtechmod.common.recipe.factory.ThermalBoilerRecipeMap;
import gregtechmod.common.recipe.maps.FurnanceRecipeMap; import gregtechmod.common.recipe.maps.FurnanceRecipeMap;
import gregtechmod.common.recipe.maps.IC2RecipeMap; import gregtechmod.common.recipe.maps.IC2RecipeMap;
import gregtechmod.common.recipe.maps.PulverizerRecipeMap; import gregtechmod.common.recipe.maps.PulverizerRecipeMap;
@ -55,4 +56,5 @@ public class RecipeMaps {
public static final RecyclerRecipeMap RECYCLING = new RecyclerRecipeMap(1, 2, 1, 2); public static final RecyclerRecipeMap RECYCLING = new RecyclerRecipeMap(1, 2, 1, 2);
public static final ScannerRecipeMap SCANNING = new ScannerRecipeMap(1, 2, 1, 2); public static final ScannerRecipeMap SCANNING = new ScannerRecipeMap(1, 2, 1, 2);
public static final FurnanceRecipeMap MELTING = new FurnanceRecipeMap(1, 2, 1, 2); public static final FurnanceRecipeMap MELTING = new FurnanceRecipeMap(1, 2, 1, 2);
public static final ThermalBoilerRecipeMap THERMAL_BOILER = new ThermalBoilerRecipeMap();
} }

View file

@ -0,0 +1,82 @@
package gregtechmod.common.recipe.factory;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import gregtechmod.api.enums.GT_Items;
import gregtechmod.api.recipe.Recipe;
import gregtechmod.api.util.GT_Utility;
import gregtechmod.common.recipe.RecipeMaps;
import gregtechmod.common.recipe.maps.DummyRecipeMap;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
/** Fake RecipeMap which generates recipes for Thermal boiler from hot fuels map
* Will allow only fluid-fluid recipe, replacing cells to fluids (TODO add fluid out to thermal generator)
* @author TheDarkDnKTv
*
*/
public class ThermalBoilerRecipeMap extends DummyRecipeMap {
public ThermalBoilerRecipeMap() {
super(0, 0, 0, 1, 0, 1, 0, 1);
}
@Override
public Recipe findRecipe(List<ItemStack> input, List<FluidStack> fluidInputs, Predicate<Recipe> metaChecker) {
return super.findRecipe(input, fluidInputs, metaChecker);
}
@Override
public Set<Recipe> getMappedRecipes(List<ItemStack> input, List<FluidStack> fluidInputs) {
Set<Recipe> recipesTotal = new HashSet<>();
for (FluidStack fluid : fluidInputs) {
if (GT_Utility.isFluidStackValid(fluid) && fluid.getFluid() != FluidRegistry.WATER) {
int fluidInt = GT_Utility.fluidStackToInt(fluid);
List<Recipe> recipesFluid = MAPPINGS.get(fluidInt);
if (recipesFluid != null) {
recipesTotal.addAll(recipesFluid);
} else {
Set<Recipe> recipes1 = RecipeMaps.HOT_FUELS.getMappedRecipes(input, fluidInputs);
Recipe recipe = this.findRecipe(recipes1, input, fluidInputs, r -> true);
if (recipe != null) {
this.createMappings(recipe);
recipesTotal.add(recipe);
} else {
for (Recipe rec : recipes1) {
if (rec.getInputs().isEmpty()) {
this.createMappings(rec);
recipesTotal.add(rec);
} else if (rec.getInputs().size() == 1 && rec.getInputs().get(0).match(GT_Items.Cell_Empty.get(1))) {
FluidStack fluidOut = GT_Utility.getFluidForFilledItem(rec.getOutputs().get(0));
if (fluidOut != null) {
rec = new Recipe(rec.getEUtoStart(),
rec.getEUt(),
rec.getDuration(),
rec.isShaped(),
Collections.emptyList(),
Collections.emptyList(),
Collections.emptyList(),
rec.getFluidInputs(),
Collections.singletonList(fluidOut),
Collections.emptyMap());
this.createMappings(rec);
recipesTotal.add(rec);
}
}
}
}
}
}
}
return recipesTotal;
}
}

View file

@ -2,6 +2,7 @@ package gregtechmod.common.recipe.maps;
import gregtechmod.api.recipe.Recipe; import gregtechmod.api.recipe.Recipe;
import gregtechmod.api.recipe.RecipeMap; import gregtechmod.api.recipe.RecipeMap;
import gregtechmod.api.util.GT_ItsNotMyFaultException;
import gregtechmod.common.recipe.factory.SimpleRecipeFactory; import gregtechmod.common.recipe.factory.SimpleRecipeFactory;
/** /**
@ -15,18 +16,22 @@ public abstract class DummyRecipeMap extends RecipeMap<SimpleRecipeFactory> {
super(minInputs, maxInputs, minOutputs, maxOutputs, null); super(minInputs, maxInputs, minOutputs, maxOutputs, null);
} }
@Override protected DummyRecipeMap(int minInputs, int maxInputs, int minOutputs, int maxOutputs, int minFluidInput, int maxFluidInput, int minFluidOutput, int maxFluidOutput) {
public SimpleRecipeFactory factory() { super(minInputs, maxInputs, minOutputs, maxOutputs, minFluidInput, maxFluidInput, minFluidOutput, maxFluidOutput, null);
return null;
} }
@Override @Override
public boolean register(Recipe recipe) { public final SimpleRecipeFactory factory() {
throw new GT_ItsNotMyFaultException("It is not allowed to call factory() method for Dummy recipe maps!\n This maps type created to GENERATE recipes in runtime, not to store it.");
}
@Override
public final boolean register(Recipe recipe) {
return false; return false;
} }
@Override @Override
public boolean remove(Recipe recipe) { public final boolean remove(Recipe recipe) {
return false; return false;
} }
} }

View file

@ -105,7 +105,7 @@ public class GT_MetaTileEntity_ElectricTypeSorter extends GT_MetaTileEntity_Elec
OrePrefixes tPrefix = OrePrefixes.getPrefix(sTypeList[mMode]); OrePrefixes tPrefix = OrePrefixes.getPrefix(sTypeList[mMode]);
if (((mMode == 11 && mInventory[0].getItem() instanceof ItemFood) || (mMode == 12 && RecipeMaps.GRINDER.findRecipe(Arrays.asList(new ItemStack[] {mInventory[0], GT_ModHandler.getWaterCell(1)}), Collections.emptyList()) != null) || (tPrefix != null && tPrefix.contains(mInventory[0])) || GT_OreDictUnificator.isItemStackInstanceOf(mInventory[0], sTypeList[mMode]))) { if (((mMode == 11 && mInventory[0].getItem() instanceof ItemFood) || (mMode == 12 && RecipeMaps.GRINDER.findRecipe(Arrays.asList(new ItemStack[] {mInventory[0], GT_ModHandler.getWaterCell(1)}), Collections.emptyList(), rec -> true) != null) || (tPrefix != null && tPrefix.contains(mInventory[0])) || GT_OreDictUnificator.isItemStackInstanceOf(mInventory[0], sTypeList[mMode]))) {
getBaseMetaTileEntity().decreaseStoredEnergyUnits(tPrice = GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), getBaseMetaTileEntity().getIInventoryAtSide(mTargetDirection), getBaseMetaTileEntity().getBackFacing(), GT_Utility.getOppositeSide(mTargetDirection), null, false, mTargetStackSize!=0?(byte)mTargetStackSize:64, mTargetStackSize!=0?(byte)mTargetStackSize:1, (byte)64, (byte)1)*3, true); getBaseMetaTileEntity().decreaseStoredEnergyUnits(tPrice = GT_Utility.moveOneItemStack(getBaseMetaTileEntity(), getBaseMetaTileEntity().getIInventoryAtSide(mTargetDirection), getBaseMetaTileEntity().getBackFacing(), GT_Utility.getOppositeSide(mTargetDirection), null, false, mTargetStackSize!=0?(byte)mTargetStackSize:64, mTargetStackSize!=0?(byte)mTargetStackSize:1, (byte)64, (byte)1)*3, true);
} }
if (tPrice <= 0) { if (tPrice <= 0) {

View file

@ -41,11 +41,11 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
@Override public int maxEUOutput() {return 400;} @Override public int maxEUOutput() {return 400;}
public GT_MetaTileEntity_Multi_ThermalBoiler(int aID, String mName) { public GT_MetaTileEntity_Multi_ThermalBoiler(int aID, String mName) {
super(aID, mName, RecipeMaps.HOT_FUELS); super(aID, mName, RecipeMaps.THERMAL_BOILER);
} }
public GT_MetaTileEntity_Multi_ThermalBoiler() { public GT_MetaTileEntity_Multi_ThermalBoiler() {
super(RecipeMaps.HOT_FUELS); super(RecipeMaps.THERMAL_BOILER);
} }
@Override @Override
@ -54,7 +54,7 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
} }
protected void initRecipeLogic(RecipeMap<?> map) { protected void initRecipeLogic(RecipeMap<?> map) {
recipeLogic = new MultiblockGenerator(() -> mEfficiency, map, this); recipeLogic = new ThermalBoilerLogic(() -> mEfficiency, map, this);
} }
@Override @Override
@ -158,7 +158,7 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
@Override @Override
public Map<String, List<Object>> getInfoData() { public Map<String, List<Object>> getInfoData() {
return InfoBuilder.create() return InfoBuilder.create()
.newKey("metatileentity.multiblock.thermalboiler.left_eu", ((MultiblockGenerator)recipeLogic).getLeftEU()) .newKey("metatileentity.multiblock.thermalboiler.left_eu", ((ThermalBoilerLogic)recipeLogic).getLeftEU())
.newKey("metatileentity.multiblock.malfunction_amount", getIdealStatus() - getRepairStatus()) .newKey("metatileentity.multiblock.malfunction_amount", getIdealStatus() - getRepairStatus())
.build(); .build();
} }
@ -189,9 +189,9 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
return "metatileentity.GT_Multi_ThermalBoiler.tooltip"; return "metatileentity.GT_Multi_ThermalBoiler.tooltip";
} }
private static class MultiblockGenerator extends GeneratorRecipeLogic { private static class ThermalBoilerLogic extends GeneratorRecipeLogic {
protected MultiblockGenerator(IntSupplier efficiency, RecipeMap<?> recipeMap, IRecipeWorkable machine) { protected ThermalBoilerLogic(IntSupplier efficiency, RecipeMap<?> recipeMap, IRecipeWorkable machine) {
super(efficiency, recipeMap, machine); super(efficiency, recipeMap, machine);
} }
@ -201,7 +201,6 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
MTEWorkableMultiblock machine = (MTEWorkableMultiblock) getMachine(); MTEWorkableMultiblock machine = (MTEWorkableMultiblock) getMachine();
IGregTechTileEntity base = machine.getBaseMetaTileEntity(); IGregTechTileEntity base = machine.getBaseMetaTileEntity();
if (base.isAllowedToWork()) {
if (leftEU > 0) { if (leftEU > 0) {
long tmp = leftEU; long tmp = leftEU;
success = updateRecipeProgress(); success = updateRecipeProgress();
@ -210,12 +209,14 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
} }
} }
if (base.isAllowedToWork()) {
if (leftEU == 0) { if (leftEU == 0) {
if (machine.hasInventoryBeenModified() || base.hasWorkJustBeenEnabled() || success || base.getTimer() % 600 == 0) { if (machine.hasInventoryBeenModified() || base.hasWorkJustBeenEnabled() || success || base.getTimer() % 600 == 0) {
trySerachRecipe(); trySerachRecipe();
} }
} }
} } else if (success)
triggerMachine(false);
return success; return success;
} }
@ -223,11 +224,10 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
@Override @Override
protected boolean updateRecipeProgress() { protected boolean updateRecipeProgress() {
MTEWorkableMultiblock machine = (MTEWorkableMultiblock) getMachine(); MTEWorkableMultiblock machine = (MTEWorkableMultiblock) getMachine();
if (leftEU > 0) {
int EU = (int) Math.min(((MetaTileEntity) getMachine()).maxEUOutput(), leftEU); int EU = (int) Math.min(((MetaTileEntity) getMachine()).maxEUOutput(), leftEU);
EU = progressTimeManipulator.applyAsInt(EU); EU = progressTimeManipulator.applyAsInt(EU);
if (machine.depleteInput(GT_ModHandler.getWater((EU + 160) / 160))) { if (machine.depleteInput(GT_ModHandler.getWater((EU + 160) / 160))) {
machine.addOutput(GT_ModHandler.getSteam(EU * 2)); this.addSteam(machine.getFluidOutputs(), EU * 2);
leftEU -= EU; leftEU -= EU;
if (leftEU <= 0) { if (leftEU <= 0) {
progressTime = 0; progressTime = 0;
@ -237,14 +237,32 @@ public class GT_MetaTileEntity_Multi_ThermalBoiler extends MTEWorkableMultiblock
if (previousRecipe != null) endRecipe(previousRecipe); if (previousRecipe != null) endRecipe(previousRecipe);
getMachine().endProcess(); getMachine().endProcess();
}
return true; return true;
} }
} else machine.stopMachine();
return false;
} }
machine.stopMachine(); @Override
return false; public void stop() {
leftEU = 0;
super.stop();
}
protected void addSteam(List<FluidStack> fluids, int amount) {
FluidStack steam = GT_ModHandler.getSteam(amount);
for (int i = 0; i < fluids.size(); i++) {
FluidStack slot = fluids.get(i);
if (slot == null) {
fluids.set(i, steam);
} else if (slot.isFluidEqual(steam)) {
int newSize = Math.min(MAX_FLUID_STACK, slot.amount + amount);
slot.amount = newSize;
} else continue;
break;
}
} }
} }
} }