diff --git a/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java b/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java index 29b8c52c72f..d03ad532ac3 100644 --- a/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java +++ b/src/main/java/goodgenerator/blocks/tileEntity/MTENeutronActivator.java @@ -129,7 +129,7 @@ public CheckRecipeResult process() { mFloor = (lastRecipe.mSpecialValue % 10000) * 1000000; mCeil = (lastRecipe.mSpecialValue / 10000) * 1000000; if (eV > mCeil || eV < mFloor) { - setOutputItems(ItemRefer.Radioactive_Waste.get(4)); + overwriteOutputItems(ItemRefer.Radioactive_Waste.get(4)); } // NA does not consume power, its hatches do. Set it to 0 to be sure calculatedEut = 0; diff --git a/src/main/java/gregtech/GTMod.java b/src/main/java/gregtech/GTMod.java index fe67bcb2a1f..c071cd291da 100644 --- a/src/main/java/gregtech/GTMod.java +++ b/src/main/java/gregtech/GTMod.java @@ -66,6 +66,7 @@ import gregtech.api.interfaces.internal.IGTMod; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.implementations.MTEHatchNonConsumableBase; +import gregtech.api.objects.GTItemStack; import gregtech.api.objects.ItemData; import gregtech.api.objects.XSTR; import gregtech.api.registries.LHECoolantRegistry; @@ -80,7 +81,6 @@ import gregtech.api.util.GTRecipeRegistrator; import gregtech.api.util.GTSpawnEventHandler; import gregtech.api.util.GTUtility; -import gregtech.api.util.item.ItemHolder; import gregtech.common.GTDummyWorld; import gregtech.common.GTNetwork; import gregtech.common.GTProxy; @@ -800,7 +800,7 @@ public void onIDChangingEvent(FMLModIdMappingEvent aEvent) { for (Map gt_itemStackMap : GregTechAPI.sItemStackMappings) { GTUtility.reMap(gt_itemStackMap); } - for (SetMultimap gt_itemStackMap : GregTechAPI.itemStackMultiMaps) { + for (SetMultimap gt_itemStackMap : GregTechAPI.itemStackMultiMaps) { GTUtility.reMap(gt_itemStackMap); } } catch (Throwable e) { diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index a888078cd02..c9f1d90a1ba 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -61,7 +61,6 @@ import gregtech.api.util.GTModHandler; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTUtility; -import gregtech.api.util.item.ItemHolder; import gregtech.api.world.GTWorldgen; import gregtech.common.GTDummyWorld; import gregtech.common.items.ItemIntegratedCircuit; @@ -93,7 +92,7 @@ public class GregTechAPI { * {@link GTItemStack} */ public static final Collection> sItemStackMappings = new ArrayList<>(); - public static final Collection> itemStackMultiMaps = new ArrayList<>(); + public static final Collection> itemStackMultiMaps = new ArrayList<>(); /** * The MetaTileEntity-ID-List-Length @@ -150,17 +149,16 @@ public class GregTechAPI { /** * The List of Tools, which can be used. Accepts regular damageable Items and Electric Items */ - public static final GTHashSet sToolList = new GTHashSet<>(), sCrowbarList = new GTHashSet<>(), - sScrewdriverList = new GTHashSet<>(), sWrenchList = new GTHashSet<>(), sSoftHammerList = new GTHashSet<>(), - sHardHammerList = new GTHashSet<>(), sWireCutterList = new GTHashSet<>(), - sSolderingToolList = new GTHashSet<>(), sSolderingMetalList = new GTHashSet<>(), - sJackhammerList = new GTHashSet<>(); + public static final GTHashSet sToolList = new GTHashSet(), sCrowbarList = new GTHashSet(), + sScrewdriverList = new GTHashSet(), sWrenchList = new GTHashSet(), sSoftHammerList = new GTHashSet(), + sHardHammerList = new GTHashSet(), sWireCutterList = new GTHashSet(), sSolderingToolList = new GTHashSet(), + sSolderingMetalList = new GTHashSet(), sJackhammerList = new GTHashSet(); /** * The List of Hazmat Armors */ - public static final GTHashSet sGasHazmatList = new GTHashSet<>(), sBioHazmatList = new GTHashSet<>(), - sFrostHazmatList = new GTHashSet<>(), sHeatHazmatList = new GTHashSet<>(), sRadioHazmatList = new GTHashSet<>(), - sElectroHazmatList = new GTHashSet<>(); + public static final GTHashSet sGasHazmatList = new GTHashSet(), sBioHazmatList = new GTHashSet(), + sFrostHazmatList = new GTHashSet(), sHeatHazmatList = new GTHashSet(), sRadioHazmatList = new GTHashSet(), + sElectroHazmatList = new GTHashSet(); private static final Multimap sRealConfigurationList = Multimaps .newListMultimap(new TreeMap<>(), ArrayList::new); diff --git a/src/main/java/gregtech/api/enums/GTValues.java b/src/main/java/gregtech/api/enums/GTValues.java index 4223a7ed3fe..1c5dedee8a7 100644 --- a/src/main/java/gregtech/api/enums/GTValues.java +++ b/src/main/java/gregtech/api/enums/GTValues.java @@ -230,79 +230,7 @@ public class GTValues { */ public static final class NBT { - public static final String COLOR = "gt.color", // Integer - COVERS = "gt.covers", // String - CUSTOM_NAME = "name", // String - DISPLAY = "gt.display", // String - TIER = "gt.tier", // Number - FACING = "gt.facing", // Byte - LOCK_UPGRADE = "gt.locked", // Boolean - MATERIAL = "gt.material", // String containing the Material Name. - MODE = "gt.mode", // Number - ALLOWED_MODES = "gt.amode", // Number - MTE_ID = "gt.mte.id", // Containing the MTE ID - MTE_REG = "gt.mte.reg", // Containing the MTE Registry ID - OWNER = "gt.owner", // String - OWNER_UUID = "gt.ownerUuid", // UUID (String) - - // Machines - ACTIVE = "gt.active", // Boolean - FLUID_OUT = "gt.fluidout", // Output Fluid - ITEM_OUT = "gt.itemout", // Output Item - PARALLEL = "gt.parallel", // Number - TANK_CAPACITY = "gt.tankcap", // Number - TANK_IN = "gt.tank.in.", // FluidStack - TANK_OUT = "gt.tank.out.", // FluidStack - TEXTURE_FOLDER = "gt.texture.folder", // String - INV_INPUT_SIZE = "gt.invsize.in", // Number - INV_OUTPUT_SIZE = "gt.invsize.out", // Number - INV_INPUT_LIST = "gt.invlist.in", // NBT List - INV_OUTPUT_LIST = "gt.invlist.out", // NBT List - VOLTAGE = "gt.voltage", // Number - AMPERAGE = "gt.amperage", // Number - STORED_ENERGY = "gt.stored.energy", // Number - MAXIMUM_ENERGY = "gt.maximum.energy", // Number - EUT_CONSUMPTION = "gt.eut.consumption", // Number - BURN_TIME_LEFT = "gt.burn.time.left", // Number - TOTAL_BURN_TIME = "gt.total.burn.time", // Number - ALLOWED_WORK = "gt.allowed.work", // Boolean - TASKS = "gt.tasks", // Compound - - // MultiBlock - STRUCTURE_OK = "gt.structure.ok", ROTATION = "gt.eRotation", FLIP = "gt.eFlip", TARGET = "gt.target", // Boolean - TARGET_X = "gt.target.x", // Number - TARGET_Y = "gt.target.y", // Number - TARGET_Z = "gt.target.z", // Number - LOCKED_FLUID = "gt.locked.fluid", // String - LOCKED_INVENTORY = "gt.locked.inv", // String - LOCKED_INVENTORY_INDEX = "gt.locked.inv.index", // Number - UPGRADE_INVENTORY_SIZE = "gt.invsize.upg", // String - UPGRADE_INVENTORY_UUID = "gt.invuuid.upg", // String - UPGRADE_INVENTORY_NAME = "gt.invname.upg", // String - UPGRADE_INVENTORIES_INPUT = "gt.invlist.upg.in", // NBT List - UPGRADE_INVENTORIES_OUTPUT = "gt.invlist.upg.out", // NBT List - UPGRADE_TANK_CAPACITY = "gt.tank.cap.upg", // Long - UPGRADE_TANK_COUNT = "gt.tank.ct.upg", // Int - UPGRADE_TANK_CAPACITY_MULTIPLIER = "gt.tank.cap.mult.upg", // Long - UPGRADE_TANK_UUID = "gt.tankuuid.upg", // String - UPGRADE_TANK_NAME = "gt.tankname.upg", // String - UPGRADE_TANKS_INPUT = "gt.tanklist.upg.in", // NBT List - UPGRADE_TANKS_OUTPUT = "gt.tanklist.upg.out", // NBT List - UPGRADE_TANKS_PREFIX = "gt.tank.upg", // NBT Tag - UPGRADE_AMPERAGE = "gt.amp.upg", // Long - SEPARATE_INPUTS = "gt.separate.inputs", // Boolean - VOIDING_MODE = "gt.voiding.mode", // String - BATCH_MODE = "gt.batch.mode", // Boolean - RECIPE_LOCK = "gt.recipe.lock", // Boolean - - // Logic - POWER_LOGIC = "gt.pow.logic", // NBT Tag - POWER_LOGIC_STORED_ENERGY = "gt.pow.energy", // Number - POWER_LOGIC_ENERGY_CAPACITY = "gt.pow.energy.cap", // Number - POWER_LOGIC_VOLTAGE = "gt.pow.volt", // Number - POWER_LOGIC_AMPERAGE = "gt.pow.amp", // Number - POWER_LOGIC_TYPE = "gt.pow.type", // Number - empty_ = ""; + public static final String COVERS = "gt.covers"; // String } /** The Color White as RGB Short Array. */ @@ -435,11 +363,6 @@ public static final class NBT { * Debug parameter for {@link GTChunkAssociatedData} */ public static boolean debugWorldData = false; - /** - * Parameter if multi tile entities (MuTEs) should be enabled in the pack. Turned off by default until - * implementation is done. - */ - public static boolean enableMultiTileEntities = false; /** * Number of ticks between sending sound packets to clients for electric machines. Default is 1.5 seconds. Trying to * mitigate lag and FPS drops. diff --git a/src/main/java/gregtech/api/enums/InventoryType.java b/src/main/java/gregtech/api/enums/InventoryType.java deleted file mode 100644 index 50927381748..00000000000 --- a/src/main/java/gregtech/api/enums/InventoryType.java +++ /dev/null @@ -1,7 +0,0 @@ -package gregtech.api.enums; - -public enum InventoryType { - Input, - Output, - Both -} diff --git a/src/main/java/gregtech/api/gui/GUIHost.java b/src/main/java/gregtech/api/gui/GUIHost.java deleted file mode 100644 index bbb94317c47..00000000000 --- a/src/main/java/gregtech/api/gui/GUIHost.java +++ /dev/null @@ -1,56 +0,0 @@ -package gregtech.api.gui; - -import java.util.Objects; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; - -import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; - -public interface GUIHost extends ITileWithModularUI { - - @Nonnull - @Override - default ModularWindow createWindow(UIBuildContext uiContext) { - Objects.requireNonNull(uiContext); - GUIProvider gui = getGUI(uiContext); - return gui.openGUI(uiContext); - } - - /** - * Width of the GUI when its being displayed - */ - default int getWidth() { - return 170; - } - - default int getHeight() { - return 192; - } - - @Nonnull - GUIProvider getGUI(@Nonnull UIBuildContext uiContext); - - ItemStack getAsItem(); - - String getMachineName(); - - default boolean hasItemInput() { - return true; - } - - default boolean hasItemOutput() { - return true; - } - - default boolean hasFluidInput() { - return true; - } - - default boolean hasFluidOutput() { - return true; - } -} diff --git a/src/main/java/gregtech/api/gui/GUIProvider.java b/src/main/java/gregtech/api/gui/GUIProvider.java deleted file mode 100644 index 6fec4aa52af..00000000000 --- a/src/main/java/gregtech/api/gui/GUIProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -package gregtech.api.gui; - -import java.util.Objects; - -import javax.annotation.Nonnull; - -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; - -public abstract class GUIProvider { - - @Nonnull - protected final T host; - - public GUIProvider(@Nonnull T host) { - this.host = host; - } - - @Nonnull - public ModularWindow openGUI(@Nonnull UIBuildContext uiContext) { - Builder builder = Objects.requireNonNull(ModularWindow.builder(host.getWidth(), host.getHeight())); - if (shouldBindPlayerInventory()) { - builder.bindPlayerInventory(uiContext.getPlayer()); - } - attachSynchHandlers(builder, uiContext); - addWidgets(builder, uiContext); - return Objects.requireNonNull(builder.build()); - } - - protected abstract void attachSynchHandlers(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext); - - protected abstract void addWidgets(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext); - - protected boolean shouldBindPlayerInventory() { - return true; - } -} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 6dbc6bd5b8b..2139bb4c547 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -2,15 +2,11 @@ import java.util.Objects; -import javax.annotation.Nonnull; - import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import cofh.api.energy.IEnergyReceiver; import gregtech.api.GregTechAPI; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.util.GTUtility; import ic2.api.energy.tile.IEnergySink; @@ -77,15 +73,7 @@ public static long emitEnergyToNetwork(long voltage, long amperage, IEnergyConne final ForgeDirection oppositeSide = Objects.requireNonNull(side.getOpposite()); final TileEntity tTileEntity = emitterTile.getTileEntityAtSide(side); - if (tTileEntity instanceof PowerLogicHost host) { - - final PowerLogic logic = host.getPowerLogic(oppositeSide); - if (logic == null || logic.isEnergyReceiver()) { - continue; - } - - usedAmperes += logic.injectEnergy(voltage, amperage - usedAmperes); - } else if (tTileEntity instanceof IEnergyConnected energyConnected) { + if (tTileEntity instanceof IEnergyConnected energyConnected) { if (emitter.getColorization() >= 0) { final byte tColor = energyConnected.getColorization(); if (tColor >= 0 && tColor != emitter.getColorization()) continue; @@ -107,72 +95,5 @@ public static long emitEnergyToNetwork(long voltage, long amperage, IEnergyConne } return usedAmperes; } - - /** - * Same as {@link #emitEnergyToNetwork(long, long, IEnergyConnected)}, but instead we remove the energy directly from the logic itself. - * @param emitter The host, which is trying to emit energy in the network - * @param outputSide side from where energy is being outputted to. If its {@link ForgeDirection#UNKNOWN} then it doesn't emit energy to the network - */ - public static void emitEnergyToNetwork(@Nonnull final PowerLogicHost emitter, @Nonnull final ForgeDirection outputSide) { - if (outputSide == ForgeDirection.UNKNOWN) return; - final PowerLogic emitterLogic = emitter.getPowerLogic(); - long usedAmperes = 0; - long voltage = emitterLogic.getVoltage(); - long amperage = emitterLogic.getMaxAmperage(); - if (!(emitter instanceof final IHasWorldObjectAndCoords emitterTile)) { - return; - } - // We need to make sure we can actually output energy on this side. This is more of a safety check. - if (emitter.getPowerLogic(outputSide) == null) { - return; - } - - final ForgeDirection oppositeSide = Objects.requireNonNull(outputSide.getOpposite()); - final TileEntity tileEntity = emitterTile.getTileEntityAtSide(outputSide); - if (tileEntity instanceof PowerLogicHost host) { - - final PowerLogic logic = host.getPowerLogic(oppositeSide); - if (logic == null || logic.isEnergyReceiver()) { - return; - } - - usedAmperes += logic.injectEnergy(voltage, amperage); - emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); - return; - } - - if (tileEntity instanceof IEnergyConnected energyConnected) { - if (emitter instanceof IColoredTileEntity coloredEmitter && coloredEmitter.getColorization() >= 0) { - final byte tColor = energyConnected.getColorization(); - if (tColor >= 0 && tColor != coloredEmitter.getColorization()) { - return; - } - } - usedAmperes += energyConnected.injectEnergyUnits(oppositeSide, voltage, amperage - usedAmperes); - emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); - return; - } - - if (tileEntity instanceof IEnergySink sink) { - if (sink.acceptsEnergyFrom((TileEntity) emitter, oppositeSide)) { - while (amperage > usedAmperes && sink.getDemandedEnergy() > 0 - && sink.injectEnergy(oppositeSide, voltage, voltage) < voltage) { - usedAmperes++; - } - emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); - return; - } - } - - if (GregTechAPI.mOutputRF && tileEntity instanceof IEnergyReceiver receiver) { - final int rfOut = GTUtility.safeInt(voltage * GregTechAPI.mEUtoRF / 100); - if (receiver.receiveEnergy(oppositeSide, rfOut, true) == rfOut) { - receiver.receiveEnergy(oppositeSide, rfOut, false); - usedAmperes++; - emitterLogic.removeEnergyUnsafe(usedAmperes * voltage); - return; - } - } - } } } diff --git a/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java b/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java deleted file mode 100644 index d4f0e96a36b..00000000000 --- a/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java +++ /dev/null @@ -1,344 +0,0 @@ -package gregtech.api.logic; - -import java.util.function.Supplier; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -import gregtech.api.interfaces.tileentity.IVoidable; -import gregtech.api.recipe.RecipeMap; -import gregtech.api.recipe.check.CheckRecipeResult; -import gregtech.api.recipe.check.CheckRecipeResultRegistry; -import gregtech.api.util.GTRecipe; -import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; - -/** - * Logic class to calculate result of recipe check from inputs. - */ -@SuppressWarnings({ "unused", "UnusedReturnValue" }) -public abstract class AbstractProcessingLogic

> { - - protected IVoidable machine; - protected Supplier> recipeMapSupplier; - protected GTRecipe lastRecipe; - protected RecipeMap lastRecipeMap; - protected ItemStack[] outputItems; - protected FluidStack[] outputFluids; - protected long calculatedEut; - protected int duration; - protected long availableVoltage; - protected long availableAmperage; - protected double overClockTimeReduction = 2.0; - protected double overClockPowerIncrease = 4.0; - protected boolean protectItems; - protected boolean protectFluids; - protected int maxParallel = 1; - protected Supplier maxParallelSupplier; - protected int calculatedParallels = 0; - protected int batchSize = 1; - protected double euModifier = 1.0; - protected double speedBoost = 1.0; - protected boolean amperageOC = true; - protected boolean isCleanroom; - protected boolean needWipeCraftingPatternRecipeCache; - - // #region Setters - - /** - * Overwrites item output result of the calculation. - */ - public P setOutputItems(ItemStack... itemOutputs) { - this.outputItems = itemOutputs; - return getThis(); - } - - /** - * Overwrites fluid output result of the calculation. - */ - public P setOutputFluids(FluidStack... fluidOutputs) { - this.outputFluids = fluidOutputs; - return getThis(); - } - - public P setIsCleanroom(boolean isCleanroom) { - this.isCleanroom = isCleanroom; - return getThis(); - } - - /** - * Sets max amount of parallel. - */ - public P setMaxParallel(int maxParallel) { - this.maxParallel = maxParallel; - return getThis(); - } - - /** - * Sets method to get max amount of parallel. - */ - public P setMaxParallelSupplier(Supplier supplier) { - this.maxParallelSupplier = supplier; - return getThis(); - } - - /** - * Sets batch size for batch mode. - */ - public P setBatchSize(int size) { - this.batchSize = size; - return getThis(); - } - - public P setRecipeMap(RecipeMap recipeMap) { - return setRecipeMapSupplier(() -> recipeMap); - } - - public P setRecipeMapSupplier(Supplier> supplier) { - this.recipeMapSupplier = supplier; - return getThis(); - } - - public P setEuModifier(double modifier) { - this.euModifier = modifier; - return getThis(); - } - - public P setSpeedBonus(double speedModifier) { - this.speedBoost = speedModifier; - return getThis(); - } - - /** - * Sets machine used for void protection logic. - */ - public P setMachine(IVoidable machine) { - this.machine = machine; - return getThis(); - } - - /** - * Overwrites duration result of the calculation. - */ - public P setDuration(int duration) { - this.duration = duration; - return getThis(); - } - - /** - * Overwrites EU/t result of the calculation. - */ - public P setCalculatedEut(long calculatedEut) { - this.calculatedEut = calculatedEut; - return getThis(); - } - - /** - * Sets voltage of the machine. It doesn't need to be actual voltage (excluding amperage) of the machine; - * For example, most of the multiblock machines set maximum possible input power (including amperage) as voltage - * and 1 as amperage. That way recipemap search will be executed with overclocked voltage. - */ - public P setAvailableVoltage(long voltage) { - availableVoltage = voltage; - return getThis(); - } - - /** - * Sets amperage of the machine. This amperage doesn't involve in EU/t when searching recipemap. - * Useful for preventing tier skip but still considering amperage for parallel. - */ - public P setAvailableAmperage(long amperage) { - availableAmperage = amperage; - return getThis(); - } - - public P setVoidProtection(boolean protectItems, boolean protectFluids) { - this.protectItems = protectItems; - this.protectFluids = protectFluids; - return getThis(); - } - - public P setOverclock(double timeReduction, double powerIncrease) { - this.overClockTimeReduction = timeReduction; - this.overClockPowerIncrease = powerIncrease; - return getThis(); - } - - /** - * Sets overclock ratio to 4/4. - */ - public P enablePerfectOverclock() { - return this.setOverclock(4.0, 4.0); - } - - /** - * Sets whether the multi should use amperage to OC or not - */ - public P setAmperageOC(boolean amperageOC) { - this.amperageOC = amperageOC; - return getThis(); - } - - /** - * Clears calculated results (and provided machine inputs) to prepare for the next machine operation. - */ - public P clear() { - this.calculatedEut = 0; - this.duration = 0; - this.calculatedParallels = 0; - return getThis(); - } - - // #endregion - - // #region Logic - - /** - * Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs. - */ - @Nonnull - public abstract CheckRecipeResult process(); - - /** - * Refreshes recipemap to use. Remember to call this before {@link #process} to make sure correct recipemap is used. - * - * @return Recipemap to use now - */ - protected RecipeMap preProcess() { - RecipeMap recipeMap; - if (recipeMapSupplier == null) { - recipeMap = null; - } else { - recipeMap = recipeMapSupplier.get(); - } - if (lastRecipeMap != recipeMap) { - if (lastRecipeMap != null) needWipeCraftingPatternRecipeCache = true; - lastRecipe = null; - lastRecipeMap = recipeMap; - } - - if (maxParallelSupplier != null) { - maxParallel = maxParallelSupplier.get(); - } - - return recipeMap; - } - - /** - * Check has been succeeded, so it applies the recipe and calculated parameters. - * At this point, inputs have been already consumed. - */ - @Nonnull - protected CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull ParallelHelper helper, - @Nonnull OverclockCalculator calculator, @Nonnull CheckRecipeResult result) { - if (recipe.mCanBeBuffered) { - lastRecipe = recipe; - } else { - lastRecipe = null; - } - calculatedParallels = helper.getCurrentParallel(); - - if (calculator.getConsumption() == Long.MAX_VALUE) { - return CheckRecipeResultRegistry.POWER_OVERFLOW; - } - if (calculator.getDuration() == Integer.MAX_VALUE) { - return CheckRecipeResultRegistry.DURATION_OVERFLOW; - } - - calculatedEut = calculator.getConsumption(); - - double finalDuration = calculateDuration(recipe, helper, calculator); - if (finalDuration >= Integer.MAX_VALUE) { - return CheckRecipeResultRegistry.DURATION_OVERFLOW; - } - duration = (int) finalDuration; - - CheckRecipeResult hookResult = onRecipeStart(recipe); - if (!hookResult.wasSuccessful()) { - return hookResult; - } - - outputItems = helper.getItemOutputs(); - outputFluids = helper.getFluidOutputs(); - - return result; - } - - /** - * Override to tweak final duration that will be set as a result of this logic class. - */ - protected double calculateDuration(@Nonnull GTRecipe recipe, @Nonnull ParallelHelper helper, - @Nonnull OverclockCalculator calculator) { - return calculator.getDuration() * helper.getDurationMultiplierDouble(); - } - - /** - * Override to do additional check for found recipe if needed. - */ - @Nonnull - protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { - return CheckRecipeResultRegistry.SUCCESSFUL; - } - - /** - * Override to perform additional logic when recipe starts. - *

- * This is called when the recipe processing logic has finished all - * checks, consumed all inputs, but has not yet set the outputs to - * be produced. Returning a result other than SUCCESSFUL will void - * all inputs! - */ - @Nonnull - protected CheckRecipeResult onRecipeStart(@Nonnull GTRecipe recipe) { - return CheckRecipeResultRegistry.SUCCESSFUL; - } - - /** - * Override to tweak overclock logic if needed. - */ - @Nonnull - protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { - return new OverclockCalculator().setRecipeEUt(recipe.mEUt) - .setAmperage(availableAmperage) - .setEUt(availableVoltage) - .setDuration(recipe.mDuration) - .setSpeedBoost(speedBoost) - .setEUtDiscount(euModifier) - .setAmperageOC(amperageOC) - .setDurationDecreasePerOC(overClockTimeReduction) - .setEUtIncreasePerOC(overClockPowerIncrease); - } - // #endregion - - // #region Getters - - public ItemStack[] getOutputItems() { - return outputItems; - } - - public FluidStack[] getOutputFluids() { - return outputFluids; - } - - public int getDuration() { - return duration; - } - - public long getCalculatedEut() { - return calculatedEut; - } - - public int getCurrentParallels() { - return calculatedParallels; - } - - @SuppressWarnings("unchecked") - @Nonnull - public P getThis() { - return (P) this; - } - - // #endregion -} diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java deleted file mode 100644 index 91df0bb1b64..00000000000 --- a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java +++ /dev/null @@ -1,113 +0,0 @@ -package gregtech.api.logic; - -import java.util.stream.LongStream; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public class ComplexParallelProcessingLogic

> - extends MuTEProcessingLogic

{ - - protected int maxComplexParallels; - protected ItemStack[][] outputItems; - protected FluidStack[][] outputFluids; - protected long[] calculatedEutValues; - protected int[] durations; - protected int[] progresses; - - public P setMaxComplexParallel(int maxComplexParallels) { - this.maxComplexParallels = maxComplexParallels; - reinitializeProcessingArrays(); - return getThis(); - } - - public ItemStack[] getOutputItems(int index) { - if (index >= 0 && index < maxComplexParallels) { - return outputItems[index]; - } - return null; - } - - public FluidStack[] getOutputFluids(int index) { - if (index >= 0 && index < maxComplexParallels) { - return outputFluids[index]; - } - return null; - } - - @Override - public boolean canWork() { - for (int i = 0; i < maxComplexParallels; i++) { - if (progresses[i] >= durations[i]) { - return machineHost.isAllowedToWork(); - } - } - return false; - } - - @Override - public long getCalculatedEut() { - return LongStream.of(this.calculatedEutValues) - .sum(); - } - - public int getDuration(int index) { - return durations[index]; - } - - public int getProgress(int index) { - return progresses[index]; - } - - @Override - public void progress() { - for (int i = 0; i < maxComplexParallels; i++) { - if (progresses[i] == durations[i]) { - progresses[i] = 0; - durations[i] = 0; - output(i); - continue; - } - progresses[i] = progresses[i] + 1; - } - } - - @Override - public void startCheck() { - for (int i = 0; i < maxComplexParallels; i++) { - if (durations[i] > 0) continue; - recipeResult = process(); - calculatedEutValues[i] = calculatedEut; - durations[i] = duration; - progresses[i] = 0; - outputItems[i] = getOutputItems(); - outputFluids[i] = getOutputFluids(); - } - } - - protected void output(int index) { - setOutputItems(getOutputItems(index)); - setOutputFluids(getOutputFluids(index)); - output(); - } - - protected void reinitializeProcessingArrays() { - ItemStack[][] oldOutputItems = outputItems; - FluidStack[][] oldOutputFluids = outputFluids; - long[] oldCalculatedEutValues = calculatedEutValues; - int[] oldDurations = durations; - int[] oldProgresses = progresses; - outputItems = new ItemStack[maxComplexParallels][]; - outputFluids = new FluidStack[maxComplexParallels][]; - calculatedEutValues = new long[maxComplexParallels]; - durations = new int[maxComplexParallels]; - progresses = new int[maxComplexParallels]; - System.arraycopy(oldOutputItems, 0, outputItems, 0, oldOutputItems.length); - System.arraycopy(oldOutputFluids, 0, outputFluids, 0, oldOutputFluids.length); - System.arraycopy(oldCalculatedEutValues, 0, calculatedEutValues, 0, oldCalculatedEutValues.length); - for (int i = 0; i < oldDurations[i]; i++) { - durations[i] = oldDurations[i]; - } - System.arraycopy(oldProgresses, 0, progresses, 0, oldProgresses.length); - } -} diff --git a/src/main/java/gregtech/api/logic/ControllerFluidLogic.java b/src/main/java/gregtech/api/logic/ControllerFluidLogic.java deleted file mode 100644 index 227f7641ce5..00000000000 --- a/src/main/java/gregtech/api/logic/ControllerFluidLogic.java +++ /dev/null @@ -1,152 +0,0 @@ -package gregtech.api.logic; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; - -import org.apache.commons.lang3.tuple.Pair; - -/** - * Controller logic for Fluid inventories - * - * @author BlueWeabo - */ -public class ControllerFluidLogic { - - private final Map inventories = new HashMap<>(); - private final Set> unallocatedInventories = new HashSet<>(); - - public void addInventory(@Nonnull UUID id, @Nonnull FluidInventoryLogic inventory) { - Pair found = checkIfInventoryExistsAsUnallocated(inventory); - if (inventory.isUpgradeInventory() && found != null) { - unallocatedInventories.remove(found); - inventories.put(id, found.getRight()); - return; - } - inventories.put(id, inventory); - } - - @Nonnull - public UUID addInventory(@Nonnull FluidInventoryLogic inventory) { - Pair found = checkIfInventoryExistsAsUnallocated(inventory); - if (inventory.isUpgradeInventory() && found != null) { - unallocatedInventories.remove(found); - inventories.put(found.getLeft(), found.getRight()); - return Objects.requireNonNull(found.getLeft()); - } - UUID generatedUUID = Objects.requireNonNull(UUID.randomUUID()); - inventories.put(generatedUUID, inventory); - return generatedUUID; - } - - @Nullable - private Pair checkIfInventoryExistsAsUnallocated( - @Nonnull FluidInventoryLogic inventory) { - if (unallocatedInventories.isEmpty()) { - return null; - } - return unallocatedInventories.stream() - .filter( - unallocated -> unallocated.getRight() - .getTier() == inventory.getTier()) - .findFirst() - .get(); - } - - /** - * Removes the inventory with said id and gives it back to be processed if needed. - */ - @Nonnull - public FluidInventoryLogic removeInventory(@Nonnull UUID id) { - return Objects.requireNonNull(inventories.remove(id)); - } - - @Nonnull - public FluidInventoryLogic getAllInventoryLogics() { - return new FluidInventoryLogic( - inventories.values() - .stream() - .map(inv -> inv.getInventory()) - .collect(Collectors.toList())); - } - - @Nonnull - public FluidInventoryLogic getInventoryLogic(@Nullable UUID id) { - if (id == null) return getAllInventoryLogics(); - return Objects.requireNonNull(inventories.getOrDefault(id, getAllInventoryLogics())); - } - - @Nonnull - public Set> getAllInventoryLogicsAsEntrySet() { - return Objects.requireNonNull(inventories.entrySet()); - } - - @Nonnull - public String getInventoryDisplayName(@Nullable UUID id) { - if (id == null) return ""; - FluidInventoryLogic logic = inventories.get(id); - if (logic == null) return ""; - String displayName = logic.getDisplayName(); - if (displayName == null) return Objects.requireNonNull(id.toString()); - return displayName; - } - - public void setInventoryDisplayName(@Nullable UUID id, @Nullable String displayName) { - if (id == null) return; - FluidInventoryLogic logic = inventories.get(id); - if (logic == null) return; - logic.setDisplayName(displayName); - } - - @Nonnull - public NBTTagCompound saveToNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - NBTTagList inventoriesNBT = new NBTTagList(); - inventories.forEach((uuid, inventory) -> { - NBTTagCompound inventoryNBT = new NBTTagCompound(); - inventoryNBT.setTag("inventory", inventory.saveToNBT()); - inventoryNBT.setString("uuid", uuid.toString()); - inventoryNBT.setInteger( - "invSize", - inventory.getInventory() - .getTanks()); - inventoryNBT.setLong( - "tankCapacity", - inventory.getInventory() - .getTankCapacity(0)); - inventoriesNBT.appendTag(inventoryNBT); - }); - nbt.setTag("inventories", inventoriesNBT); - return nbt; - } - - public void loadFromNBT(@Nonnull NBTTagCompound nbt) { - NBTTagList inventoriesNBT = nbt.getTagList("inventories", Constants.NBT.TAG_COMPOUND); - if (inventoriesNBT == null) return; - for (int i = 0; i < inventoriesNBT.tagCount(); i++) { - NBTTagCompound inventoryNBT = inventoriesNBT.getCompoundTagAt(i); - UUID uuid = UUID.fromString(inventoryNBT.getString("uuid")); - FluidInventoryLogic inventory = new FluidInventoryLogic( - inventoryNBT.getInteger("invSize"), - inventoryNBT.getLong("tankCapacity")); - inventory.loadFromNBT(inventoryNBT.getCompoundTag("inventory")); - if (inventory.isUpgradeInventory()) { - unallocatedInventories.add(Pair.of(uuid, inventory)); - } else { - inventories.put(uuid, inventory); - } - } - } -} diff --git a/src/main/java/gregtech/api/logic/ControllerItemLogic.java b/src/main/java/gregtech/api/logic/ControllerItemLogic.java deleted file mode 100644 index 28cc75313a3..00000000000 --- a/src/main/java/gregtech/api/logic/ControllerItemLogic.java +++ /dev/null @@ -1,148 +0,0 @@ -package gregtech.api.logic; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; - -import org.apache.commons.lang3.tuple.Pair; - -/** - * Logic of the Item logic for the controller. This is controlling all of the inventories. - * - * @author BlueWeabo - */ -public class ControllerItemLogic { - - private final Map inventories = new HashMap<>(); - private final Set> unallocatedInventories = new HashSet<>(); - - public void addInventory(@Nonnull UUID id, @Nonnull ItemInventoryLogic inventory) { - Pair found = checkIfInventoryExistsAsUnallocated(inventory); - if (inventory.isUpgradeInventory() && found != null) { - unallocatedInventories.remove(found); - inventories.put(id, found.getRight()); - return; - } - inventories.put(id, inventory); - } - - @Nonnull - public UUID addInventory(@Nonnull ItemInventoryLogic inventory) { - Pair found = checkIfInventoryExistsAsUnallocated(inventory); - if (inventory.isUpgradeInventory() && found != null) { - unallocatedInventories.remove(found); - inventories.put(found.getLeft(), found.getRight()); - return Objects.requireNonNull(found.getLeft()); - } - UUID generatedUUID = Objects.requireNonNull(UUID.randomUUID()); - inventories.put(generatedUUID, inventory); - return generatedUUID; - } - - @Nullable - private Pair checkIfInventoryExistsAsUnallocated(@Nonnull ItemInventoryLogic inventory) { - if (unallocatedInventories.isEmpty()) { - return null; - } - return unallocatedInventories.stream() - .filter( - unallocated -> unallocated.getRight() - .getTier() == inventory.getTier() - && unallocated.getRight() - .getSlots() == inventory.getSlots()) - .findFirst() - .get(); - } - - /** - * Removes the inventory with said id and gives it back to be processed if needed. - */ - @Nonnull - public ItemInventoryLogic removeInventory(@Nonnull UUID id) { - return Objects.requireNonNull(inventories.remove(id)); - } - - @Nonnull - public ItemInventoryLogic getAllInventoryLogics() { - return new ItemInventoryLogic( - inventories.values() - .stream() - .map(inv -> inv.getInventory()) - .collect(Collectors.toList())); - } - - @Nonnull - public ItemInventoryLogic getInventoryLogic(@Nullable UUID id) { - if (id == null) return getAllInventoryLogics(); - return Objects.requireNonNull(inventories.getOrDefault(id, getAllInventoryLogics())); - } - - @Nonnull - public Set> getAllInventoryLogicsAsEntrySet() { - return Objects.requireNonNull(inventories.entrySet()); - } - - @Nullable - public String getInventoryDisplayName(@Nullable UUID id) { - if (id == null) return ""; - ItemInventoryLogic logic = inventories.get(id); - if (logic == null) return ""; - String displayName = logic.getDisplayName(); - if (displayName == null) return Objects.requireNonNull(id.toString()); - return displayName; - } - - public void setInventoryDisplayName(@Nullable UUID id, @Nullable String displayName) { - if (id == null) return; - ItemInventoryLogic logic = inventories.get(id); - if (logic == null) return; - logic.setDisplayName(displayName); - } - - @Nonnull - public NBTTagCompound saveToNBT() { - NBTTagCompound nbt = new NBTTagCompound(); - NBTTagList inventoriesNBT = new NBTTagList(); - inventories.forEach((uuid, inventory) -> { - NBTTagCompound inventoryNBT = new NBTTagCompound(); - inventoryNBT.setTag("inventory", inventory.saveToNBT()); - inventoryNBT.setString("uuid", uuid.toString()); - inventoryNBT.setInteger( - "invSize", - inventory.getInventory() - .getSlots()); - inventoriesNBT.appendTag(inventoryNBT); - }); - nbt.setTag("inventories", inventoriesNBT); - return nbt; - } - - public void loadFromNBT(@Nonnull NBTTagCompound nbt) { - NBTTagList inventoriesNBT = nbt.getTagList("inventories", Constants.NBT.TAG_COMPOUND); - if (inventoriesNBT == null) return; - for (int i = 0; i < inventoriesNBT.tagCount(); i++) { - NBTTagCompound inventoryNBT = inventoriesNBT.getCompoundTagAt(i); - UUID uuid = UUID.fromString(inventoryNBT.getString("uuid")); - ItemInventoryLogic inventory = new ItemInventoryLogic(inventoryNBT.getInteger("invSize")); - NBTTagCompound internalInventoryNBT = inventoryNBT.getCompoundTag("inventory"); - if (internalInventoryNBT != null) inventory.loadFromNBT(internalInventoryNBT); - if (inventory.isUpgradeInventory()) { - unallocatedInventories.add(Pair.of(uuid, inventory)); - } else { - inventories.put(uuid, inventory); - } - } - } -} diff --git a/src/main/java/gregtech/api/logic/FluidInventoryLogic.java b/src/main/java/gregtech/api/logic/FluidInventoryLogic.java deleted file mode 100644 index 1949a27e2ae..00000000000 --- a/src/main/java/gregtech/api/logic/FluidInventoryLogic.java +++ /dev/null @@ -1,268 +0,0 @@ -package gregtech.api.logic; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; - -import com.gtnewhorizons.modularui.api.fluids.FluidTanksHandler; -import com.gtnewhorizons.modularui.api.fluids.IFluidTankLong; -import com.gtnewhorizons.modularui.api.fluids.IFluidTanksHandler; -import com.gtnewhorizons.modularui.api.fluids.ListFluidHandler; -import com.gtnewhorizons.modularui.api.math.Size; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget; -import com.gtnewhorizons.modularui.common.widget.Scrollable; - -/** - * Generic Fluid logic for MuTEs. - * - * @author BlueWeabo - */ -public class FluidInventoryLogic { - - private static final int DEFAULT_COLUMNS_PER_ROW = 4; - private static final int POSITION_INTERVAL = 18; - private static final Size SIZE = new Size(18, 18); - - protected String displayName = ""; - @Nonnull - protected final IFluidTanksHandler inventory; - protected final Map fluidToTankMap; - protected int tier = 0; - protected boolean isUpgradeInventory = false; - - public FluidInventoryLogic(int numberOfSlots, long capacityOfEachTank) { - this(new FluidTanksHandler(numberOfSlots, capacityOfEachTank), 0, false); - } - - public FluidInventoryLogic(int numberOfSlots, long capacityOfEachTank, int tier) { - this(new FluidTanksHandler(numberOfSlots, capacityOfEachTank), tier, false); - } - - public FluidInventoryLogic(int numberOfSlots, long capacityOfEachTank, int tier, boolean isUpgradeInventory) { - this(new FluidTanksHandler(numberOfSlots, capacityOfEachTank), tier, isUpgradeInventory); - } - - public FluidInventoryLogic(@Nonnull IFluidTanksHandler inventory, int tier, boolean isUpgradeInventory) { - this.inventory = inventory; - fluidToTankMap = new HashMap<>(inventory.getTanks()); - this.tier = tier; - this.isUpgradeInventory = isUpgradeInventory; - } - - public FluidInventoryLogic(Collection inventories) { - this(new ListFluidHandler(inventories), -1, false); - } - - @Nullable - public String getDisplayName() { - return displayName; - } - - public int getTier() { - return tier; - } - - public boolean isUpgradeInventory() { - return isUpgradeInventory; - } - - public void setDisplayName(@Nullable String displayName) { - this.displayName = displayName; - } - - /** - * - * @return The Fluid Inventory Logic as an NBTTagList to be saved in another nbt as how one wants. - */ - @Nonnull - public NBTTagCompound saveToNBT() { - final NBTTagCompound nbt = new NBTTagCompound(); - final NBTTagList tList = new NBTTagList(); - for (int tankNumber = 0; tankNumber < inventory.getTanks(); tankNumber++) { - final IFluidTankLong tank = inventory.getFluidTank(tankNumber); - if (tank == null) continue; - - final NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("s", (byte) tankNumber); - tank.saveToNBT(tag); - tList.appendTag(tag); - } - nbt.setTag("inventory", tList); - nbt.setInteger("tier", tier); - if (displayName != null) { - nbt.setString("displayName", displayName); - } - nbt.setBoolean("isUpgradeInventory", isUpgradeInventory); - return nbt; - } - - /** - * Loads the Item Inventory Logic from an NBTTagList. - */ - public void loadFromNBT(@Nonnull NBTTagCompound nbt) { - NBTTagList nbtList = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); - for (int i = 0; i < nbtList.tagCount(); i++) { - final NBTTagCompound tankNBT = nbtList.getCompoundTagAt(i); - final int tank = tankNBT.getShort("s"); - if (tank >= 0 && tank < inventory.getTanks()) inventory.getFluidTank(tank) - .loadFromNBT(tankNBT); - if (inventory.getFluidInTank(tank) != null) { - fluidToTankMap.put(inventory.getFluidInTank(tank), inventory.getFluidTank(tank)); - } - } - tier = nbt.getInteger("tier"); - if (nbt.hasKey("displayName")) { - displayName = nbt.getString("displayName"); - } - isUpgradeInventory = nbt.getBoolean("isUpgradeInventory"); - } - - @Nonnull - public IFluidTanksHandler getInventory() { - return inventory; - } - - @Nonnull - public FluidStack[] getStoredFluids() { - final FluidStack[] fluids = inventory.getFluids() - .stream() - .filter(Objects::nonNull) - .toArray(FluidStack[]::new); - if (fluids == null) { - return new FluidStack[0]; - } - return fluids; - } - - public boolean isFluidValid(@Nullable Fluid fluid) { - return fluid != null; - } - - /** - * @param fluid What we are trying to input - * @param amount amount of fluid we are trying to put - * @return amount of fluid filled into the tank - */ - public long fill(@Nullable Fluid fluid, long amount, boolean simulate) { - if (!isFluidValid(fluid)) return 0; - IFluidTankLong tank = fluidToTankMap.get(fluid); - if (tank != null) { - return tank.fill(fluid, amount, !simulate); - } - int tankNumber = 0; - tank = inventory.getFluidTank(tankNumber++); - while (tank.getStoredFluid() != fluid && tank.getStoredFluid() != null) { - tank = inventory.getFluidTank(tankNumber++); - } - fluidToTankMap.put(fluid, tank); - return tank.fill(fluid, amount, !simulate); - } - - @Nullable - public FluidStack fill(@Nullable FluidStack fluid) { - if (fluid == null) return null; - for (int i = 0; i < inventory.getTanks(); i++) { - fill(fluid.getFluid(), fluid.amount, false); - } - return fluid; - } - - /** - * Try and drain the first fluid found for that amount. Used by GT_Cover_Pump - * - * @param amount Fluid to drain from the tank - * @return A fluidstack with the possible amount drained - */ - @Nullable - public FluidStack drain(long amount, boolean simulate) { - for (int i = 0; i < inventory.getTanks(); i++) { - Fluid fluid = inventory.getFluidInTank(i); - FluidStack drained = drain(fluid, amount, simulate); - if (drained != null) return drained; - } - - return null; - } - - @Nullable - public FluidStack drain(Fluid fluid, long amount, boolean simulate) { - if (!isFluidValid(fluid)) return null; - IFluidTankLong tank = fluidToTankMap.get(fluid); - if (tank != null) { - return tank.drain(amount, !simulate); - } - int tankNumber = 0; - tank = inventory.getFluidTank(tankNumber++); - while (tank.getStoredFluid() != fluid) { - tank = inventory.getFluidTank(tankNumber++); - } - fluidToTankMap.put(fluid, tank); - return tank.drain(amount, !simulate); - } - - public void update() { - for (int i = 0; i < inventory.getTanks(); i++) { - IFluidTankLong tank = inventory.getFluidTank(i); - if (tank.getFluidAmountLong() > 0) continue; - tank.setFluid(null, 0); - } - } - - public long calculateAmountOfTimesFluidCanBeTaken(Fluid fluid, long amountToTake) { - if (!isFluidValid(fluid)) return 0; - IFluidTankLong tank = fluidToTankMap.get(fluid); - if (tank == null) return 0; - return tank.getFluidAmountLong() / amountToTake; - } - - @Nonnull - public Map getMapOfStoredFluids() { - Map map = new HashMap<>(); - for (int i = 0; i < inventory.getTanks(); i++) { - IFluidTankLong tank = inventory.getFluidTank(i); - if (tank == null) continue; - Fluid fluid = tank.getStoredFluid(); - if (fluid == null) continue; - map.put(fluid, map.getOrDefault(fluid, 0L) + tank.getFluidAmountLong()); - } - return map; - } - - /** - * Return a scrollable widget with only the inventory. - */ - @Nonnull - public Widget getGuiPart() { - return getGUIPart(DEFAULT_COLUMNS_PER_ROW); - } - - /** - * Return a scrollable widget with only the inventory. - */ - @Nonnull - public Widget getGUIPart(int columnsPerRow) { - final Scrollable scrollable = new Scrollable(); - scrollable.setVerticalScroll(); - for (int rows = 0; rows * 4 < inventory.getTanks(); rows++) { - final int columnsToMake = Math.min(inventory.getTanks() - rows * 4, 4); - for (int column = 0; column < columnsToMake; column++) { - final FluidSlotWidget fluidSlot = new FluidSlotWidget(inventory, rows * 4 + column); - scrollable.widget( - fluidSlot.setPos(column * POSITION_INTERVAL, rows * POSITION_INTERVAL) - .setSize(SIZE)); - } - } - return scrollable; - } -} diff --git a/src/main/java/gregtech/api/logic/ItemInventoryLogic.java b/src/main/java/gregtech/api/logic/ItemInventoryLogic.java deleted file mode 100644 index b37920d2061..00000000000 --- a/src/main/java/gregtech/api/logic/ItemInventoryLogic.java +++ /dev/null @@ -1,314 +0,0 @@ -package gregtech.api.logic; - -import java.util.Collection; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.common.util.Constants; - -import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; -import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; -import com.gtnewhorizons.modularui.api.forge.ListItemHandler; -import com.gtnewhorizons.modularui.api.math.Size; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.Scrollable; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; - -import gregtech.api.util.GTUtility; -import gregtech.api.util.item.ItemHolder; - -/** - * Generic Item logic for MuTEs. - * - * @author BlueWeabo - */ -public class ItemInventoryLogic { - - private static final int DEFAULT_COLUMNS_PER_ROW = 4; - private static final int POSITION_INTERVAL = 18; - private static final Size SIZE = new Size(18, 18); - - protected String displayName; - @Nonnull - protected final IItemHandlerModifiable inventory; - protected UUID connectedFluidInventory; - protected int tier; - protected boolean isUpgradeInventory; - protected Map cachedItemMap; - protected boolean inRecipeCheck; - - public ItemInventoryLogic(int numberOfSlots) { - this(numberOfSlots, 0); - } - - public ItemInventoryLogic(int numberOfSlots, int tier) { - this(new ItemStackHandler(numberOfSlots), tier, false); - } - - public ItemInventoryLogic(int numberOfSlots, int tier, boolean isUpgradeInventory) { - this(new ItemStackHandler(numberOfSlots), tier, isUpgradeInventory); - } - - public ItemInventoryLogic(@Nonnull IItemHandlerModifiable inventory, int tier, boolean isUpgradeInventory) { - this.inventory = inventory; - this.tier = tier; - this.isUpgradeInventory = isUpgradeInventory; - } - - public ItemInventoryLogic(Collection inventories) { - this(new ListItemHandler(inventories), -1, false); - } - - @Nullable - public String getDisplayName() { - return displayName; - } - - public int getTier() { - return tier; - } - - public boolean isUpgradeInventory() { - return isUpgradeInventory; - } - - public int getSlots() { - return getInventory().getSlots(); - } - - public void setDisplayName(@Nullable String displayName) { - this.displayName = displayName; - } - - @Nullable - public UUID getConnectedFluidInventoryID() { - return connectedFluidInventory; - } - - public void setConnectedFluidInventoryID(@Nullable UUID connectedFluidTank) { - this.connectedFluidInventory = connectedFluidTank; - } - - /** - * - * @return The Item Inventory Logic as an NBTTagCompound to be saved in another nbt as how one wants. - */ - @Nonnull - public NBTTagCompound saveToNBT() { - final NBTTagCompound nbt = new NBTTagCompound(); - final NBTTagList tList = new NBTTagList(); - for (int slot = 0; slot < inventory.getSlots(); slot++) { - final ItemStack tStack = inventory.getStackInSlot(slot); - if (tStack == null) continue; - - final NBTTagCompound tag = new NBTTagCompound(); - tag.setByte("s", (byte) slot); - tStack.writeToNBT(tag); - tList.appendTag(tag); - } - nbt.setTag("inventory", tList); - nbt.setInteger("tier", tier); - if (displayName != null) { - nbt.setString("displayName", displayName); - } - nbt.setBoolean("isUpgradeInventory", isUpgradeInventory); - if (connectedFluidInventory != null) { - nbt.setString("connectedFluidInventory", connectedFluidInventory.toString()); - } - return nbt; - } - - /** - * Loads the Item Inventory Logic from an NBTTagCompound. - */ - public void loadFromNBT(@Nonnull NBTTagCompound nbt) { - tier = nbt.getInteger("tier"); - if (nbt.hasKey("displayName")) { - displayName = nbt.getString("displayName"); - } - - isUpgradeInventory = nbt.getBoolean("isUpgradeInventory"); - if (nbt.hasKey("connectedFluidInventory")) { - connectedFluidInventory = UUID.fromString(nbt.getString("connectedFluidInventory")); - } - - NBTTagList nbtList = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); - if (nbtList == null) return; - - for (int i = 0; i < nbtList.tagCount(); i++) { - final NBTTagCompound tNBT = nbtList.getCompoundTagAt(i); - final int tSlot = tNBT.getShort("s"); - if (tSlot >= 0 && tSlot < inventory.getSlots()) { - inventory.setStackInSlot(tSlot, GTUtility.loadItem(tNBT)); - } - } - } - - @Nonnull - public IItemHandlerModifiable getInventory() { - return inventory; - } - - @Nonnull - public ItemStack[] getStoredItems() { - final ItemStack[] items = inventory.getStacks() - .stream() - .filter(Objects::nonNull) - .toArray(ItemStack[]::new); - if (items == null) { - return new ItemStack[0]; - } - return items; - } - - public boolean isStackValid(ItemStack item) { - return true; - } - - @Nullable - public ItemStack insertItem(ItemStack item) { - if (!isStackValid(item)) return item; - for (int i = 0; i < inventory.getSlots() && item != null && item.stackSize > 0; i++) { - item = inventory.insertItem(i, item, false); - } - return item; - } - - @Nullable - public ItemStack extractItem(int slot, int amount) { - return inventory.extractItem(slot, amount, false); - } - - public boolean subtractItemAmount(@Nonnull ItemHolder item, long amount, boolean simulate) { - Map itemMap = getMapOfStoredItems(); - if (!itemMap.containsKey(item)) { - return false; - } - - if (itemMap.get(item) < amount) { - return false; - } - - if (simulate) { - return true; - } - - itemMap.put(item, itemMap.get(item) - amount); - return true; - } - - @Nullable - public ItemStack getItemInSlot(int slot) { - return inventory.getStackInSlot(slot); - } - - public void sort() { - Map itemMap = getMapOfStoredItems(); - List sortedItems = itemMap.keySet() - .stream() - .sorted( - Comparator.comparing( - a -> a.getItem() - .getUnlocalizedName() + a.getMeta())) - .collect(Collectors.toList()); - putInItemsFromMap(itemMap, sortedItems); - } - - public void update(boolean shouldSort) { - if (shouldSort) { - sort(); - } - - for (int i = 0; i < inventory.getSlots(); i++) { - ItemStack item = inventory.getStackInSlot(i); - if (item == null) continue; - if (item.stackSize > 0) continue; - inventory.setStackInSlot(i, null); - } - } - - /** - * Return a scrollable widget with only the inventory. - */ - @Nonnull - public Widget getGuiPart() { - return getGUIPart(DEFAULT_COLUMNS_PER_ROW); - } - - /** - * Return a scrollable widget with only the inventory. - */ - @Nonnull - public Widget getGUIPart(int columnsPerRow) { - final Scrollable scrollable = new Scrollable(); - scrollable.setVerticalScroll(); - for (int rows = 0; rows * columnsPerRow < Math.min(inventory.getSlots(), 128); rows++) { - final int columnsToMake = Math - .min(Math.min(inventory.getSlots(), 128) - rows * columnsPerRow, columnsPerRow); - for (int column = 0; column < columnsToMake; column++) { - scrollable.widget( - new SlotWidget(inventory, rows * columnsPerRow + column) - .setPos(column * POSITION_INTERVAL, rows * POSITION_INTERVAL) - .setSize(SIZE)); - } - } - return scrollable; - } - - public void startRecipeCheck() { - cachedItemMap = getMapOfStoredItems(); - inRecipeCheck = true; - } - - public void stopRecipeCheck() { - inRecipeCheck = false; - putInItemsFromMap(cachedItemMap, null); - cachedItemMap = null; - } - - @Nonnull - public Map getMapOfStoredItems() { - if (inRecipeCheck) return cachedItemMap; - Map items = new HashMap<>(); - for (int i = 0; i < inventory.getSlots(); i++) { - ItemStack item = extractItem(i, Integer.MAX_VALUE); - if (item == null) continue; - ItemHolder itemHolder = new ItemHolder(item); - items.put(itemHolder, items.getOrDefault(itemHolder, 0L) + item.stackSize); - } - return items; - } - - protected void putInItemsFromMap(@Nonnull Map itemMap, @Nullable List sortedList) { - for (ItemHolder itemHolder : (sortedList == null ? itemMap.keySet() : sortedList)) { - long itemAmount = itemMap.get(itemHolder); - ItemStack item = new ItemStack(itemHolder.getItem(), 0, itemHolder.getMeta()); - item.setTagCompound(itemHolder.getNBT()); - while (itemAmount > 0) { - item.stackSize = (int) Math.min(item.getMaxStackSize(), itemAmount); - itemAmount -= item.stackSize; - insertItem(item); - } - } - } - - public long calculateAmountOfTimesItemCanBeTaken(ItemHolder item, long amount) { - return getMapOfStoredItems().getOrDefault(item, 0L) / amount; - } - - public Set getSetOfStoredItems() { - return getMapOfStoredItems().keySet(); - } -} diff --git a/src/main/java/gregtech/api/logic/ModelRenderLogic.java b/src/main/java/gregtech/api/logic/ModelRenderLogic.java deleted file mode 100644 index d9f2fdcf274..00000000000 --- a/src/main/java/gregtech/api/logic/ModelRenderLogic.java +++ /dev/null @@ -1,5 +0,0 @@ -package gregtech.api.logic; - -public abstract class ModelRenderLogic { - -} diff --git a/src/main/java/gregtech/api/logic/MuTEProcessingLogic.java b/src/main/java/gregtech/api/logic/MuTEProcessingLogic.java deleted file mode 100644 index 0d6bf4cac95..00000000000 --- a/src/main/java/gregtech/api/logic/MuTEProcessingLogic.java +++ /dev/null @@ -1,256 +0,0 @@ -package gregtech.api.logic; - -import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraftforge.fluids.FluidStack; - -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.Scrollable; - -import gregtech.api.enums.InventoryType; -import gregtech.api.logic.interfaces.ProcessingLogicHost; -import gregtech.api.recipe.RecipeMap; -import gregtech.api.recipe.check.CheckRecipeResult; -import gregtech.api.recipe.check.CheckRecipeResultRegistry; -import gregtech.api.util.GTRecipe; -import gregtech.api.util.GTUtility; -import gregtech.api.util.OverclockCalculator; -import gregtech.api.util.ParallelHelper; - -/** - * Processing logic class, dedicated for MultiTileEntities. - */ -public class MuTEProcessingLogic

> extends AbstractProcessingLogic

{ - - protected boolean hasWork; - protected int progress; - protected ProcessingLogicHost

machineHost; - @Nonnull - protected CheckRecipeResult recipeResult = CheckRecipeResultRegistry.NONE; - @Nullable - protected UUID itemOutputID; - @Nullable - protected UUID fluidOutputID; - - public P setMachineHost(@Nonnull ProcessingLogicHost

machineHost) { - this.machineHost = machineHost; - return getThis(); - } - - // #region Logic - - @Nonnull - @Override - public CheckRecipeResult process() { - RecipeMap recipeMap = preProcess(); - - ItemInventoryLogic itemInput = null; - FluidInventoryLogic fluidInput = null; - if (machineHost.isInputSeparated()) { - for (Map.Entry itemEntry : machineHost - .getAllItemInventoryLogics(InventoryType.Input)) { - itemOutputID = Objects.requireNonNull(itemEntry.getKey()); - itemInput = Objects.requireNonNull(itemEntry.getValue()); - fluidInput = Objects.requireNonNull( - machineHost.getFluidLogic(InventoryType.Input, itemInput.getConnectedFluidInventoryID())); - fluidOutputID = itemInput.getConnectedFluidInventoryID(); - } - } else { - itemInput = Objects.requireNonNull(machineHost.getItemLogic(InventoryType.Input, null)); - fluidInput = Objects.requireNonNull(machineHost.getFluidLogic(InventoryType.Input, null)); - } - - CheckRecipeResult recipeValidatorResult = null; - if (recipeValidatorResult != null) { - return recipeValidatorResult; - } - - return processRecipe(null, Objects.requireNonNull(itemInput), Objects.requireNonNull(fluidInput)); - } - - @Nonnull - protected CheckRecipeResult processRecipe(@Nonnull List recipes, @Nonnull ItemInventoryLogic itemInput, - @Nonnull FluidInventoryLogic fluidInput) { - CheckRecipeResult result = CheckRecipeResultRegistry.INTERNAL_ERROR; - for (GTRecipe recipe : recipes) { - Objects.requireNonNull(recipe); - ParallelHelper helper = createParallelHelper(recipe, itemInput, fluidInput); - OverclockCalculator calculator = createOverclockCalculator(recipe); - helper.setCalculator(calculator); - helper.build(); - result = helper.getResult(); - if (result.wasSuccessful()) { - return applyRecipe(recipe, helper, calculator, result); - } - } - return result; - } - - /** - * Override if you don't work with regular gt recipe maps - */ - @Nonnull - protected Object findRecipe(@Nullable RecipeMap map, @Nonnull ItemInventoryLogic itemInput, - @Nonnull FluidInventoryLogic fluidInput) { - if (map == null) { - return false; - } - - return true; - } - - @Nonnull - protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe, @Nonnull ItemInventoryLogic itemInput, - @Nonnull FluidInventoryLogic fluidInput) { - return new ParallelHelper().setRecipe(recipe) - .setItemInputInventory(itemInput) - .setFluidInputInventory(fluidInput) - .setAvailableEUt(availableVoltage * availableAmperage) - .setMaxParallel(maxParallel) - .setEUtModifier(euModifier) - .enableBatchMode(batchSize) - .setConsumption(true) - .setOutputCalculation(true) - .setMuTEMode(true); - } - - // #endregion - - // #region Getters - - @Nonnull - public CheckRecipeResult getResult() { - return recipeResult; - } - - public int getProgress() { - return progress; - } - - // #endregion - - // #region Other - - public void startCheck() { - recipeResult = process(); - } - - public void progress() { - if (!hasWork) return; - if (progress == duration) { - progress = 0; - duration = 0; - calculatedEut = 0; - output(); - return; - } - progress++; - } - - protected void output() { - ItemInventoryLogic itemOutput = machineHost.getItemLogic(InventoryType.Output, itemOutputID); - FluidInventoryLogic fluidOutput = machineHost.getFluidLogic(InventoryType.Output, fluidOutputID); - if (itemOutput == null || fluidOutput == null) return; - for (ItemStack item : outputItems) { - if (item == null) continue; - itemOutput.insertItem(item); - } - for (FluidStack fluid : outputFluids) { - if (fluid == null) continue; - fluidOutput.fill(fluid.getFluid(), fluid.amount, false); - } - outputItems = new ItemStack[0]; - outputFluids = new FluidStack[0]; - } - - public boolean canWork() { - return !hasWork && machineHost.isAllowedToWork(); - } - - /** - * By how much to increase the progress? - * - * @param progressAmount in ticks - */ - public void increaseProgress(int progressAmount) { - progress += progressAmount; - } - - public NBTTagCompound saveToNBT() { - NBTTagCompound logicNBT = new NBTTagCompound(); - logicNBT.setLong("eutConsumption", calculatedEut); - logicNBT.setInteger("duration", duration); - logicNBT.setInteger("progress", progress); - logicNBT.setBoolean("hasWork", hasWork); - if (outputItems != null) { - NBTTagList itemOutputsNBT = new NBTTagList(); - for (ItemStack item : outputItems) { - itemOutputsNBT.appendTag(GTUtility.saveItem(item)); - } - logicNBT.setTag("itemOutputs", itemOutputsNBT); - } - if (outputFluids != null) { - NBTTagList fluidOutputsNBT = new NBTTagList(); - for (FluidStack fluid : outputFluids) { - fluidOutputsNBT.appendTag(fluid.writeToNBT(new NBTTagCompound())); - } - logicNBT.setTag("fluidOutputs", fluidOutputsNBT); - } - if (itemOutputID != null) { - logicNBT.setString("itemOutputID", itemOutputID.toString()); - } - if (fluidOutputID != null) { - logicNBT.setString("fluidOutputID", fluidOutputID.toString()); - } - return logicNBT; - } - - public void loadFromNBT(@Nonnull NBTTagCompound logicNBT) { - calculatedEut = logicNBT.getLong("eutConsumption"); - duration = logicNBT.getInteger("duration"); - progress = logicNBT.getInteger("progress"); - hasWork = logicNBT.getBoolean("hasWork"); - if (logicNBT.hasKey("itemOutputs")) { - NBTTagList itemOutputsNBT = logicNBT.getTagList("itemOutputs", TAG_COMPOUND); - outputItems = new ItemStack[itemOutputsNBT.tagCount()]; - for (int i = 0; i < itemOutputsNBT.tagCount(); i++) { - outputItems[i] = GTUtility.loadItem(itemOutputsNBT.getCompoundTagAt(i)); - } - } - if (logicNBT.hasKey("fluidOutputs")) { - NBTTagList fluidOutputsNBT = logicNBT.getTagList("fluidOutputs", TAG_COMPOUND); - outputFluids = new FluidStack[fluidOutputsNBT.tagCount()]; - for (int i = 0; i < fluidOutputsNBT.tagCount(); i++) { - outputFluids[i] = FluidStack.loadFluidStackFromNBT(fluidOutputsNBT.getCompoundTagAt(i)); - } - } - if (logicNBT.hasKey("itemOutputID")) { - itemOutputID = UUID.fromString(logicNBT.getString("itemOutputID")); - } - if (logicNBT.hasKey("fluidOutputID")) { - fluidOutputID = UUID.fromString(logicNBT.getString("fluidOutputID")); - } - } - - /** - * Returns a gui part, which will be displayed in a separate tab on the machine's gui. - */ - @Nonnull - public Widget getGUIPart(ModularWindow.Builder builder) { - return new Scrollable(); - } - - // #endregion -} diff --git a/src/main/java/gregtech/api/logic/NullPowerLogic.java b/src/main/java/gregtech/api/logic/NullPowerLogic.java deleted file mode 100644 index 0017f0e6473..00000000000 --- a/src/main/java/gregtech/api/logic/NullPowerLogic.java +++ /dev/null @@ -1,5 +0,0 @@ -package gregtech.api.logic; - -public class NullPowerLogic extends PowerLogic { - -} diff --git a/src/main/java/gregtech/api/logic/PowerLogic.java b/src/main/java/gregtech/api/logic/PowerLogic.java deleted file mode 100644 index 52fc762d1b9..00000000000 --- a/src/main/java/gregtech/api/logic/PowerLogic.java +++ /dev/null @@ -1,254 +0,0 @@ -package gregtech.api.logic; - -import static gregtech.common.misc.WirelessNetworkManager.addEUToGlobalEnergyMap; - -import java.util.UUID; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; - -import gregtech.api.enums.GTValues.NBT; - -/** - * Power logic for machines. This is used to store all the important variables for a machine to have energy and use it - * in any way. - * - * @author BlueWeabo, Maxim - */ -public class PowerLogic { - - public static final int NONE = 0; - public static final int RECEIVER = 1; - public static final int EMITTER = 2; - public static final int BOTH = RECEIVER | EMITTER; - private static final float wirelessChargeFactor = 0.5F; - private long storedEnergy = 0; - private long energyCapacity = 0; - private long voltage = 0; - private long amperage = 0; - private int type = 0; - private boolean canUseLaser = false; - private boolean canUseWireless = false; - private UUID owner; - - public PowerLogic() {} - - /** - * Sets the max voltage the logic can accept - */ - @Nonnull - public PowerLogic setMaxVoltage(long voltage) { - this.voltage = voltage; - return this; - } - - /** - * Sets the maximum amount of energy the machine can store inside of it - */ - @Nonnull - public PowerLogic setEnergyCapacity(long energyCapacity) { - this.energyCapacity = energyCapacity; - return this; - } - - /** - * Sets the maximum amount of amps a machine can receive from an emitter - */ - @Nonnull - public PowerLogic setMaxAmperage(long amperage) { - this.amperage = amperage; - return this; - } - - /** - * Sets the type of power logic this is. Whether it will receive EU or emit it to others, or do both - */ - @Nonnull - public PowerLogic setType(int type) { - this.type = type; - return this; - } - - /** - * If this power logic can use lasers to be used for it - */ - @Nonnull - public PowerLogic setCanUseLaser(boolean canUse) { - canUseLaser = canUse; - return this; - } - - /** - * If the power logic should use wireless EU first before using its internal buffer - */ - @Nonnull - public PowerLogic setCanUseWireless(boolean canUse, UUID owner) { - canUseWireless = canUse; - this.owner = owner; - return this; - } - - /** - * Adding energy directly to the buffer, but only if it has the capacity. - */ - public boolean addEnergyUnsafe(long totalEUAdded) { - if (storedEnergy + totalEUAdded >= energyCapacity) { - return false; - } - - storedEnergy += totalEUAdded; - return true; - } - - /** - * Adding energy to the buffer if the voltage given isn't higher than the voltage of the logic - */ - public boolean addEnergy(long voltage, long amperage) { - if (voltage > this.voltage) { - return false; - } - - return addEnergyUnsafe(voltage * amperage); - } - - /** - * Same as {@link #addEnergy(long, long)}, but only 1 amp of it - */ - public boolean addEnergy(long voltage) { - return addEnergy(voltage, 1); - } - - /** - * Injecting energy in the multiblock ampere per ampere until full or until we have added the maximum possible - * amperes for this tick - * - * @param voltage At what voltage are the amps? - * @param availableAmperage How much amperage do we have available - * @return Amount of amperes used - */ - public long injectEnergy(long voltage, long availableAmperage) { - if (canUseWireless) return 0; - long usedAmperes = 0; - while (addEnergy(voltage, 1) && usedAmperes < amperage) { - usedAmperes++; - } - - return usedAmperes; - } - - /** - * Remove energy from the logic only if it has enough to be removed. - */ - public boolean removeEnergyUnsafe(long totalEURemoved) { - if (canUseWireless) { - if (storedEnergy < energyCapacity * wirelessChargeFactor) { - if (addEUToGlobalEnergyMap(owner, -(energyCapacity - storedEnergy))) { - storedEnergy = energyCapacity; - } - } - } - if (storedEnergy - totalEURemoved < 0) { - return false; - } - - storedEnergy -= totalEURemoved; - return true; - } - - /** - * Remove the given voltage for the amount of amperage if the removed isn't higher than the logic's voltage - */ - public boolean removeEnergy(long voltage, long amperage) { - if (voltage > this.voltage) { - return false; - } - - return removeEnergyUnsafe(voltage * amperage); - } - - /** - * Same as {@link #removeEnergy(long, long)}, but with only 1 amperage - */ - public boolean removeEnergy(long voltage) { - return removeEnergy(voltage, 1); - } - - /** - * @return The maximum energy that can be stored. - */ - public long getCapacity() { - return energyCapacity; - } - - /** - * @return The maximum voltage that is available - */ - public long getVoltage() { - return voltage; - } - - /** - * @return The current energy stored - */ - public long getStoredEnergy() { - return storedEnergy; - } - - /** - * @return The current maximum Amperage - */ - public long getMaxAmperage() { - return amperage; - } - - /** - * Is the logic a receiver to receive energy - */ - public boolean isEnergyReceiver() { - return (type & RECEIVER) > 0; - } - - /** - * Is the logic a emitter to emit energy - */ - public boolean isEnergyEmitter() { - return (type & EMITTER) > 0; - } - - /** - * Saves the power logic to its own nbt tag before saving it to the given one. - * - * @param nbt Tag where you want to save the power logic tag to. - */ - public void saveToNBT(NBTTagCompound nbt) { - NBTTagCompound powerLogic = new NBTTagCompound(); - powerLogic.setLong(NBT.POWER_LOGIC_ENERGY_CAPACITY, energyCapacity); - powerLogic.setLong(NBT.POWER_LOGIC_STORED_ENERGY, storedEnergy); - powerLogic.setLong(NBT.POWER_LOGIC_AMPERAGE, amperage); - powerLogic.setLong(NBT.POWER_LOGIC_VOLTAGE, voltage); - powerLogic.setInteger(NBT.POWER_LOGIC_TYPE, type); - nbt.setTag(NBT.POWER_LOGIC, powerLogic); - } - - /** - * Loads the power logic from its own nbt after getting it from the given one - * - * @param nbt Tag where the power logic tag was saved to - */ - public void loadFromNBT(NBTTagCompound nbt) { - NBTTagCompound powerLogic = nbt.getCompoundTag(NBT.POWER_LOGIC); - energyCapacity = powerLogic.getLong(NBT.POWER_LOGIC_ENERGY_CAPACITY); - storedEnergy = powerLogic.getLong(NBT.POWER_LOGIC_STORED_ENERGY); - amperage = powerLogic.getLong(NBT.POWER_LOGIC_AMPERAGE); - voltage = powerLogic.getLong(NBT.POWER_LOGIC_VOLTAGE); - type = powerLogic.getInteger(NBT.POWER_LOGIC_TYPE); - } - - /** - * Can we use lasers for inputting EU - */ - public boolean canUseLaser() { - return canUseLaser; - } -} diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 3a381ee2041..18807bdb8ab 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -14,6 +15,7 @@ import net.minecraftforge.fluids.FluidStack; import gregtech.api.interfaces.tileentity.IRecipeLockable; +import gregtech.api.interfaces.tileentity.IVoidable; import gregtech.api.objects.GTDualInputs; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; @@ -28,89 +30,244 @@ * Logic class to calculate result of recipe check from inputs, based on recipemap. */ @SuppressWarnings({ "unused", "UnusedReturnValue" }) -public class ProcessingLogic extends AbstractProcessingLogic { +public class ProcessingLogic { + // Traits + protected IVoidable machine; protected IRecipeLockable recipeLockableMachine; - protected ItemStack specialSlotItem; + protected boolean isRecipeLocked; protected ItemStack[] inputItems; protected FluidStack[] inputFluids; - protected boolean isRecipeLocked; + protected ItemStack specialSlotItem; protected IDualInputInventory craftingPattern; + protected int maxParallel = 1; + protected Supplier maxParallelSupplier; + protected int batchSize = 1; + protected Supplier> recipeMapSupplier; + protected double euModifier = 1.0; + protected double speedBoost = 1.0; + protected long availableVoltage; + protected long availableAmperage; + protected boolean protectItems; + protected boolean protectFluids; + protected double overClockTimeReduction = 2.0; + protected double overClockPowerIncrease = 4.0; + protected boolean amperageOC = true; + + // Calculated results + protected ItemStack[] outputItems; + protected FluidStack[] outputFluids; + protected long calculatedEut; + protected int duration; + protected int calculatedParallels = 0; + + // Cache + protected RecipeMap lastRecipeMap; + protected GTRecipe lastRecipe; protected Map> craftingPatternRecipeCache = new HashMap<>(); public ProcessingLogic() {} - // #region Setters + // region Setters + + /** + * Sets machine used for void protection logic. + */ + public ProcessingLogic setMachine(IVoidable machine) { + this.machine = machine; + return this; + } + + /** + * Enables single recipe locking mode. + */ + public ProcessingLogic setRecipeLocking(IRecipeLockable recipeLockableMachine, boolean isRecipeLocked) { + this.recipeLockableMachine = recipeLockableMachine; + this.isRecipeLocked = isRecipeLocked; + return this; + } @Nonnull public ProcessingLogic setInputItems(ItemStack... itemInputs) { this.inputItems = itemInputs; - return getThis(); + return this; } @Nonnull public ProcessingLogic setInputItems(List itemOutputs) { this.inputItems = itemOutputs.toArray(new ItemStack[0]); - return getThis(); + return this; } @Nonnull public ProcessingLogic setInputFluids(FluidStack... fluidInputs) { this.inputFluids = fluidInputs; - return getThis(); + return this; } @Nonnull public ProcessingLogic setInputFluids(List fluidInputs) { this.inputFluids = fluidInputs.toArray(new FluidStack[0]); - return getThis(); + return this; } public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { this.specialSlotItem = specialSlotItem; - return getThis(); + return this; } public boolean craftingPatternHandler(IDualInputInventory slot) { - if (needWipeCraftingPatternRecipeCache) { - craftingPatternRecipeCache.clear(); - needWipeCraftingPatternRecipeCache = false; + if (craftingPatternRecipeCache.containsKey(slot)) { + craftingPattern = slot; + return true; } - if (craftingPatternRecipeCache.containsKey(slot)) { + GTDualInputs inputs = slot.getPatternInputs(); + setInputItems(inputs.inputItems); + setInputFluids(inputs.inputFluid); + Set recipes = findRecipeMatches(getCurrentRecipeMap()).collect(Collectors.toSet()); + if (!recipes.isEmpty()) { + craftingPatternRecipeCache.put(slot, recipes); craftingPattern = slot; return true; - } else { - GTDualInputs inputs = slot.getPatternInputs(); - setInputItems(inputs.inputItems); - setInputFluids(inputs.inputFluid); - Set recipes = findRecipeMatches(preProcess()).collect(Collectors.toSet()); - if (!recipes.isEmpty()) { - craftingPatternRecipeCache.put(slot, recipes); - craftingPattern = slot; - return true; - } - return false; } + return false; } - public void removeEntryCraftingPatternRecipeCache(IDualInputInventory slot) { + public void clearCraftingPatternRecipeCache(IDualInputInventory slot) { craftingPatternRecipeCache.remove(slot); } /** - * Enables single recipe locking mode. + * Sets max amount of parallel. */ - public ProcessingLogic setRecipeLocking(IRecipeLockable recipeLockableMachine, boolean isRecipeLocked) { - this.recipeLockableMachine = recipeLockableMachine; - this.isRecipeLocked = isRecipeLocked; - return getThis(); + public ProcessingLogic setMaxParallel(int maxParallel) { + this.maxParallel = maxParallel; + return this; } /** - * Clears calculated results and provided machine inputs to prepare for the next machine operation. + * Sets method to get max amount of parallel. */ + public ProcessingLogic setMaxParallelSupplier(Supplier supplier) { + this.maxParallelSupplier = supplier; + return this; + } + + /** + * Sets batch size for batch mode. + */ + public ProcessingLogic setBatchSize(int size) { + this.batchSize = size; + return this; + } + + public ProcessingLogic setRecipeMap(RecipeMap recipeMap) { + return setRecipeMapSupplier(() -> recipeMap); + } + + public ProcessingLogic setRecipeMapSupplier(Supplier> supplier) { + this.recipeMapSupplier = supplier; + return this; + } + public ProcessingLogic setEuModifier(double modifier) { + this.euModifier = modifier; + return this; + } + + public ProcessingLogic setSpeedBonus(double speedModifier) { + this.speedBoost = speedModifier; + return this; + } + + /** + * Sets voltage of the machine. It doesn't need to be actual voltage (excluding amperage) of the machine; + * For example, most of the multiblock machines set maximum possible input power (including amperage) as voltage + * and 1 as amperage. That way recipemap search will be executed with overclocked voltage. + */ + public ProcessingLogic setAvailableVoltage(long voltage) { + this.availableVoltage = voltage; + return this; + } + + /** + * Sets amperage of the machine. This amperage doesn't involve in EU/t when searching recipemap. + * Useful for preventing tier skip but still considering amperage for parallel. + */ + public ProcessingLogic setAvailableAmperage(long amperage) { + this.availableAmperage = amperage; + return this; + } + + public ProcessingLogic setVoidProtection(boolean protectItems, boolean protectFluids) { + this.protectItems = protectItems; + this.protectFluids = protectFluids; + return this; + } + + public ProcessingLogic setOverclock(double timeReduction, double powerIncrease) { + this.overClockTimeReduction = timeReduction; + this.overClockPowerIncrease = powerIncrease; + return this; + } + + /** + * Sets overclock ratio to 4/4. + */ + public ProcessingLogic enablePerfectOverclock() { + return this.setOverclock(4.0, 4.0); + } + + /** + * Sets whether the multi should use amperage to OC or not. + */ + public ProcessingLogic setAmperageOC(boolean amperageOC) { + this.amperageOC = amperageOC; + return this; + } + + // endregion + + // region Overwrite calculated result + + /** + * Overwrites calculated item output. + */ + public ProcessingLogic overwriteOutputItems(ItemStack... itemOutputs) { + this.outputItems = itemOutputs; + return this; + } + + /** + * Overwrites calculated fluid output. + */ + public ProcessingLogic overwriteOutputFluids(FluidStack... fluidOutputs) { + this.outputFluids = fluidOutputs; + return this; + } + + /** + * Overwrites calculated EU/t. + */ + public ProcessingLogic overwriteCalculatedEut(long calculatedEut) { + this.calculatedEut = calculatedEut; + return this; + } + + /** + * Overwrites calculated duration. + */ + public ProcessingLogic overwriteCalculatedDuration(int duration) { + this.duration = duration; + return this; + } + + // endregion + + /** + * Clears calculated results and provided machine inputs to prepare for the next machine operation. + */ public ProcessingLogic clear() { this.inputItems = null; this.inputFluids = null; @@ -121,19 +278,43 @@ public ProcessingLogic clear() { this.duration = 0; this.calculatedParallels = 0; this.craftingPattern = null; - return getThis(); + return this; } - // #endregion + // region Logic - // #region Logic + /** + * Refreshes recipemap to use. Remember to call this before {@link #process} to make sure correct recipemap is used. + * + * @return Recipemap to use now + */ + protected RecipeMap getCurrentRecipeMap() { + RecipeMap recipeMap; + if (recipeMapSupplier == null) { + recipeMap = null; + } else { + recipeMap = recipeMapSupplier.get(); + } + if (lastRecipeMap != recipeMap) { + if (lastRecipeMap != null) { + craftingPatternRecipeCache.clear(); + } + lastRecipe = null; + lastRecipeMap = recipeMap; + } + return recipeMap; + } /** * Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs. */ @Nonnull public CheckRecipeResult process() { - RecipeMap recipeMap = preProcess(); + RecipeMap recipeMap = getCurrentRecipeMap(); + + if (maxParallelSupplier != null) { + maxParallel = maxParallelSupplier.get(); + } if (inputItems == null) { inputItems = new ItemStack[0]; @@ -210,6 +391,54 @@ private CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { return CalculationResult.ofSuccess(applyRecipe(recipe, helper, calculator, result)); } + /** + * Check has been succeeded, so it applies the recipe and calculated parameters. + * At this point, inputs have been already consumed. + */ + @Nonnull + private CheckRecipeResult applyRecipe(@Nonnull GTRecipe recipe, @Nonnull ParallelHelper helper, + @Nonnull OverclockCalculator calculator, @Nonnull CheckRecipeResult result) { + if (recipe.mCanBeBuffered) { + lastRecipe = recipe; + } else { + lastRecipe = null; + } + calculatedParallels = helper.getCurrentParallel(); + + if (calculator.getConsumption() == Long.MAX_VALUE) { + return CheckRecipeResultRegistry.POWER_OVERFLOW; + } + if (calculator.getDuration() == Integer.MAX_VALUE) { + return CheckRecipeResultRegistry.DURATION_OVERFLOW; + } + + calculatedEut = calculator.getConsumption(); + + double finalDuration = calculateDuration(recipe, helper, calculator); + if (finalDuration >= Integer.MAX_VALUE) { + return CheckRecipeResultRegistry.DURATION_OVERFLOW; + } + duration = (int) finalDuration; + + CheckRecipeResult hookResult = onRecipeStart(recipe); + if (!hookResult.wasSuccessful()) { + return hookResult; + } + + outputItems = helper.getItemOutputs(); + outputFluids = helper.getFluidOutputs(); + + return result; + } + + /** + * Override to tweak final duration that will be set as a result of this logic class. + */ + protected double calculateDuration(@Nonnull GTRecipe recipe, @Nonnull ParallelHelper helper, + @Nonnull OverclockCalculator calculator) { + return calculator.getDuration() * helper.getDurationMultiplierDouble(); + } + /** * Finds a list of matched recipes. At this point no additional check to the matched recipe has been done. *

@@ -230,6 +459,14 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { .findAll(); } + /** + * Override to do additional check for found recipe if needed. + */ + @Nonnull + protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { + return CheckRecipeResultRegistry.SUCCESSFUL; + } + /** * Override to tweak parallel logic if needed. */ @@ -248,7 +485,60 @@ protected ParallelHelper createParallelHelper(@Nonnull GTRecipe recipe) { .setOutputCalculation(true); } - // #endregion + /** + * Override to tweak overclock logic if needed. + */ + @Nonnull + protected OverclockCalculator createOverclockCalculator(@Nonnull GTRecipe recipe) { + return new OverclockCalculator().setRecipeEUt(recipe.mEUt) + .setAmperage(availableAmperage) + .setEUt(availableVoltage) + .setDuration(recipe.mDuration) + .setSpeedBoost(speedBoost) + .setEUtDiscount(euModifier) + .setAmperageOC(amperageOC) + .setDurationDecreasePerOC(overClockTimeReduction) + .setEUtIncreasePerOC(overClockPowerIncrease); + } + + /** + * Override to perform additional logic when recipe starts. + *

+ * This is called when the recipe processing logic has finished all + * checks, consumed all inputs, but has not yet set the outputs to + * be produced. Returning a result other than SUCCESSFUL will void + * all inputs! + */ + @Nonnull + protected CheckRecipeResult onRecipeStart(@Nonnull GTRecipe recipe) { + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + // endregion + + // region Getters + + public ItemStack[] getOutputItems() { + return outputItems; + } + + public FluidStack[] getOutputFluids() { + return outputFluids; + } + + public int getDuration() { + return duration; + } + + public long getCalculatedEut() { + return calculatedEut; + } + + public int getCurrentParallels() { + return calculatedParallels; + } + + // endregion /** * Represents the status of check recipe calculation. {@link #successfullyConsumedInputs} does not necessarily mean diff --git a/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java deleted file mode 100644 index c12333a4c6b..00000000000 --- a/src/main/java/gregtech/api/logic/interfaces/FluidInventoryLogicHost.java +++ /dev/null @@ -1,95 +0,0 @@ -package gregtech.api.logic.interfaces; - -import static com.google.common.primitives.Ints.saturatedCast; - -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; - -import gregtech.api.enums.InventoryType; -import gregtech.api.logic.FluidInventoryLogic; - -public interface FluidInventoryLogicHost extends IFluidHandler { - - /** - * To be used for single blocks or when directly interacting with the controller - * - * @param side The side from where fluids are being inputted or extracted from - * @param type The type of inventory being accessed. For inputting its Input, For outputting its Output. - * @return The Fluid Logic responsible for said type. Can return null if the side is invalid - */ - @Nullable - FluidInventoryLogic getFluidLogic(@Nonnull ForgeDirection side, @Nonnull InventoryType type); - - /** - * Only to be used by MultiBlockPart for accessing the Controller Inventory - * - * @param type Type of inventory, is it Input or Output - * @param id ID of the locked inventory. A null id is all inventories of said controller of said type - * @return The Fluid Logic responsible for everything that should be done with said inventory - */ - @Nonnull - default FluidInventoryLogic getFluidLogic(@Nonnull InventoryType type, @Nullable UUID id) { - return Objects.requireNonNull(getFluidLogic(ForgeDirection.UNKNOWN, type)); - } - - /** - * Returns an empty set if the type is {@link InventoryType#Both} or when the machine isn't a controller. - */ - @Nonnull - default Set> getAllFluidInventoryLogics(@Nonnull InventoryType type) { - return new HashSet<>(); - } - - @Override - default boolean canDrain(@Nonnull ForgeDirection from, Fluid fluid) { - FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); - return logic != null; - } - - @Override - default boolean canFill(@Nonnull ForgeDirection from, Fluid fluid) { - FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Input); - return logic != null; - } - - @Override - @Nullable - default FluidStack drain(@Nonnull ForgeDirection from, @Nonnull FluidStack resource, boolean doDrain) { - FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); - if (logic == null) return null; - return logic.drain(resource.getFluid(), resource.amount, !doDrain); - } - - @Override - @Nullable - default FluidStack drain(@Nonnull ForgeDirection from, int maxDrain, boolean doDrain) { - FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Output); - if (logic == null) return null; - return logic.drain(maxDrain, !doDrain); - } - - @Override - default int fill(@Nonnull ForgeDirection from, @Nonnull FluidStack resource, boolean doFill) { - FluidInventoryLogic logic = getFluidLogic(from, InventoryType.Input); - if (logic == null) return 0; - return saturatedCast(logic.fill(resource.getFluid(), resource.amount, !doFill)); - } - - @Override - @Nullable - default FluidTankInfo[] getTankInfo(@Nonnull ForgeDirection from) { - return null; - } -} diff --git a/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java deleted file mode 100644 index a65f3c50f19..00000000000 --- a/src/main/java/gregtech/api/logic/interfaces/ItemInventoryLogicHost.java +++ /dev/null @@ -1,172 +0,0 @@ -package gregtech.api.logic.interfaces; - -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.enums.InventoryType; -import gregtech.api.logic.ItemInventoryLogic; - -public interface ItemInventoryLogicHost extends ISidedInventory { - - /** - * To be used for single blocks or when directly interacting with the controller - * - * @param side The side from where items are being inputted or extracted from - * @param type The type of inventory being accessed. For inputting its Input, For outputting its Output. - * @return The Item Logic responsible for said type. Will return null if the side is not valid - */ - @Nullable - ItemInventoryLogic getItemLogic(@Nonnull ForgeDirection side, @Nonnull InventoryType type); - - /** - * Only to be used by MultiBlockPart for accessing the Controller Inventory - * - * @param type Type of inventory, is it Input or Output - * @param id ID of the locked inventory. A null id is all inventories of said controller of said type - * @return The Item Logic responsible for everything that should be done with said inventory - */ - @Nonnull - default ItemInventoryLogic getItemLogic(@Nonnull InventoryType type, @Nullable UUID id) { - return Objects.requireNonNull(getItemLogic(ForgeDirection.UNKNOWN, type)); - } - - /** - * Only to be used for MultiBlockPart - * - * @return - */ - @Nullable - default InventoryType getItemInventoryType() { - return null; - } - - /** - * Returns an empty set if the type is {@link InventoryType#Both} or this is used when the machine isn't a - * controller - */ - @Nonnull - default Set> getAllItemInventoryLogics(@Nonnull InventoryType type) { - return new HashSet<>(); - } - - @Override - @Nullable - default ItemStack decrStackSize(int slot, int count) { - InventoryType type = getItemInventoryType(); - if (type == InventoryType.Both) return null; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return null; - return logic.extractItem(slot, count); - } - - @Override - default int getSizeInventory() { - InventoryType type = getItemInventoryType(); - if (type == InventoryType.Both) return 0; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return 0; - return logic.getSlots(); - } - - @Override - @Nullable - default ItemStack getStackInSlot(int slot) { - InventoryType type = getItemInventoryType(); - if (type == InventoryType.Both) return null; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return null; - return logic.getInventory() - .getStackInSlot(slot); - } - - @Override - default boolean isItemValidForSlot(int slot, @Nullable ItemStack stack) { - InventoryType type = getItemInventoryType(); - if (type == InventoryType.Both) return false; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return false; - return logic.getInventory() - .isItemValid(slot, stack); - } - - @Override - default void setInventorySlotContents(int slot, @Nullable ItemStack stack) { - InventoryType type = getItemInventoryType(); - if (type == InventoryType.Both) return; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return; - logic.getInventory() - .setStackInSlot(slot, stack); - } - - @Override - default boolean canExtractItem(int ignoredSlot, ItemStack ignoredItem, int side) { - InventoryType type = getItemInventoryType(); - if (type == null) return false; - return getItemLogic(ForgeDirection.getOrientation(side), type) != null; - } - - @Override - default boolean canInsertItem(int ignoredSlot, ItemStack ignoredItem, int side) { - InventoryType type = getItemInventoryType(); - if (type == null) return false; - return getItemInventoryType() != InventoryType.Output - && getItemLogic(ForgeDirection.getOrientation(side), type) != null; - } - - @Override - default int[] getAccessibleSlotsFromSide(int side) { - InventoryType type = getItemInventoryType(); - if (type == null) return new int[0]; - ItemInventoryLogic logic = getItemLogic(ForgeDirection.UNKNOWN, type == null ? InventoryType.Output : type); - if (logic == null) return new int[0]; - int[] indexes = new int[logic.getSlots()]; - for (int i = 0; i < logic.getSlots(); i++) { - indexes[i] = i; - } - return indexes; - } - - @Override - default void closeInventory() {} - - @Override - default String getInventoryName() { - return ""; - } - - @Override - default int getInventoryStackLimit() { - return 64; - } - - @Override - default ItemStack getStackInSlotOnClosing(int index) { - return null; - } - - @Override - default boolean hasCustomInventoryName() { - return false; - } - - @Override - default boolean isUseableByPlayer(@Nonnull EntityPlayer player) { - return false; - } - - @Override - default void openInventory() {} - -} diff --git a/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java deleted file mode 100644 index 9a0afaa5397..00000000000 --- a/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java +++ /dev/null @@ -1,10 +0,0 @@ -package gregtech.api.logic.interfaces; - -import gregtech.api.logic.ModelRenderLogic; - -public interface ModelRenderLogicHost { - - ModelRenderLogic getRenderLogic(); - - boolean shouldRenderModel(); -} diff --git a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java deleted file mode 100644 index 4903d7fa231..00000000000 --- a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java +++ /dev/null @@ -1,60 +0,0 @@ -package gregtech.api.logic.interfaces; - -import java.util.Objects; - -import javax.annotation.Nonnull; - -import net.minecraftforge.common.util.ForgeDirection; - -import gregtech.api.interfaces.tileentity.IEnergyConnected; -import gregtech.api.logic.PowerLogic; - -/** - * Power logic class for one to use to enable a machine to use energy - */ -public interface PowerLogicHost { - - /** - * - * @param side Side being access to try and get the power logic from - * @return Can return NullPowerLogic if the side doesn't allow the return of the logic. That power logic is unusable - */ - @Nonnull - PowerLogic getPowerLogic(@Nonnull ForgeDirection side); - - /** - * Gives the power logic ignoring the side. - */ - @Nonnull - default PowerLogic getPowerLogic() { - return Objects.requireNonNull(getPowerLogic(ForgeDirection.UNKNOWN)); - } - - /** - * Shortcut to the method of {@link PowerLogic#isEnergyReceiver()} - */ - default boolean isEnergyReceiver() { - return getPowerLogic().isEnergyReceiver(); - } - - /** - * Shortcut to the method of {@link PowerLogic#isEnergyEmitter()} - */ - default boolean isEnergyEmitter() { - return getPowerLogic().isEnergyEmitter(); - } - - /** - * Method for emitting energy to other blocks and machines. Override when it needs to be changed. - */ - default void emitEnergyFromLogic() { - IEnergyConnected.Util.emitEnergyToNetwork(this, getPowerOutputSide()); - } - - /** - * From where does the machine output energy from? - * When the output side is {@link ForgeDirection#UNKNOWN} then it won't output energy - */ - @Nonnull - ForgeDirection getPowerOutputSide(); -} diff --git a/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java deleted file mode 100644 index 314d0d3d975..00000000000 --- a/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java +++ /dev/null @@ -1,82 +0,0 @@ -package gregtech.api.logic.interfaces; - -import javax.annotation.Nonnull; - -import gregtech.api.enums.VoidingMode; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.interfaces.tileentity.IVoidable; -import gregtech.api.logic.MuTEProcessingLogic; - -public interface ProcessingLogicHost

> - extends IVoidable, ItemInventoryLogicHost, FluidInventoryLogicHost, IMachineProgress { - - /** - * Get the processing logic for the current machine - */ - @Nonnull - P getProcessingLogic(); - - boolean isInputSeparated(); - - void setInputSeparation(Boolean inputSeparation); - - default boolean supportsInputSeparation() { - return true; - } - - default boolean getDefaultInputSeparationMode() { - return false; - } - - boolean isRecipeLockingEnabled(); - - void setRecipeLocking(Boolean recipeLocked); - - default boolean supportsSingleRecipeLocking() { - return true; - } - - default boolean getDefaultRecipeLockingMode() { - return false; - } - - default boolean supportsBatchMode() { - return true; - } - - void setBatchMode(Boolean batchMode); - - boolean isBatchModeEnabled(); - - default boolean getDefaultBatchMode() { - return false; - } - - /** - * Get what the machine can void or not - */ - @Nonnull - VoidingMode getVoidMode(); - - /** - * Called when the processing logic should be updated by {@link #needsUpdate()} - */ - default void updateProcessingLogic(@Nonnull P processingLogic) {} - - /** - * Called before the recipe check, but after any other updates - */ - default void setProcessingLogicPower(@Nonnull P processingLogic) {} - - /** - * DO NOT CALL YOURSELF!!! - *

- * If you want to make the processing logic be updated call {@link #setProcessingUpdate(boolean)} - */ - boolean needsUpdate(); - - /** - * To be called when one needs to updated the processing logic. That can be when parallel changes, ect. - */ - void setProcessingUpdate(boolean update); -} diff --git a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java index 02877d8497f..7398b7af8eb 100644 --- a/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/CoverableTileEntity.java @@ -247,8 +247,6 @@ protected void updateCoverBehavior() { @Override public void issueCoverUpdate(ForgeDirection side) { - // If we've got a null worldObj we're getting called as a part of readingNBT from a non tickable MultiTileEntity - // on chunk load before the world is set, so we'll want to send a cover update. final CoverInfo coverInfo = getCoverInfoAtSide(side); if (worldObj == null || (isServerSide() && coverInfo.isDataNeededOnClient())) coverInfo.setNeedsUpdate(true); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTECable.java b/src/main/java/gregtech/api/metatileentity/implementations/MTECable.java index ef1a3fe96b2..51b7a48d500 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTECable.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTECable.java @@ -44,7 +44,6 @@ import gregtech.api.interfaces.tileentity.ICoverable; import gregtech.api.interfaces.tileentity.IEnergyConnected; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.objects.GTCoverNone; @@ -339,10 +338,9 @@ public boolean canConnect(ForgeDirection side, TileEntity tileEntity) { final ForgeDirection oppositeSide = side.getOpposite(); // GT Machine handling - if ((tileEntity instanceof PowerLogicHost powerLogic && powerLogic.getPowerLogic(oppositeSide) != null) - || ((tileEntity instanceof IEnergyConnected energyConnected) - && (energyConnected.inputEnergyFrom(oppositeSide, false) - || energyConnected.outputsEnergyTo(oppositeSide, false)))) + if (((tileEntity instanceof IEnergyConnected energyConnected) + && (energyConnected.inputEnergyFrom(oppositeSide, false) + || energyConnected.outputsEnergyTo(oppositeSide, false)))) return true; // Solar Panel Compat diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 755b023b24b..5210c567df3 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -907,6 +907,11 @@ protected CheckRecipeResult doCheckRecipe() { } } + result = checkRecipeForCustomHatches(result); + if (result.wasSuccessful()) { + return result; + } + processingLogic.setInputFluids(getStoredFluids()); if (isInputSeparationEnabled()) { @@ -934,7 +939,7 @@ protected CheckRecipeResult doCheckRecipe() { if (canUseControllerSlotForRecipe() && getControllerSlot() != null) { inputItems.add(getControllerSlot()); } - processingLogic.setInputItems(inputItems.toArray(new ItemStack[0])); + processingLogic.setInputItems(inputItems); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { return foundResult; @@ -963,6 +968,18 @@ protected CheckRecipeResult doCheckRecipe() { return result; } + /** + * Override to perform additional checkRecipe logic. It gets called after CRIBs and before ordinal hatches. + * + * @param lastResult Last result of checkRecipe. It might contain interesting info about failure, so don't blindly + * overwrite it. Refer to {@link #doCheckRecipe} for how to handle it. + * @return Result of the checkRecipe. + */ + @Nonnull + protected CheckRecipeResult checkRecipeForCustomHatches(CheckRecipeResult lastResult) { + return lastResult; + } + /** * Performs additional check for {@link #processingLogic} after all the calculations are done. * As many as checks should be done inside of custom {@link ProcessingLogic}, which you can specify with diff --git a/src/main/java/gregtech/api/objects/GTHashSet.java b/src/main/java/gregtech/api/objects/GTHashSet.java index df012c05f73..fa85a9a411f 100644 --- a/src/main/java/gregtech/api/objects/GTHashSet.java +++ b/src/main/java/gregtech/api/objects/GTHashSet.java @@ -7,12 +7,14 @@ import java.util.LinkedHashMap; import java.util.Map; +import javax.annotation.Nonnull; + import net.minecraft.item.ItemStack; import gregtech.api.GregTechAPI; import gregtech.api.util.GTUtility; -public class GTHashSet extends AbstractSet { +public class GTHashSet extends AbstractSet { private static final Object OBJECT = new Object(); private final transient HashMap map; @@ -22,7 +24,7 @@ public GTHashSet() { GregTechAPI.sItemStackMappings.add(map); } - public GTHashSet(Collection c) { + public GTHashSet(Collection c) { map = new HashMap<>(Math.max((int) (c.size() / .75f) + 1, 16)); addAll(c); GregTechAPI.sItemStackMappings.add(map); @@ -47,10 +49,10 @@ public Map getMap() { return map; } - @SuppressWarnings("unchecked") // The downcasting below will throw ClassCastException unless E is GT_ItemStack. + @Nonnull @Override - public Iterator iterator() { - return (Iterator) map.keySet() + public Iterator iterator() { + return map.keySet() .iterator(); } @@ -75,7 +77,7 @@ public boolean add(ItemStack aStack) { } @Override - public boolean add(E e) { + public boolean add(GTItemStack e) { return map.put(e, OBJECT) == null; } diff --git a/src/main/java/gregtech/api/objects/GTItemStack.java b/src/main/java/gregtech/api/objects/GTItemStack.java index 3ddfcd706a2..692ee34837d 100644 --- a/src/main/java/gregtech/api/objects/GTItemStack.java +++ b/src/main/java/gregtech/api/objects/GTItemStack.java @@ -6,14 +6,13 @@ import gregtech.api.enums.GTValues; import gregtech.api.util.GTUtility; -import gregtech.api.util.item.ItemHolder; import it.unimi.dsi.fastutil.Hash; /** * An optimization of {@link ItemStack} to have a better {@code hashcode} and {@code equals} in order to improve * {@code HashMap} and {@code Set} performance */ -public class GTItemStack extends ItemHolder { +public class GTItemStack { /** * A better {@link Hash.Strategy} for {@link ItemStack}. Implementation originally from {@code GT_ItemStack2}. @@ -39,7 +38,6 @@ public boolean equals(ItemStack a, ItemStack b) { public final short mMetaData; public GTItemStack(Item aItem, long aStackSize, long aMetaData) { - super(new ItemStack(aItem, 1, (int) aMetaData)); mItem = aItem; mStackSize = (byte) aStackSize; mMetaData = (short) aMetaData; diff --git a/src/main/java/gregtech/api/objects/GTItemStack2.java b/src/main/java/gregtech/api/objects/GTItemStack2.java deleted file mode 100644 index 798915d8489..00000000000 --- a/src/main/java/gregtech/api/objects/GTItemStack2.java +++ /dev/null @@ -1,41 +0,0 @@ -package gregtech.api.objects; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -/** - * GT_ItemStack, but with a better hashCode(). Due to this change, it should not be placed in the same hash based data - * structure with GT_ItemStack. It also shouldn't be used to construct search query into a hash based data structure - * that contains GT_ItemStack. - * - * @deprecated See {@link GTItemStack#ITEMSTACK_HASH_STRATEGY2} - */ -@Deprecated -public class GTItemStack2 extends GTItemStack { - - public GTItemStack2(Item aItem, long aStackSize, long aMetaData) { - super(aItem, aStackSize, aMetaData); - } - - public GTItemStack2(ItemStack aStack) { - super(aStack); - } - - public GTItemStack2(ItemStack aStack, boolean wildcard) { - super(aStack, wildcard); - } - - @Override - public boolean equals(Object aStack) { - if (aStack == this) return true; - if (aStack instanceof GTItemStack) { - return ((GTItemStack) aStack).mItem == mItem && ((GTItemStack) aStack).mMetaData == mMetaData; - } - return false; - } - - @Override - public int hashCode() { - return mItem.hashCode() * 38197 + mMetaData; - } -} diff --git a/src/main/java/gregtech/api/task/TaskHost.java b/src/main/java/gregtech/api/task/TaskHost.java deleted file mode 100644 index d6377949c16..00000000000 --- a/src/main/java/gregtech/api/task/TaskHost.java +++ /dev/null @@ -1,18 +0,0 @@ -package gregtech.api.task; - -import javax.annotation.Nonnull; - -import org.jetbrains.annotations.ApiStatus; - -/** - * Classes implementing this interface can have {@link TickableTask} to run. Tasks with conflicting name should not be - * allowed, to prevent them from overwriting others' NBT load/save. - */ -public interface TaskHost { - - /** - * This method should be called ONLY by {@link TickableTask} constructor. - */ - @ApiStatus.OverrideOnly - void registerTask(@Nonnull TickableTask task); -} diff --git a/src/main/java/gregtech/api/task/TickableTask.java b/src/main/java/gregtech/api/task/TickableTask.java deleted file mode 100644 index 3bbeb216e7c..00000000000 --- a/src/main/java/gregtech/api/task/TickableTask.java +++ /dev/null @@ -1,48 +0,0 @@ -package gregtech.api.task; - -import javax.annotation.Nonnull; - -import net.minecraft.nbt.NBTTagCompound; - -/** - * This class aims at separating logic run on {@link TaskHost}, rather than using interface layers. - * It has two main functionalities: Run tick and Save/Load. - * - * @param Type of the host - */ -public abstract class TickableTask { - - @Nonnull - protected final T taskHost; - - public TickableTask(@Nonnull T taskHost) { - this.taskHost = taskHost; - taskHost.registerTask(this); - } - - /** - * @return Name of this task. Tasks with conflicting name cannot be registered to the same machine. - */ - @Nonnull - public abstract String getName(); - - /** - * Called once per world tick. - */ - public abstract void update(long tick, boolean isServerSide); - - /** - * Save info to NBT. - */ - public void writeToNBT(@Nonnull NBTTagCompound nbt) {} - - /** - * Read info from NBT. - */ - public void readFromNBT(@Nonnull NBTTagCompound nbt) {} - - @Override - public String toString() { - return "TickableTask{" + "name=" + getName() + ", taskHost=" + taskHost + "}"; - } -} diff --git a/src/main/java/gregtech/api/task/tasks/PollutionTask.java b/src/main/java/gregtech/api/task/tasks/PollutionTask.java deleted file mode 100644 index c8c9705e6c7..00000000000 --- a/src/main/java/gregtech/api/task/tasks/PollutionTask.java +++ /dev/null @@ -1,45 +0,0 @@ -package gregtech.api.task.tasks; - -import javax.annotation.Nonnull; - -import net.minecraft.tileentity.TileEntity; - -import gregtech.api.enums.TickTime; -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.task.TaskHost; -import gregtech.api.task.TickableTask; -import gregtech.common.pollution.Pollution; - -public class PollutionTask extends TickableTask { - - private int pollutionPerSecond; - private static final int POLLUTION_TICK = TickTime.SECOND; - - public PollutionTask(@Nonnull T taskHost) { - super(taskHost); - } - - public PollutionTask setPollutionPerSecond(int pollutionPerSecond) { - this.pollutionPerSecond = pollutionPerSecond; - return this; - } - - public int getPollutionPerSecond() { - return pollutionPerSecond; - } - - @Nonnull - @Override - public String getName() { - return "pollution"; - } - - @Override - public void update(long tick, boolean isServerSide) { - if (isServerSide && tick % POLLUTION_TICK == 0 && taskHost.hasThingsToDo()) { - if (taskHost instanceof final TileEntity entity) { - Pollution.addPollution(entity, getPollutionPerSecond()); - } - } - } -} diff --git a/src/main/java/gregtech/api/task/tasks/PowerOutputTask.java b/src/main/java/gregtech/api/task/tasks/PowerOutputTask.java deleted file mode 100644 index ef800635fb1..00000000000 --- a/src/main/java/gregtech/api/task/tasks/PowerOutputTask.java +++ /dev/null @@ -1,32 +0,0 @@ -package gregtech.api.task.tasks; - -import javax.annotation.Nonnull; - -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.logic.interfaces.PowerLogicHost; -import gregtech.api.task.TaskHost; -import gregtech.api.task.TickableTask; - -public class PowerOutputTask extends TickableTask { - - private static final String NAME = "powerOutput"; - - public PowerOutputTask(@Nonnull T taskHost) { - super(taskHost); - } - - @Override - @Nonnull - public String getName() { - return NAME; - } - - @Override - public void update(long tick, boolean isServerSide) { - if (!isServerSide) return; - if (!taskHost.isActive()) return; - if (!taskHost.isEnergyEmitter()) return; - taskHost.emitEnergyFromLogic(); - } - -} diff --git a/src/main/java/gregtech/api/task/tasks/ProcessingTask.java b/src/main/java/gregtech/api/task/tasks/ProcessingTask.java deleted file mode 100644 index 410c8d7a6f6..00000000000 --- a/src/main/java/gregtech/api/task/tasks/ProcessingTask.java +++ /dev/null @@ -1,51 +0,0 @@ -package gregtech.api.task.tasks; - -import javax.annotation.Nonnull; - -import gregtech.api.interfaces.tileentity.IMachineProgress; -import gregtech.api.logic.MuTEProcessingLogic; -import gregtech.api.logic.interfaces.ProcessingLogicHost; -import gregtech.api.task.TaskHost; -import gregtech.api.task.TickableTask; - -public class ProcessingTask & IMachineProgress, P extends MuTEProcessingLogic

> - extends TickableTask { - - public ProcessingTask(@Nonnull T taskHost) { - super(taskHost); - } - - private static final String NAME = "processing"; - - @Override - @Nonnull - public String getName() { - return NAME; - } - - @Override - public void update(long tick, boolean isServerSide) { - if (!isServerSide) return; - if (!taskHost.isAllowedToWork()) return; - final P logic = taskHost.getProcessingLogic(); - if (taskHost.needsUpdate()) { - taskHost.updateProcessingLogic(logic); - taskHost.setProcessingUpdate(false); - } - if (logic.canWork() && tick % 100 == 0) { - taskHost.setProcessingLogicPower(logic); - logic.startCheck(); - if (logic.getResult() - .wasSuccessful()) { - taskHost.setActive(true); - } - } - - if (taskHost.hasThingsToDo()) { - logic.progress(); - } else { - taskHost.setActive(false); - } - } - -} diff --git a/src/main/java/gregtech/api/util/GTModHandler.java b/src/main/java/gregtech/api/util/GTModHandler.java index a564af1ffb0..ab6ec46658a 100644 --- a/src/main/java/gregtech/api/util/GTModHandler.java +++ b/src/main/java/gregtech/api/util/GTModHandler.java @@ -102,7 +102,7 @@ public class GTModHandler { private static final List delayedRemovalByRecipe = new ArrayList<>(); public static Collection sNativeRecipeClasses = new HashSet<>(), sSpecialRecipeClasses = new HashSet<>(); - public static GTHashSet sNonReplaceableItems = new GTHashSet<>(); + public static GTHashSet sNonReplaceableItems = new GTHashSet(); public static Object sBoxableWrapper = new GTIBoxableWrapper(); public static Collection sBoxableItems = new ArrayList<>(); private static final Map emptyRecipeMap = new HashMap<>(); diff --git a/src/main/java/gregtech/api/util/GTRecipe.java b/src/main/java/gregtech/api/util/GTRecipe.java index ce17f693331..329816c6c5c 100644 --- a/src/main/java/gregtech/api/util/GTRecipe.java +++ b/src/main/java/gregtech/api/util/GTRecipe.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -26,8 +25,6 @@ import gregtech.api.GregTechAPI; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; -import gregtech.api.logic.FluidInventoryLogic; -import gregtech.api.logic.ItemInventoryLogic; import gregtech.api.metatileentity.implementations.MTEHatchInput; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.metatileentity.implementations.MTEHatchMultiInput; @@ -40,7 +37,6 @@ import gregtech.api.recipe.metadata.EmptyRecipeMetadataStorage; import gregtech.api.recipe.metadata.IRecipeMetadataStorage; import gregtech.api.util.extensions.ArrayExt; -import gregtech.api.util.item.ItemHolder; import gregtech.common.tileentities.machines.MTEHatchInputBusME; import gregtech.common.tileentities.machines.MTEHatchInputME; import gregtech.nei.GTNEIDefaultHandler; @@ -687,60 +683,6 @@ private static boolean shouldCheckNBT(ItemStack item) { return false; } - public boolean isRecipePossible(@Nullable ItemInventoryLogic itemInput, @Nullable FluidInventoryLogic fluidInput) { - return getAmountOfRecipesDone(itemInput, fluidInput, 1, true) > 0; - } - - public long getAmountOfRecipesDone(@Nullable ItemInventoryLogic itemInput, @Nullable FluidInventoryLogic fluidInput, - long maxParallel, boolean simulate) { - if (itemInput == null) { - itemInput = new ItemInventoryLogic(0); - } - - if (fluidInput == null) { - fluidInput = new FluidInventoryLogic(0, 0); - } - - itemInput.startRecipeCheck(); - Map recipeItems = getItemInputsAsItemMap(); - for (Entry entry : recipeItems.entrySet()) { - maxParallel = Math - .min(maxParallel, itemInput.calculateAmountOfTimesItemCanBeTaken(entry.getKey(), entry.getValue())); - } - - for (FluidStack fluid : mFluidInputs) { - if (fluid == null) continue; - maxParallel = Math - .min(maxParallel, fluidInput.calculateAmountOfTimesFluidCanBeTaken(fluid.getFluid(), fluid.amount)); - } - - if (simulate) { - itemInput.stopRecipeCheck(); - return maxParallel; - } - - for (Entry entry : recipeItems.entrySet()) { - itemInput.subtractItemAmount(entry.getKey(), entry.getValue() * maxParallel, false); - } - - for (FluidStack fluid : mFluidInputs) { - if (fluid == null) continue; - fluidInput.drain(fluid.getFluid(), fluid.amount * maxParallel, false); - } - itemInput.stopRecipeCheck(); - return maxParallel; - } - - private Map getItemInputsAsItemMap() { - Map items = new HashMap<>(); - for (ItemStack item : mInputs) { - if (item == null) continue; - ItemHolder itemHolder = new ItemHolder(item); - items.put(itemHolder, items.getOrDefault(itemHolder, 0L) + item.stackSize); - } - return items; - } - @Override public int compareTo(GTRecipe recipe) { // first lowest tier recipes diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java index fbaa3357d73..8098c372fd4 100644 --- a/src/main/java/gregtech/api/util/GTUtility.java +++ b/src/main/java/gregtech/api/util/GTUtility.java @@ -164,7 +164,6 @@ import gregtech.api.net.GTPacketSound; import gregtech.api.objects.CollectorUtils; import gregtech.api.objects.GTItemStack; -import gregtech.api.objects.GTItemStack2; import gregtech.api.objects.ItemData; import gregtech.api.recipe.RecipeMaps; import gregtech.api.threads.RunnableSound; @@ -3019,23 +3018,11 @@ public static boolean isStackInList(ItemStack aStack, Collection aL return isStackInList(new GTItemStack(aStack), aList); } - public static boolean isStackInList(ItemStack aStack, Set aList) { - if (aStack == null) { - return false; - } - return isStackInList(new GTItemStack2(aStack), aList); - } - public static boolean isStackInList(GTItemStack aStack, Collection aList) { return aStack != null && (aList.contains(aStack) || aList.contains(new GTItemStack(aStack.mItem, aStack.mStackSize, W))); } - public static boolean isStackInList(GTItemStack2 aStack, Set aList) { - return aStack != null - && (aList.contains(aStack) || aList.contains(new GTItemStack2(aStack.mItem, aStack.mStackSize, W))); - } - /** * re-maps all Keys of a Map after the Keys were weakened. */ diff --git a/src/main/java/gregtech/api/util/ParallelHelper.java b/src/main/java/gregtech/api/util/ParallelHelper.java index de08a594721..99e7cac569f 100644 --- a/src/main/java/gregtech/api/util/ParallelHelper.java +++ b/src/main/java/gregtech/api/util/ParallelHelper.java @@ -13,8 +13,6 @@ import gregtech.api.interfaces.tileentity.IRecipeLockable; import gregtech.api.interfaces.tileentity.IVoidable; -import gregtech.api.logic.FluidInventoryLogic; -import gregtech.api.logic.ItemInventoryLogic; import gregtech.api.objects.XSTR; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; @@ -62,14 +60,6 @@ public class ParallelHelper { * The inputs of the multiblock for the current recipe check */ private ItemStack[] itemInputs; - /** - * The inputs of the machine for current recipe check - */ - private ItemInventoryLogic itemInputInventory; - /** - * The output item inventory of the machine - */ - private ItemInventoryLogic itemOutputInventory; /** * The outputs of the recipe with the applied parallel */ @@ -78,14 +68,6 @@ public class ParallelHelper { * The inputs of the multiblock for the current recipe check */ private FluidStack[] fluidInputs; - /** - * The inputs of the machine for the current recipe check - */ - private FluidInventoryLogic fluidInputInventory; - /** - * The output fluid inventory of the machine; - */ - private FluidInventoryLogic fluidOutputInventory; /** * The outputs of the recipe with the applied parallel */ @@ -150,12 +132,6 @@ public class ParallelHelper { private Function customFluidOutputCalculation; - /** - * MuTE Mode this is a mode for changing how the GT_ParallelHelper works as Mutes don't use ItemStack and FluidStack - * arrays for inputs - */ - private boolean muteMode = false; - public ParallelHelper() {} /** @@ -316,24 +292,6 @@ public ParallelHelper setCustomFluidOutputCalculation(Function fluidOutputInventory.getInventory() - .getTanks()) { - return 0; - } - - // A map to hold the items we will be 'inputting' into the output hatches. These fluidstacks are actually - // the recipe outputs. - Map tFluidOutputMap = new HashMap<>(); - - // Map that keeps track of the number of parallel crafts we can accommodate for each fluid output. - // In the pair, we keep track of number of full crafts plus mb of fluid in a partial craft, to avoid - // issues with floating point math not being completely accurate when summing. - Map tParallels = new HashMap<>(); - - // Iterate over the outputs, calculating require stack spacing they will require. - for (FluidStack aY : fluidOutputs) { - if (aY == null) continue; - int fluidAmount = aY.amount * outputMultiplier; - if (fluidAmount <= 0) continue; - tFluidOutputMap.merge(aY, fluidAmount, Integer::sum); - tParallels.put(aY, new ParallelData(0, 0)); - } - - if (tFluidOutputMap.isEmpty()) { - // nothing to output, bail early - return maxParallel; - } - - for (int i = 0; i < fluidOutputInventory.getInventory() - .getTanks(); i++) { - IFluidTankLong tank = fluidOutputInventory.getInventory() - .getFluidTank(i); - long tSpaceLeft = tank.getCapacityLong() - tank.getFluidAmountLong(); - // check if hatch filled - if (tSpaceLeft <= 0) continue; - // check if hatch is empty and unrestricted - if (tank.getStoredFluid() == null) continue; - - for (Map.Entry entry : tParallels.entrySet()) { - FluidStack tFluidOutput = entry.getKey(); - if (tank.fill(tFluidOutput.getFluid(), tFluidOutput.amount, false) == tFluidOutput.amount) continue; - // this fluid is not prevented by restrictions on output hatch - ParallelData tParallel = entry.getValue(); - Integer tCraftSize = tFluidOutputMap.get(tFluidOutput); - tParallel.batch += (tParallel.partial + tSpaceLeft) / tCraftSize; - tParallel.partial = (tParallel.partial + tSpaceLeft) % tCraftSize; - } - } - // now that all partial/restricted hatches have been counted, create a priority queue for our outputs - // the lowest priority fluid is the number of complete parallel crafts we can support - PriorityQueue> aParallelQueue = new PriorityQueue<>( - Comparator.comparing(i -> i.batch)); - for (Map.Entry entry : tParallels.entrySet()) { - aParallelQueue - .add(new ParallelStackInfo<>(entry.getValue().batch, entry.getValue().partial, entry.getKey())); - } - // add extra parallels for open slots as well - for (int i = 0; i < fluidOutputInventory.getInventory() - .getTanks(); i++) { - IFluidTankLong tank = fluidOutputInventory.getInventory() - .getFluidTank(i); - // partially filled or restricted hatch. done in the last pass - if (tank.getStoredFluid() != null) continue; - - ParallelStackInfo tParallel = aParallelQueue.poll(); - assert tParallel != null; // will always be true, specifying assert here to avoid IDE/compiler warnings - Integer tCraftSize = tFluidOutputMap.get(tParallel.stack); - long tSpaceLeft = tank.getCapacityLong(); - tParallel.batch += (tParallel.partial + tSpaceLeft) / tCraftSize; - tParallel.partial = (tParallel.partial + tSpaceLeft) % tCraftSize; - aParallelQueue.add(tParallel); - } - - return aParallelQueue.element().batch; - } - /** * Calculates the max parallels one can do with items if void protection is on */ private int calculateMaxItemParallels() { - List busStacks; - - if (muteMode) { - busStacks = itemOutputInventory.getInventory() - .getStacks(); - } else { - busStacks = machine.getItemOutputSlots(itemOutputs); - } + List busStacks = machine.getItemOutputSlots(itemOutputs); // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the // recipe outputs. Map tItemOutputMap = new ItemStackMap<>(); diff --git a/src/main/java/gregtech/api/util/item/ItemHolder.java b/src/main/java/gregtech/api/util/item/ItemHolder.java deleted file mode 100644 index 51215c93cbf..00000000000 --- a/src/main/java/gregtech/api/util/item/ItemHolder.java +++ /dev/null @@ -1,79 +0,0 @@ -package gregtech.api.util.item; - -import static net.minecraftforge.oredict.OreDictionary.getOreIDs; - -import java.util.Arrays; - -import javax.annotation.Nonnull; - -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import gregtech.api.util.GTUtility; - -public class ItemHolder { - - private final Item item; - private final int meta; - private final NBTTagCompound tag; - private final int[] oreIDs; - - public ItemHolder(@Nonnull ItemStack item) { - this.item = item.getItem(); - this.meta = Items.feather.getDamage(item); - this.tag = item.getTagCompound(); - this.oreIDs = getOreIDs(item); - } - - public Item getItem() { - return item; - } - - public int getMeta() { - return meta; - } - - public NBTTagCompound getNBT() { - return tag; - } - - public int[] getOreDictTagIDs() { - return oreIDs; - } - - @Override - public boolean equals(Object other) { - if (other == this) return true; - if (!(other instanceof ItemHolder otherIH)) return false; - if (Arrays.stream(oreIDs) - .anyMatch(id -> { - for (int i = 0; i < otherIH.getOreDictTagIDs().length; i++) { - if (id == otherIH.getOreDictTagIDs()[i]) return true; - } - return false; - })) { - return true; - } - - if (item != otherIH.getItem() || meta != otherIH.getMeta()) { - return false; - } - if (this.tag == null && otherIH.getNBT() == null) return true; - if (this.tag == null || otherIH.getNBT() == null) return false; - return this.tag.equals(otherIH); - } - - @Override - public int hashCode() { - return GTUtility.stackToInt(toStack()); - } - - @Nonnull - private ItemStack toStack() { - ItemStack item = new ItemStack(this.item, 1, meta); - item.stackTagCompound = tag; - return item; - } -} diff --git a/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java b/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java deleted file mode 100644 index 485ee991c54..00000000000 --- a/src/main/java/gregtech/api/util/recipe/RecipeInputRequirements.java +++ /dev/null @@ -1,77 +0,0 @@ -package gregtech.api.util.recipe; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; - -import gregtech.api.util.GTRecipe; -import gregtech.api.util.item.ItemHolder; - -public class RecipeInputRequirements { - - protected Map itemInputs = new HashMap<>(); - protected Set itemInputsMet = new HashSet<>(); - protected boolean metAllItem = false; - protected Map fluidInputs = new HashMap<>(); - protected Set fluidInputsMet = new HashSet<>(); - protected boolean metAllFluid = false; - - public RecipeInputRequirements(@Nonnull GTRecipe recipe) { - this(recipe.mInputs, recipe.mFluidInputs); - } - - public RecipeInputRequirements(@Nonnull ItemStack[] itemInputs, @Nonnull FluidStack[] fluidInputs) { - for (ItemStack item : itemInputs) { - if (item == null) continue; - ItemHolder itemIH = new ItemHolder(item); - this.itemInputs.put(itemIH, this.itemInputs.getOrDefault(itemIH, 0L) + item.stackSize); - } - - for (FluidStack fluid : fluidInputs) { - if (fluid == null) continue; - this.fluidInputs.put(fluid.getFluid(), this.fluidInputs.getOrDefault(fluid.getFluid(), 0L) + fluid.amount); - } - } - - /** - * - * @param itemInputs we have and want to fill this request - * @return {@code true} when all item inputs are met - */ - public boolean tryToFillItemRequirements(Map itemInputs) { - if (metAllItem) return metAllItem; - for (Entry entry : itemInputs.entrySet()) { - if (itemInputsMet.contains(entry.getKey())) continue; - if (!this.itemInputs.containsKey(entry.getKey())) continue; - if (this.itemInputs.get(entry.getKey()) > entry.getValue()) continue; - itemInputsMet.add(entry.getKey()); - } - metAllItem = itemInputsMet.containsAll(this.itemInputs.keySet()); - return metAllItem; - } - - /** - * - * @param fluidInputs we have and want to fill this request - * @return {@code true} when all fluid inputs are met - */ - public boolean tryToFillFluidRequirements(Map fluidInputs) { - if (metAllFluid) return metAllFluid; - for (Entry entry : fluidInputs.entrySet()) { - if (fluidInputsMet.contains(entry.getKey())) continue; - if (!this.fluidInputs.containsKey(entry.getKey())) continue; - if (this.fluidInputs.get(entry.getKey()) > entry.getValue()) continue; - fluidInputsMet.add(entry.getKey()); - } - metAllFluid = fluidInputsMet.containsAll(this.fluidInputs.keySet()); - return metAllFluid; - } -} diff --git a/src/main/java/gregtech/common/gui/ComplexParallelMachineGUIProvider.java b/src/main/java/gregtech/common/gui/ComplexParallelMachineGUIProvider.java deleted file mode 100644 index 89b42c8500f..00000000000 --- a/src/main/java/gregtech/common/gui/ComplexParallelMachineGUIProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -package gregtech.common.gui; - -import javax.annotation.Nonnull; - -import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; - -import gregtech.api.gui.GUIHost; -import gregtech.api.logic.ComplexParallelProcessingLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; -import gregtech.api.logic.interfaces.ProcessingLogicHost; - -/** - * Default GUI class for machines with complex parallel - */ -public class ComplexParallelMachineGUIProvider> & PowerLogicHost> - extends MachineGUIProvider { - - public ComplexParallelMachineGUIProvider(@Nonnull T host) { - super(host); - } - - @Override - protected void attachSynchHandlers(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - - } - - @Override - protected void addWidgets(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - - } -} diff --git a/src/main/java/gregtech/common/gui/MachineGUIProvider.java b/src/main/java/gregtech/common/gui/MachineGUIProvider.java deleted file mode 100644 index a8d8804ebe9..00000000000 --- a/src/main/java/gregtech/common/gui/MachineGUIProvider.java +++ /dev/null @@ -1,510 +0,0 @@ -package gregtech.common.gui; - -import static gregtech.api.metatileentity.BaseTileEntity.BUTTON_FORBIDDEN_TOOLTIP; -import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; - -import net.minecraft.util.StatCollector; - -import com.gtnewhorizons.modularui.api.ModularUITextures; -import com.gtnewhorizons.modularui.api.NumberFormatMUI; -import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; -import com.gtnewhorizons.modularui.api.drawable.UITexture; -import com.gtnewhorizons.modularui.api.math.Pos2d; -import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.ButtonWidget; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; -import com.gtnewhorizons.modularui.common.widget.MultiChildWidget; -import com.gtnewhorizons.modularui.common.widget.TabButton; -import com.gtnewhorizons.modularui.common.widget.TabContainer; -import com.gtnewhorizons.modularui.common.widget.TextWidget; - -import gregtech.api.enums.InventoryType; -import gregtech.api.enums.SoundResource; -import gregtech.api.enums.VoidingMode; -import gregtech.api.gui.GUIHost; -import gregtech.api.gui.GUIProvider; -import gregtech.api.gui.modularui.GTUITextures; -import gregtech.api.gui.modularui.GUITextureSet; -import gregtech.api.logic.MuTEProcessingLogic; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; -import gregtech.api.logic.interfaces.ProcessingLogicHost; - -/** - * Default GUI a machine will use to show its information - */ -public class MachineGUIProvider> & PowerLogicHost> - extends GUIProvider { - - private static final int LOGO_SIZE = 17; - @Nonnull - protected static final Pos2d POWER_SWITCH_BUTTON_DEFAULT_POS = new Pos2d(144, 0); - @Nonnull - protected static final Pos2d VOIDING_MODE_BUTTON_DEFAULT_POS = new Pos2d(54, 0); - @Nonnull - protected static final Pos2d INPUT_SEPARATION_BUTTON_DEFAULT_POS = new Pos2d(36, 0); - @Nonnull - protected static final Pos2d BATCH_MODE_BUTTON_DEFAULT_POS = new Pos2d(18, 0); - @Nonnull - protected static final Pos2d RECIPE_LOCKING_BUTTON_DEFAULT_POS = new Pos2d(0, 0); - - protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); - - public MachineGUIProvider(@Nonnull T host) { - super(host); - } - - @Override - protected void attachSynchHandlers(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - - } - - @Override - protected void addWidgets(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - int page = 0; - builder.setBackground(GTUITextures.BACKGROUND_SINGLEBLOCK_DEFAULT); - MultiChildWidget mainTab = new MultiChildWidget(); - mainTab.setSize(host.getWidth(), host.getHeight()); - createMainTab(mainTab, builder, uiContext); - TabContainer tabs = new TabContainer().setButtonSize(20, 24); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f), - new ItemDrawable(host.getAsItem()).withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f), - new ItemDrawable(host.getAsItem()).withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip(host.getMachineName()) - .setPos(20 * (page - 1), -20)) - .addPage(mainTab); - if (host.hasItemInput()) { - MultiChildWidget itemInputTab = new MultiChildWidget(); - itemInputTab.setSize(host.getWidth(), host.getHeight()); - createItemInputTab(itemInputTab, builder, uiContext); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), - GTUITextures.PICTURE_ITEM_IN.withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), - GTUITextures.PICTURE_ITEM_IN.withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip("Item Input Inventory") - .setPos(20 * (page - 1), -20)) - .addPage(itemInputTab.addChild(getLogo().setPos(147, 86))); - } - - if (host.hasItemOutput()) { - MultiChildWidget itemOutputTab = new MultiChildWidget(); - itemOutputTab.setSize(host.getWidth(), host.getHeight()); - createItemOutputTab(itemOutputTab, builder, uiContext); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), - GTUITextures.PICTURE_ITEM_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), - GTUITextures.PICTURE_ITEM_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip("Item Output Inventory") - .setPos(20 * (page - 1), -20)) - .addPage(itemOutputTab.addChild(getLogo().setPos(147, 86))); - } - - if (host.hasFluidInput()) { - MultiChildWidget fluidInputTab = new MultiChildWidget(); - fluidInputTab.setSize(host.getWidth(), host.getHeight()); - createFluidInputTab(fluidInputTab, builder, uiContext); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), - GTUITextures.PICTURE_FLUID_IN.withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), - GTUITextures.PICTURE_FLUID_IN.withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip("Fluid Input Tanks") - .setPos(20 * (page - 1), -20)) - .addPage(fluidInputTab.addChild(getLogo().setPos(147, 86))); - } - - if (host.hasFluidOutput()) { - MultiChildWidget fluidOutputTab = new MultiChildWidget(); - fluidOutputTab.setSize(host.getWidth(), host.getHeight()); - createFluidOutputTab(fluidOutputTab, builder, uiContext); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), - GTUITextures.PICTURE_FLUID_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), - GTUITextures.PICTURE_FLUID_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip("Fluid Output Tanks") - .setPos(20 * (page - 1), -20)) - .addPage(fluidOutputTab.addChild(getLogo().setPos(147, 86))); - } - MultiChildWidget powerInfoTab = new MultiChildWidget(); - powerInfoTab.setSize(host.getWidth(), host.getHeight()); - createPowerTab(powerInfoTab, builder, uiContext); - tabs.addTabButton( - new TabButton(page++) - .setBackground( - false, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f), - GTUITextures.PICTURE_FLUID_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .setBackground( - true, - ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f), - GTUITextures.PICTURE_FLUID_OUT.withFixedSize(16, 16) - .withOffset(2, 4)) - .addTooltip("Power Information") - .setPos(20 * (page - 1), -20)) - .addPage(powerInfoTab.addChild(getLogo().setPos(147, 86))); - builder.widget(tabs); - } - - protected void createMainTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - MultiChildWidget buttons = new MultiChildWidget(); - buttons.setSize(16, 167) - .setPos(7, 86); - buttons.addChild(createPowerSwitchButton(builder)) - .addChild(createVoidExcessButton(builder)) - .addChild(createInputSeparationButton(builder)) - .addChild(createBatchModeButton(builder)) - .addChild(createLockToSingleRecipeButton(builder)); - tab.addChild( - new DrawableWidget().setDrawable(GTUITextures.PICTURE_SCREEN_BLACK) - .setPos(7, 4) - .setSize(160, 75)) - .addChild(buttons); - } - - protected void createItemInputTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - tab.addChild( - host.getItemLogic(InventoryType.Input, null) - .getGuiPart() - .setSize(18 * 4 + 9, 5 * 18) - .setPos(host.getWidth() / 2 - 2 * 18, 10)); - } - - protected void createItemOutputTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - tab.addChild( - host.getItemLogic(InventoryType.Output, null) - .getGuiPart() - .setSize(18 * 4 + 9, 5 * 18) - .setPos(host.getWidth() / 2 - 2 * 18, 10)); - } - - protected void createFluidInputTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - tab.addChild( - host.getFluidLogic(InventoryType.Input, null) - .getGuiPart() - .setSize(18 * 4 + 9, 5 * 18) - .setPos(host.getWidth() / 2 - 2 * 18, 10)); - } - - protected void createFluidOutputTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - tab.addChild( - host.getFluidLogic(InventoryType.Output, null) - .getGuiPart() - .setSize(18 * 4 + 9, 5 * 18) - .setPos(host.getWidth() / 2 - 2 * 18, 10)); - } - - protected void createPowerTab(@Nonnull MultiChildWidget tab, @Nonnull Builder builder, - @Nonnull UIBuildContext uiBuildContext) { - PowerLogic power = host.getPowerLogic(); - tab.addChild( - new TextWidget() - .setStringSupplier( - () -> numberFormat.format(power.getStoredEnergy()) + "/" - + numberFormat.format(power.getCapacity()) - + " EU") - .setPos(10, 30)) - .addChild( - new TextWidget() - .setStringSupplier( - () -> numberFormat.format(power.getVoltage()) + " EU/t" - + "(" - + numberFormat.format(power.getMaxAmperage()) - + " A)") - .setPos(10, 60)); - } - - /** - * Should return the logo you want to use that is pasted on each tab. Default is the GT logo. - */ - @Nonnull - protected Widget getLogo() { - DrawableWidget logo = new DrawableWidget(); - logo.setDrawable(GUITextureSet.DEFAULT.getGregTechLogo()) - .setSize(LOGO_SIZE, LOGO_SIZE); - return logo; - } - - protected Pos2d getPowerSwitchButtonPos() { - return POWER_SWITCH_BUTTON_DEFAULT_POS; - } - - protected ButtonWidget createPowerSwitchButton(IWidgetBuilder builder) { - ButtonWidget button = new ButtonWidget(); - button.setOnClick((clickData, widget) -> { - if (host.isAllowedToWork()) { - host.disableWorking(); - } else { - host.enableWorking(); - } - }) - .setPlayClickSoundResource( - () -> host.isAllowedToWork() ? SoundResource.GUI_BUTTON_UP.resourceLocation - : SoundResource.GUI_BUTTON_DOWN.resourceLocation) - .setBackground(() -> { - if (host.isAllowedToWork()) { - return new IDrawable[] { GTUITextures.BUTTON_STANDARD_PRESSED, - GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_ON }; - } else { - return new IDrawable[] { GTUITextures.BUTTON_STANDARD, - GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_OFF }; - } - }) - .attachSyncer(new FakeSyncWidget.BooleanSyncer(host::isAllowedToWork, host::setAllowedToWork), builder) - .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.power_switch")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getPowerSwitchButtonPos()) - .setSize(16, 16); - return button; - } - - @Nonnull - protected Pos2d getVoidingModeButtonPos() { - return VOIDING_MODE_BUTTON_DEFAULT_POS; - } - - @Nonnull - protected ButtonWidget createVoidExcessButton(IWidgetBuilder builder) { - ButtonWidget button = new ButtonWidget(); - button.setOnClick((clickData, widget) -> { - if (host.supportsVoidProtection()) { - Set allowed = host.getAllowedVoidingModes(); - switch (clickData.mouseButton) { - case 0 -> host.setVoidingMode( - host.getVoidingMode() - .nextInCollection(allowed)); - case 1 -> host.setVoidingMode( - host.getVoidingMode() - .previousInCollection(allowed)); - } - widget.notifyTooltipChange(); - } - }) - .setPlayClickSound(host.supportsVoidProtection()) - .setBackground(() -> { - List ret = new ArrayList<>(); - ret.add(host.getVoidingMode().buttonTexture); - ret.add(host.getVoidingMode().buttonOverlay); - if (!host.supportsVoidProtection()) { - ret.add(GTUITextures.OVERLAY_BUTTON_FORBIDDEN); - } - return ret.toArray(new IDrawable[0]); - }) - .attachSyncer( - new FakeSyncWidget.IntegerSyncer( - () -> host.getVoidingMode() - .ordinal(), - val -> host.setVoidingMode(VoidingMode.fromOrdinal(val))), - builder) - .dynamicTooltip( - () -> Arrays.asList( - StatCollector.translateToLocal("GT5U.gui.button.voiding_mode"), - StatCollector.translateToLocal( - host.getVoidingMode() - .getTransKey()))) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getVoidingModeButtonPos()) - .setSize(16, 16); - if (!host.supportsVoidProtection()) { - button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); - } - return button; - } - - @Nonnull - protected Pos2d getInputSeparationButtonPos() { - return INPUT_SEPARATION_BUTTON_DEFAULT_POS; - } - - protected ButtonWidget createInputSeparationButton(IWidgetBuilder builder) { - ButtonWidget button = new ButtonWidget(); - button.setOnClick((clickData, widget) -> { - if (host.supportsInputSeparation()) { - host.setInputSeparation(!host.isInputSeparated()); - } - }) - .setPlayClickSound(host.supportsInputSeparation()) - .setBackground(() -> { - List ret = new ArrayList<>(); - if (host.isInputSeparated()) { - ret.add(GTUITextures.BUTTON_STANDARD_PRESSED); - if (host.supportsInputSeparation()) { - ret.add(GTUITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_INPUT_SEPARATION_ON_DISABLED); - } - } else { - ret.add(GTUITextures.BUTTON_STANDARD); - if (host.supportsInputSeparation()) { - ret.add(GTUITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_INPUT_SEPARATION_OFF_DISABLED); - } - } - if (!host.supportsInputSeparation()) { - ret.add(GTUITextures.OVERLAY_BUTTON_FORBIDDEN); - } - return ret.toArray(new IDrawable[0]); - }) - .attachSyncer(new FakeSyncWidget.BooleanSyncer(host::isInputSeparated, host::setInputSeparation), builder) - .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.input_separation")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getInputSeparationButtonPos()) - .setSize(16, 16); - if (!host.supportsInputSeparation()) { - button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); - } - return button; - } - - @Nonnull - protected Pos2d getBatchModeButtonPos() { - return BATCH_MODE_BUTTON_DEFAULT_POS; - } - - protected ButtonWidget createBatchModeButton(IWidgetBuilder builder) { - ButtonWidget button = new ButtonWidget(); - button.setOnClick((clickData, widget) -> { - if (host.supportsBatchMode()) { - host.setBatchMode(!host.isBatchModeEnabled()); - } - }) - .setPlayClickSound(host.supportsBatchMode()) - .setBackground(() -> { - List ret = new ArrayList<>(); - if (host.isBatchModeEnabled()) { - ret.add(GTUITextures.BUTTON_STANDARD_PRESSED); - if (host.supportsBatchMode()) { - ret.add(GTUITextures.OVERLAY_BUTTON_BATCH_MODE_ON); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_BATCH_MODE_ON_DISABLED); - } - } else { - ret.add(GTUITextures.BUTTON_STANDARD); - if (host.supportsBatchMode()) { - ret.add(GTUITextures.OVERLAY_BUTTON_BATCH_MODE_OFF); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_BATCH_MODE_OFF_DISABLED); - } - } - if (!host.supportsBatchMode()) { - ret.add(GTUITextures.OVERLAY_BUTTON_FORBIDDEN); - } - return ret.toArray(new IDrawable[0]); - }) - .attachSyncer(new FakeSyncWidget.BooleanSyncer(host::isBatchModeEnabled, host::setBatchMode), builder) - .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.batch_mode")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getBatchModeButtonPos()) - .setSize(16, 16); - if (!host.supportsBatchMode()) { - button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); - } - return button; - } - - @Nonnull - protected Pos2d getRecipeLockingButtonPos() { - return RECIPE_LOCKING_BUTTON_DEFAULT_POS; - } - - protected ButtonWidget createLockToSingleRecipeButton(IWidgetBuilder builder) { - ButtonWidget button = new ButtonWidget(); - button.setOnClick((clickData, widget) -> { - if (host.supportsSingleRecipeLocking()) { - host.setRecipeLocking(!host.isRecipeLockingEnabled()); - } - }) - .setPlayClickSound(host.supportsSingleRecipeLocking()) - .setBackground(() -> { - List ret = new ArrayList<>(); - if (host.isRecipeLockingEnabled()) { - ret.add(GTUITextures.BUTTON_STANDARD_PRESSED); - if (host.supportsSingleRecipeLocking()) { - ret.add(GTUITextures.OVERLAY_BUTTON_RECIPE_LOCKED); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_RECIPE_LOCKED_DISABLED); - } - } else { - ret.add(GTUITextures.BUTTON_STANDARD); - if (host.supportsSingleRecipeLocking()) { - ret.add(GTUITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED); - } else { - ret.add(GTUITextures.OVERLAY_BUTTON_RECIPE_UNLOCKED_DISABLED); - } - } - if (!host.supportsSingleRecipeLocking()) { - ret.add(GTUITextures.OVERLAY_BUTTON_FORBIDDEN); - } - return ret.toArray(new IDrawable[0]); - }) - .attachSyncer( - new FakeSyncWidget.BooleanSyncer(host::isRecipeLockingEnabled, host::setRecipeLocking), - builder) - .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.lock_recipe")) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(getRecipeLockingButtonPos()) - .setSize(16, 16); - if (!host.supportsSingleRecipeLocking()) { - button.addTooltip(StatCollector.translateToLocal(BUTTON_FORBIDDEN_TOOLTIP)); - } - return button; - } -} diff --git a/src/main/java/gregtech/common/gui/PartGUIProvider.java b/src/main/java/gregtech/common/gui/PartGUIProvider.java deleted file mode 100644 index 7600444f712..00000000000 --- a/src/main/java/gregtech/common/gui/PartGUIProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -package gregtech.common.gui; - -import javax.annotation.Nonnull; - -import com.gtnewhorizons.modularui.api.screen.ModularWindow.Builder; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; - -import gregtech.api.gui.GUIHost; -import gregtech.api.gui.GUIProvider; -import gregtech.api.logic.interfaces.FluidInventoryLogicHost; -import gregtech.api.logic.interfaces.ItemInventoryLogicHost; -import gregtech.api.logic.interfaces.PowerLogicHost; - -public class PartGUIProvider - extends GUIProvider { - - public PartGUIProvider(@Nonnull T host) { - super(host); - } - - @Override - protected void attachSynchHandlers(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'attachSynchHandlers'"); - } - - @Override - protected void addWidgets(@Nonnull Builder builder, @Nonnull UIBuildContext uiContext) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'addWidgets'"); - } - -} diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index fd7d291c29d..aefef077fde 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -122,13 +122,7 @@ public interface SharedItemGetter { private final GTUtility.ItemId itemId; public PatternSlot(ItemStack pattern, World world, SharedItemGetter getter) { - this.pattern = pattern; - this.patternDetails = ((ICraftingPatternItem) Objects.requireNonNull(pattern.getItem())) - .getPatternForItem(pattern, world); - this.itemInventory = new ArrayList<>(); - this.fluidInventory = new ArrayList<>(); - this.sharedItemGetter = getter; - this.itemId = GTUtility.ItemId.create(pattern); + this(pattern, null, world, getter); } public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedItemGetter getter) { @@ -139,6 +133,7 @@ public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedIte this.fluidInventory = new ArrayList<>(); this.sharedItemGetter = getter; this.itemId = GTUtility.ItemId.create(pattern); + if (nbt == null) return; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < inv.tagCount(); i++) { NBTTagCompound tagItemStack = inv.getCompoundTagAt(i); @@ -831,7 +826,7 @@ private void onPatternChange(int index, ItemStack newItem) { try { originalPattern.refund(getProxy(), getRequest()); for (ProcessingLogic pl : processingLogics) { - pl.removeEntryCraftingPatternRecipeCache(originalPattern); + pl.clearCraftingPatternRecipeCache(originalPattern); } } catch (GridAccessException ignored) {} internalInventory[index] = null; @@ -870,7 +865,7 @@ private void resetCraftingInputRecipeMap() { for (ProcessingLogic pl : processingLogics) { for (PatternSlot sl : internalInventory) { if (sl == null) continue; - pl.removeEntryCraftingPatternRecipeCache(sl); + pl.clearCraftingPatternRecipeCache(sl); } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java index b2954f15e05..38ae848b060 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEIndustrialElectromagneticSeparator.java @@ -408,7 +408,7 @@ public boolean supportsSingleRecipeLocking() { @Override protected void setProcessingLogicPower(ProcessingLogic logic) { // This fix works for normal energy hatches, preventing over-paralleling with 1 energy hatch - // However, it does not work with multiamp. MuTEs can't come soon enough. + // However, it does not work with multiamp. if (mExoticEnergyHatches.isEmpty()) { logic.setAvailableVoltage(GTUtility.roundUpVoltage(this.getMaxInputVoltage())); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index ef409934211..6c071c74b5c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -21,6 +21,8 @@ import java.util.Collection; import java.util.List; +import javax.annotation.Nonnull; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -32,7 +34,6 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -52,7 +53,6 @@ import gregtech.api.metatileentity.implementations.MTEExtendedPowerMultiBlockBase; import gregtech.api.metatileentity.implementations.MTEHatchEnergy; import gregtech.api.metatileentity.implementations.MTEHatchInput; -import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; import gregtech.api.recipe.check.CheckRecipeResult; @@ -62,9 +62,6 @@ import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.common.blocks.BlockCasings10; -import gregtech.common.tileentities.machines.IDualInputHatch; -import gregtech.common.tileentities.machines.IDualInputInventory; -import gregtech.common.tileentities.machines.MTEHatchCraftingInputME; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchSolidifier; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -294,12 +291,8 @@ protected ProcessingLogic createProcessingLogic() { // Override is needed so that switching recipe maps does not stop recipe locking. @Override - protected RecipeMap preProcess() { + protected RecipeMap getCurrentRecipeMap() { lastRecipeMap = currentRecipeMap; - - if (maxParallelSupplier != null) { - maxParallel = maxParallelSupplier.get(); - } return currentRecipeMap; } @@ -430,35 +423,9 @@ public boolean supportsBatchMode() { return true; } - @NotNull + @Nonnull @Override - protected CheckRecipeResult doCheckRecipe() { - CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; - - // check crafting input hatches first - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - - if (!slot.isEmpty() && processingLogic.craftingPatternHandler(slot)) { - - processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); - processingLogic.setInputFluids(slot.getFluidInputs()); - - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; - } - } - } - } - - // Logic for GT_MetaTileEntity_Hatch_Solidifier + protected CheckRecipeResult checkRecipeForCustomHatches(CheckRecipeResult lastResult) { for (MTEHatchInput solidifierHatch : mInputHatches) { if (solidifierHatch instanceof MTEHatchSolidifier hatch) { ItemStack mold = hatch.getMold(); @@ -468,7 +435,7 @@ protected CheckRecipeResult doCheckRecipe() { List inputItems = new ArrayList<>(); inputItems.add(mold); - processingLogic.setInputItems(inputItems.toArray(new ItemStack[0])); + processingLogic.setInputItems(inputItems); processingLogic.setInputFluids(fluid); CheckRecipeResult foundResult = processingLogic.process(); @@ -477,39 +444,13 @@ protected CheckRecipeResult doCheckRecipe() { } if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; + lastResult = foundResult; } } } } processingLogic.clear(); - processingLogic.setInputFluids(getStoredFluids()); - // Default logic - for (MTEHatchInputBus bus : mInputBusses) { - if (bus instanceof MTEHatchCraftingInputME) { - continue; - } - List inputItems = new ArrayList<>(); - for (int i = bus.getSizeInventory() - 1; i >= 0; i--) { - ItemStack stored = bus.getStackInSlot(i); - if (stored != null) { - inputItems.add(stored); - } - } - if (canUseControllerSlotForRecipe() && getControllerSlot() != null) { - inputItems.add(getControllerSlot()); - } - processingLogic.setInputItems(inputItems.toArray(new ItemStack[0])); - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; - } - } - return result; + return lastResult; } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTETranscendentPlasmaMixer.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTETranscendentPlasmaMixer.java index 52186e1d7d3..8953318e200 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTETranscendentPlasmaMixer.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTETranscendentPlasmaMixer.java @@ -210,7 +210,7 @@ protected CheckRecipeResult onRecipeStart(@Nonnull GTRecipe recipe) { return CheckRecipeResultRegistry.insufficientStartupPower(finalConsumption); } // Energy consumed all at once from wireless net. - setCalculatedEut(0); + overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } diff --git a/src/main/java/tectech/TecTech.java b/src/main/java/tectech/TecTech.java index 1c30594c0f1..8027aee6d35 100644 --- a/src/main/java/tectech/TecTech.java +++ b/src/main/java/tectech/TecTech.java @@ -18,7 +18,6 @@ import tectech.loader.ConfigHandler; import tectech.loader.MainLoader; import tectech.loader.gui.CreativeTabTecTech; -import tectech.loader.thing.MuTeLoader; import tectech.mechanics.enderStorage.EnderWorldSavedData; import tectech.proxy.CommonProxy; import tectech.recipe.EyeOfHarmonyRecipeStorage; @@ -81,7 +80,6 @@ public void PreLoad(FMLPreInitializationEvent PreEvent) { TecTechRecipeMaps.init(); MainLoader.preLoad(); - new MuTeLoader().run(); } @Mod.EventHandler diff --git a/src/main/java/tectech/loader/thing/MuTeLoader.java b/src/main/java/tectech/loader/thing/MuTeLoader.java deleted file mode 100644 index 74c51f1bf16..00000000000 --- a/src/main/java/tectech/loader/thing/MuTeLoader.java +++ /dev/null @@ -1,21 +0,0 @@ -package tectech.loader.thing; - -import tectech.TecTech; - -public class MuTeLoader implements Runnable { - - @Override - public void run() { - TecTech.LOGGER.info("TecTech: Registering MultiTileEntities"); - registerMachines(); - registerCasings(); - } - - private static void registerMachines() { - - } - - private static void registerCasings() { - - } -} diff --git a/src/main/java/tectech/thing/metaTileEntity/hatch/MTEHatchDynamoTunnel.java b/src/main/java/tectech/thing/metaTileEntity/hatch/MTEHatchDynamoTunnel.java index 703a269bf0d..314d52ad841 100644 --- a/src/main/java/tectech/thing/metaTileEntity/hatch/MTEHatchDynamoTunnel.java +++ b/src/main/java/tectech/thing/metaTileEntity/hatch/MTEHatchDynamoTunnel.java @@ -21,8 +21,6 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.GTUtility; import tectech.mechanics.pipe.IConnectsToEnergyTunnel; @@ -235,15 +233,6 @@ private void moveAround(IGregTechTileEntity aBaseMetaTileEntity) { return; } } else { - if (tGTTileEntity instanceof PowerLogicHost) { - PowerLogic logic = ((PowerLogicHost) tGTTileEntity).getPowerLogic(opposite); - if (logic == null || !logic.canUseLaser() || opposite != tGTTileEntity.getFrontFacing()) { - return; - } - - long ampsUsed = logic.injectEnergy(maxEUOutput(), Amperes); - setEUVar(aBaseMetaTileEntity.getStoredEU() - ampsUsed * maxEUOutput()); - } return; } } else { diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java index e14a40f8631..71e68ae91b7 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEExoticModule.java @@ -181,7 +181,7 @@ protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { addToPowerTally(powerForRecipe); addToRecipeTally(calculatedParallels); - setCalculatedEut(0); + overwriteCalculatedEut(0); plasmaRecipe = null; recipeInProgress = false; return CheckRecipeResultRegistry.SUCCESSFUL; diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java index eace01bb6a7..a7080a4fe1a 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEMoltenModule.java @@ -93,7 +93,7 @@ protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { addToRecipeTally(calculatedParallels); currentParallel = calculatedParallels; EUt = calculatedEut; - setCalculatedEut(0); + overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } }; diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java index 05ae43e341b..48a4388048f 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTEPlasmaModule.java @@ -100,7 +100,7 @@ protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { addToRecipeTally(calculatedParallels); currentParallel = calculatedParallels; EUt = calculatedEut; - setCalculatedEut(0); + overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } diff --git a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java index 1e499b3507a..c1bd1502eb3 100644 --- a/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java +++ b/src/main/java/tectech/thing/metaTileEntity/multi/godforge/MTESmeltingModule.java @@ -118,7 +118,7 @@ protected CheckRecipeResult onRecipeStart(@NotNull GTRecipe recipe) { } currentParallel = calculatedParallels; EUt = calculatedEut; - setCalculatedEut(0); + overwriteCalculatedEut(0); return CheckRecipeResultRegistry.SUCCESSFUL; } diff --git a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java index e94f4d31ff3..9610030311d 100644 --- a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java +++ b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergy.java @@ -21,8 +21,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.MetaPipeEntity; import gregtech.api.objects.GTRenderedTexture; @@ -119,14 +117,6 @@ public void updateNetwork(boolean nestedCall) { continue; } } - if (tTileEntity instanceof PowerLogicHost host) { - PowerLogic logic = host.getPowerLogic(oppositeSide); - if (logic != null && logic.canUseLaser()) { - mConnections |= side.flag; - connectionCount++; - continue; - } - } if (tTileEntity instanceof IConnectsToEnergyTunnel tunnel && tunnel.canConnect(oppositeSide)) { mConnections |= side.flag; connectionCount++; diff --git a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergyMirror.java b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergyMirror.java index 91fdc3e3a1f..d5c525a2fdb 100644 --- a/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergyMirror.java +++ b/src/main/java/tectech/thing/metaTileEntity/pipe/MTEPipeEnergyMirror.java @@ -17,8 +17,6 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IColoredTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.logic.PowerLogic; -import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.objects.GTRenderedTexture; import gregtech.common.GTClient; import tectech.TecTech; @@ -108,15 +106,6 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { continue; } } - if (tTileEntity instanceof PowerLogicHost) { - PowerLogic logic = ((PowerLogicHost) tTileEntity).getPowerLogic(oppositeSide); - if (logic != null && logic.canUseLaser()) { - mConnections |= 1 << side.ordinal(); - connectedSides[connectionCount] = side; - connectionCount++; - continue; - } - } if (tTileEntity instanceof IConnectsToEnergyTunnel && ((IConnectsToEnergyTunnel) tTileEntity).canConnect(oppositeSide)) { mConnections |= 1 << side.ordinal(); @@ -197,12 +186,6 @@ public IGregTechTileEntity bendAround(ForgeDirection inputSide) { return null; } } else { - if (tGTTileEntity instanceof PowerLogicHost) { - PowerLogic logic = ((PowerLogicHost) tGTTileEntity).getPowerLogic(opposite); - if (logic == null || !logic.canUseLaser() || opposite != tGTTileEntity.getFrontFacing()) { - return tGTTileEntity; - } - } return null; } } else {