diff options
Diffstat (limited to 'src/main/java')
3 files changed, 13 insertions, 404 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java index 85a3fd4edc..ed1765dfd3 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_SteamMultiBase.java @@ -19,17 +19,12 @@ import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_HatchElementBuilder; -import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.api.util.IGT_HatchAdder; -import gtPlusPlus.api.objects.data.AutoMap; -import gtPlusPlus.api.objects.data.ConcurrentHashSet; -import gtPlusPlus.api.objects.data.ConcurrentSet; -import gtPlusPlus.api.objects.data.FlexiblePair; -import gtPlusPlus.api.objects.data.Triplet; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusInput; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Steam_BusOutput; @@ -179,370 +174,6 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu super.stopMachine(); } - public FluidStack[] getOutputFluids(GT_Recipe aRecipe, int parallelRecipes) { - // Collect fluid outputs - FluidStack[] tOutputFluids = new FluidStack[aRecipe.mFluidOutputs.length]; - for (int h = 0; h < aRecipe.mFluidOutputs.length; h++) { - if (aRecipe.getFluidOutput(h) != null) { - tOutputFluids[h] = aRecipe.getFluidOutput(h).copy(); - tOutputFluids[h].amount *= parallelRecipes; - } - } - return tOutputFluids; - } - - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[aRecipe.mOutputs.length]; - for (int h = 0; h < aRecipe.mOutputs.length; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - public int getOutputCount(ItemStack[] aOutputs) { - return aOutputs.length; - } - - public int getOutputFluidCount(FluidStack[] aOutputs) { - return aOutputs.length; - } - - public int canBufferOutputs(final ItemStack[] aOutputs, FluidStack[] aFluidOutputs, int aParallelRecipes) { - - log("Determining if we have space to buffer outputs. Parallel: " + aParallelRecipes); - - // Null recipe or a recipe with lots of outputs? - // E.G. Gendustry custom comb with a billion centrifuge outputs? - // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. - if (aOutputs == null && aFluidOutputs == null) { - return 0; - } - - // Do we even need to check for item outputs? - boolean aDoesOutputItems = aOutputs != null ? aOutputs.length > 0 : false; - // Do we even need to check for fluid outputs? - boolean aDoesOutputFluids = aFluidOutputs != null ? aFluidOutputs.length > 0 : false; - - if (!aDoesOutputItems && !aDoesOutputFluids) { - return 0; - } - - /* - * ======================================== Item Management ======================================== - */ - - if (aDoesOutputItems) { - log("We have items to output."); - - // How many slots are free across all the output buses? - int aInputBusSlotsFree = 0; - - /* - * Create Variables for Item Output - */ - - AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>(); - AutoMap<ItemStack> aItemOutputs = new AutoMap<ItemStack>(aOutputs); - - for (final GT_MetaTileEntity_Hatch_Steam_BusOutput tBus : this.mSteamOutputs) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - final IInventory tBusInv = tBus.getBaseMetaTileEntity(); - for (int i = 0; i < tBusInv.getSizeInventory(); i++) { - if (tBus.getStackInSlot(i) == null) { - aInputBusSlotsFree++; - } else { - ItemStack aT = tBus.getStackInSlot(i); - int aSize = aT.stackSize; - aT = aT.copy(); - aT.stackSize = 0; - aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize)); - } - } - } - - // Count the slots we need, later we can check if any are able to merge with existing stacks - int aRecipeSlotsRequired = 0; - - // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the - // recipe outputs. - ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>(); - - // Iterate over the outputs, calculating require stack spacing they will require. - for (int i = 0; i < getOutputCount(aOutputs); i++) { - ItemStack aY = aItemOutputs.get(i); - if (aY == null) { - continue; - } else { - int aStackSize = aY.stackSize * aParallelRecipes; - if (aStackSize > 64) { - int aSlotsNeedsForThisStack = (int) Math.ceil((double) ((float) aStackSize / 64f)); - // Should round up and add as many stacks as required nicely. - aRecipeSlotsRequired += aSlotsNeedsForThisStack; - for (int o = 0; o < aRecipeSlotsRequired; o++) { - int aStackToRemove = (aStackSize -= 64) > 64 ? 64 : aStackSize; - aY = aY.copy(); - aY.stackSize = 0; - aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove)); - } - } else { - // Only requires one slot - aRecipeSlotsRequired++; - aY = aY.copy(); - aY.stackSize = 0; - aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackSize)); - } - } - } - - // We have items to add to the output buses. See if any are not full stacks and see if we can make them - // full. - if (aInputMap.size() > 0) { - // Iterate over the current stored items in the Output busses, if any match and are not full, we can try - // account for merging. - busItems: for (FlexiblePair<ItemStack, Integer> y : aItemMap) { - // Iterate over the 'inputs', we can safely remove these as we go. - outputItems: for (FlexiblePair<ItemStack, Integer> u : aInputMap) { - // Create local vars for readability. - ItemStack aOutputBusStack = y.getKey(); - ItemStack aOutputStack = u.getKey(); - // Stacks match, including NBT. - if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) { - // Stack Matches, but it's full, continue. - if (aOutputBusStack.stackSize >= 64) { - // This stack is full, no point checking it. - continue busItems; - } else { - // We can merge these two stacks without any hassle. - if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) { - // Update the stack size in the bus storage map. - y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - continue outputItems; - } - // Stack merging is too much, so we fill this stack, leave the remainder. - else { - int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64; - // Update the stack size in the bus storage map. - y.setValue(64); - // Create a new object to iterate over later, with the remainder data; - FlexiblePair<ItemStack, Integer> t = new FlexiblePair<ItemStack, Integer>( - u.getKey(), - aRemainder); - // Remove the 'input' stack from the recipe outputs, so we don't try count it again. - aInputMap.remove(u); - // Add the remainder stack. - aInputMap.add(t); - continue outputItems; - } - } - } else { - continue outputItems; - } - } - } - } - - // We have stacks that did not merge, do we have space for them? - if (aInputMap.size() > 0) { - if (aInputMap.size() > aInputBusSlotsFree) { - aParallelRecipes = (int) Math - .floor((double) aInputBusSlotsFree / aInputMap.size() * aParallelRecipes); - // We do not have enough free slots in total to accommodate the remaining managed stacks. - log(" Free: " + aInputBusSlotsFree + ", Required: " + aInputMap.size()); - if (aParallelRecipes == 0) { - log("Failed to find enough space for all item outputs."); - return 0; - } - } - } - - /* - * End Item Management - */ - - } - - /* - * ======================================== Fluid Management ======================================== - */ - - if (aDoesOutputFluids) { - log("We have Fluids to output."); - // How many slots are free across all the output buses? - int aFluidHatches = 0; - int aEmptyFluidHatches = 0; - int aFullFluidHatches = 0; - // Create Map for Fluid Output - ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = new ArrayList<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>(); - for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) { - if (!isValidMetaTileEntity(tBus)) { - continue; - } - aFluidHatches++; - // Map the Hatch with the space left for easy checking later. - if (tBus.getFluid() == null) { - aOutputHatches.add( - new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( - tBus, - null, - tBus.getCapacity())); - } else { - int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount(); - aOutputHatches.add( - new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( - tBus, - tBus.getFluid(), - aSpaceLeft)); - } - } - // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can - // merge into existing hatch stacks. - ArrayList<FluidStack> aOutputFluids = new ArrayList<FluidStack>(); - // Ugly ass boxing - aOutputFluids.addAll(new AutoMap<FluidStack>(aFluidOutputs)); - // Iterate the Hatches, updating their 'stored' data. - // for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) { - for (int i = 0; i < aOutputHatches.size(); i++) { - // The Hatch Itself - GT_MetaTileEntity_Hatch_Output aHatch = aOutputHatches.get(i).getValue_1(); - // Fluid in the Hatch - FluidStack aHatchStack = aOutputHatches.get(i).getValue_2(); - // Space left in Hatch - int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount(); - // Hatch is full, - if (aSpaceLeftInHatch <= 0) { - aFullFluidHatches++; - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - continue; - } - // Hatch has space - else { - // Check if any fluids match - // aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) { - for (int j = 0; j < getOutputFluidCount(aFluidOutputs); j++) { - // log(" aHatchStack "+aHatchStack.getLocalizedName()+" aOutput stack - // "+aOutputStack.getLocalizedName()); - if (GT_Utility.areFluidsEqual(aHatchStack, aOutputFluids.get(j))) { - int aFluidToPutIntoHatch = aOutputFluids.get(j).amount * aParallelRecipes; - // Not Enough space to insert all of the fluid. - // We fill this hatch and add a smaller Fluidstack back to the iterator. - if (aSpaceLeftInHatch < aFluidToPutIntoHatch) { - // Copy existing Hatch Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - aNewHatchStack.amount = 0; - // Copy existing Hatch Stack again - FluidStack aNewOutputStack = aHatchStack.copy(); - aNewOutputStack.amount = 0; - // How much fluid do we have left after we fill the hatch? - int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch; - // Set new stacks to appropriate values - aNewHatchStack.amount = aHatch.getCapacity(); - aNewOutputStack.amount = aFluidLeftAfterInsert; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Add remaining Fluid to Output list - aOutputFluids.add(aNewOutputStack); - // Re-add hatch to hatch list, with new data. - // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new - // Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, - // aNewHatchStack.amount); - // aOutputHatches.add(aNewHatchData); - break; - } - // We can fill this hatch perfectly (rare case), may as well add it directly to the full - // list. - else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( - aHatch, - aNewHatchStack, - aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - break; - } - // We have more space than we need to merge, so we remove the stack from the output list and - // update the hatch list. - else { - // Copy Old Stack - FluidStack aNewHatchStack = aHatchStack.copy(); - // Add in amount from output stack - aNewHatchStack.amount += aFluidToPutIntoHatch; - // Remove fluid from output list, merge success - aOutputFluids.remove(aOutputFluids.get(j)); - j--; - // Remove hatch from hatch list, data is now invalid. - aOutputHatches.remove(aOutputHatches.get(i)); - i--; - // Re-add hatch to hatch list, with new data. - Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>( - aHatch, - aNewHatchStack, - aNewHatchStack.amount); - aOutputHatches.add(aNewHatchData); - // Check next fluid - continue; - } - - } else { - continue; - } - } - } - } - - for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) { - // Free Hatch - if (aFreeHatchCheck.getValue_2() == null || aFreeHatchCheck.getValue_3() == 0 - || aFreeHatchCheck.getValue_1().getFluid() == null) { - aEmptyFluidHatches++; - } - } - - // We have Fluid Stacks we did not merge. Do we have space? - log("fluids to output " + aOutputFluids.size() + " empty hatches " + aEmptyFluidHatches); - if (aOutputFluids.size() > 0) { - // Not enough space to add fluids. - if (aOutputFluids.size() > aEmptyFluidHatches) { - aParallelRecipes = (int) Math - .floor((double) aEmptyFluidHatches / aOutputFluids.size() * aParallelRecipes); - log( - "Failed to find enough space for all fluid outputs. Free: " + aEmptyFluidHatches - + ", Required: " - + aOutputFluids.size()); - return 0; - } - } - - /* - * End Fluid Management - */ - } - - return aParallelRecipes; - } - /* * Handle I/O with custom hatches */ @@ -661,6 +292,18 @@ public abstract class GregtechMeta_SteamMultiBase<T extends GregtechMeta_SteamMu } @Override + public List<ItemStack> getItemOutputSlots(ItemStack[] toOutput) { + List<ItemStack> ret = new ArrayList<>(); + for (final GT_MetaTileEntity_Hatch tBus : filterValidMetaTileEntities(mSteamOutputs)) { + final IInventory tBusInv = tBus.getBaseMetaTileEntity(); + for (int i = 0; i < tBusInv.getSizeInventory(); i++) { + ret.add(tBus.getStackInSlot(i)); + } + } + return ret; + } + + @Override public void updateSlots() { for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : mSteamInputFluids) if (isValidMetaTileEntity(tHatch)) tHatch.updateSlots(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java index d5607ae2e3..658a1db4a8 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java @@ -119,21 +119,4 @@ public class GregtechMetaTileEntity_SteamCompressor return GT_Recipe.GT_Recipe_Map.sCompressorRecipes; } - @Override - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[1]; - for (int h = 0; h < 1; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - @Override - public int getOutputCount(ItemStack[] aOutputs) { - return 1; - } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java index ad50d51c3a..0efa2d1220 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java @@ -123,21 +123,4 @@ public class GregtechMetaTileEntity_SteamMacerator return GT_Recipe.GT_Recipe_Map.sMaceratorRecipes; } - @Override - public ItemStack[] getOutputItems(GT_Recipe aRecipe) { - // Collect output item types - ItemStack[] tOutputItems = new ItemStack[1]; - for (int h = 0; h < 1; h++) { - if (aRecipe.getOutput(h) != null) { - tOutputItems[h] = aRecipe.getOutput(h).copy(); - tOutputItems[h].stackSize = 0; - } - } - return tOutputItems; - } - - @Override - public int getOutputCount(ItemStack[] aOutputs) { - return 1; - } } |