diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index 0447cbcd20..e0da8e9fc2 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -5,12 +5,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import gregtech.api.GregTech_API; import gregtech.api.util.GT_Utility; import net.minecraftforge.fluids.FluidStack; import org.apache.commons.lang3.ArrayUtils; import gregtech.api.enums.Materials; +import gregtech.api.gui.GT_Container_MultiMachine; +import gregtech.api.gui.GT_GUIContainer_MultiMachine; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.items.GT_MetaGenerated_Tool; @@ -19,9 +20,7 @@ import gregtech.api.metatileentity.implementations.*; import gregtech.api.util.GT_Recipe; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.LoadedMods; -import gtPlusPlus.core.util.PollutionUtils; import gtPlusPlus.core.util.math.MathUtils; -import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine; import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; @@ -57,21 +56,27 @@ GT_MetaTileEntity_MultiBlockBase { .getMetaTileEntity() == aMetaTileEntity) && !aMetaTileEntity.getBaseMetaTileEntity().isDead(); } + + public abstract boolean hasSlotInGUI(); @Override - public Object getServerGUI(final int aID, - final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return new CONTAINER_MultiMachine(aPlayerInventory, - aBaseMetaTileEntity); + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + if (hasSlotInGUI()) { + return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + } + else { + return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity); + } } @Override - public Object getClientGUI(final int aID, - final InventoryPlayer aPlayerInventory, - final IGregTechTileEntity aBaseMetaTileEntity) { - return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, - this.getLocalName(), "MultiblockDisplay.png"); + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { + if (hasSlotInGUI()) { + return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); + } + else { + return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MultiblockDisplay.png"); + } } @Override @@ -115,8 +120,10 @@ GT_MetaTileEntity_MultiBlockBase { public String getSound() { return ""; } - public boolean canBufferOutputs(final GT_Recipe aRecipe) { - // Count slots available in hatches + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { + // Count slots available in output buses + ArrayList<ItemStack> tBusStacks = new ArrayList<>(); + int tEmptySlots = 0; for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) { if (!isValidMetaTileEntity(tBus)) { @@ -127,12 +134,26 @@ GT_MetaTileEntity_MultiBlockBase { if (tBus.getStackInSlot(i) == null) { tEmptySlots++; } + else { + tBusStacks.add(tBus.getStackInSlot(i)); + } } } - // TODO: Check if any of the output stacks can stack with the stacks in the hatches? + int slotsNeeded = aRecipe.mOutputs.length; + for (final ItemStack tRecipeOutput: aRecipe.mOutputs) { + int amount = tRecipeOutput.stackSize * aParallelRecipes; + for (final ItemStack tBusStack : tBusStacks) { + if (GT_Utility.areStacksEqual(tBusStack, tRecipeOutput)) { + if (tBusStack.stackSize + amount <= tBusStack.getMaxStackSize()) { + slotsNeeded--; + break; + } + } + } + } // Enough open slots? - if (tEmptySlots < aRecipe.mOutputs.length) return false; + if (tEmptySlots < slotsNeeded) return false; // For each output fluid, make sure an output hatch can accept it. for (FluidStack tRecipeFluid: aRecipe.mFluidOutputs) { @@ -176,13 +197,17 @@ GT_MetaTileEntity_MultiBlockBase { ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + // Based on the Processing Array. A bit overkill, but very flexible. + // Reset outputs and progress stats + this.mEUt = 0; + this.mMaxProgresstime = 0; + this.mOutputItems = new ItemStack[]{}; + this.mOutputFluids = new FluidStack[]{}; - // Based on the Processing Array. A bit overkill, but very flexible. long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - int parallelRecipes = 0; GT_Recipe tRecipe = this.getRecipeMap().findRecipe( getBaseMetaTileEntity(), mLastRecipe, false, @@ -195,7 +220,7 @@ GT_MetaTileEntity_MultiBlockBase { return false; } - if (!this.canBufferOutputs(tRecipe)) { + if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { return false; } @@ -203,12 +228,8 @@ GT_MetaTileEntity_MultiBlockBase { float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; float tTotalEUt = 0.0f; - // Reset outputs and progress stats - this.mEUt = 0; - this.mMaxProgresstime = 0; - this.mOutputItems = new ItemStack[]{}; - this.mOutputFluids = new FluidStack[]{}; - + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { @@ -221,6 +242,9 @@ GT_MetaTileEntity_MultiBlockBase { return false; } + // -- Try not to fail after this point - inputs have already been consumed! -- + + // Convert speed bonus to duration multiplier // e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration. aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent); |