diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 18:49:30 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2022-01-29 18:49:30 +0000 |
commit | b926dfb3bc67b74b53749a3e420a8a6ce0fba6a7 (patch) | |
tree | 2aee4a9cb0c803e0104e5baf6c4810b9f4020c0f /src/main/java/gtPlusPlus | |
parent | e77484a62ce2a5c20a6c731147aed7f38098f35d (diff) | |
download | GT5-Unofficial-b926dfb3bc67b74b53749a3e420a8a6ce0fba6a7.tar.gz GT5-Unofficial-b926dfb3bc67b74b53749a3e420a8a6ce0fba6a7.tar.bz2 GT5-Unofficial-b926dfb3bc67b74b53749a3e420a8a6ce0fba6a7.zip |
Overhauled Matter Fabricator CPU.
Diffstat (limited to 'src/main/java/gtPlusPlus')
4 files changed, 448 insertions, 90 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_MatterFab.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_MatterFab.java index 808eb90728..93591b2aaf 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_MatterFab.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/CONTAINER_MatterFab.java @@ -1,11 +1,15 @@ package gtPlusPlus.xmod.gregtech.api.gui; -import net.minecraft.entity.player.InventoryPlayer; +import java.util.Iterator; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.gui.GT_ContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntity_MassFabricator; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -13,9 +17,12 @@ import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.Gr * The Container I use for all my Basic Machines */ public class CONTAINER_MatterFab extends GT_ContainerMetaTile_Machine { - - public int mUUA_USED = ((GregtechMetaTileEntity_MassFabricator)this.mTileEntity.getMetaTileEntity()).getAmplifierUsed(); - public int mUUM_MADE = ((GregtechMetaTileEntity_MassFabricator)this.mTileEntity.getMetaTileEntity()).getMatterProduced(); + + public int mMatterProduced = 0; + public int mScrapProduced = 0; + public int mAmplifierProduced = 0; + public int mScrapUsed = 0; + public int mAmplifierUsed = 0; public CONTAINER_MatterFab(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity) { super(aInventoryPlayer, aTileEntity); @@ -39,4 +46,58 @@ public class CONTAINER_MatterFab extends GT_ContainerMetaTile_Machine { public int getShiftClickSlotCount() { return 0; } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) { + return; + } + GregtechMetaTileEntity_MassFabricator aTile = ((GregtechMetaTileEntity_MassFabricator)this.mTileEntity.getMetaTileEntity()); + + mAmplifierProduced = aTile.mAmplifierProduced; + mAmplifierUsed = aTile.mAmplifierUsed; + mMatterProduced = aTile.mMatterProduced; + mScrapProduced = aTile.mScrapProduced; + mScrapUsed = aTile.mScrapUsed; + + Iterator var2 = this.crafters.iterator(); + while (var2.hasNext()) { + ICrafting var1 = (ICrafting) var2.next(); + var1.sendProgressBarUpdate(this, 201, mAmplifierProduced); + var1.sendProgressBarUpdate(this, 202, mAmplifierUsed); + var1.sendProgressBarUpdate(this, 203, mMatterProduced); + var1.sendProgressBarUpdate(this, 204, mScrapProduced); + var1.sendProgressBarUpdate(this, 205, mScrapUsed); + } + } + + @Override + public void addCraftingToCrafters(ICrafting par1ICrafting) { + super.addCraftingToCrafters(par1ICrafting); + } + + @Override + @SideOnly(Side.CLIENT) + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 201: + mAmplifierProduced = (par2); + break; + case 202: + mAmplifierUsed = (par2); + break; + case 203: + mMatterProduced = (par2); + break; + case 204: + mScrapProduced = (par2); + break; + case 205: + mScrapUsed = (par2); + break; + } + } + } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GUI_MatterFab.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GUI_MatterFab.java index 95bde9fd9f..653a177285 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GUI_MatterFab.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/GUI_MatterFab.java @@ -5,7 +5,7 @@ import net.minecraft.entity.player.InventoryPlayer; import gregtech.api.gui.GT_GUIContainerMetaTile_Machine; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; - +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.lib.CORE; /** @@ -18,8 +18,11 @@ import gtPlusPlus.core.lib.CORE; public class GUI_MatterFab extends GT_GUIContainerMetaTile_Machine { String mName = ""; - int uuaUsed = 0; - int uumMade = 0; + public int mMatterProduced = 0; + public int mScrapProduced = 0; + public int mAmplifierProduced = 0; + public int mScrapUsed = 0; + public int mAmplifierUsed = 0; public GUI_MatterFab(final InventoryPlayer aInventoryPlayer, final IGregTechTileEntity aTileEntity, final String aName, final String aTextureFile) { super(new CONTAINER_MatterFab(aInventoryPlayer, aTileEntity), CORE.RES_PATH_GUI + (aTextureFile == null ? "MultiblockDisplay" : aTextureFile)); @@ -61,11 +64,21 @@ public class GUI_MatterFab extends GT_GUIContainerMetaTile_Machine { this.fontRendererObj.drawString("to (re-)start the Machine", 10, 24, 16448255); this.fontRendererObj.drawString("if it doesn't start.", 10, 32, 16448255); } else { - this.uuaUsed = ((CONTAINER_MatterFab) this.mContainer).mUUA_USED; - this.uumMade = ((CONTAINER_MatterFab) this.mContainer).mUUM_MADE; + CONTAINER_MatterFab aContainer = (CONTAINER_MatterFab) this.mContainer; + + this.mMatterProduced = aContainer.mMatterProduced; + this.mAmplifierProduced = aContainer.mAmplifierProduced; + this.mAmplifierUsed = aContainer.mAmplifierUsed; + this.mScrapProduced = aContainer.mScrapProduced; + this.mScrapUsed = aContainer.mScrapUsed; + this.fontRendererObj.drawString("Running perfectly.", 10, 16, 16448255); - this.fontRendererObj.drawString("UU-Amplifier Used: "+this.uuaUsed, 10, 24, 16448255); - this.fontRendererObj.drawString("UU-Matter Fabricated: "+this.uumMade, 10, 32, 16448255); + + this.fontRendererObj.drawString("Scrap Produced: "+this.mScrapProduced, 10, 32, 16448255); + this.fontRendererObj.drawString("Scrap Used: "+this.mScrapUsed, 10, 40, 16448255); + this.fontRendererObj.drawString("UU-Amplifier Produced: "+this.mAmplifierProduced, 10, 48, 16448255); + this.fontRendererObj.drawString("UU-Amplifier Used: "+this.mAmplifierUsed, 10, 56, 16448255); + this.fontRendererObj.drawString("UU-Matter Fabricated: "+this.mMatterProduced, 10, 64, 16448255); } } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/basic/CONTAINER_PollutionCleaner.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/basic/CONTAINER_PollutionCleaner.java index 79d1033bd0..e4dc7835cb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/basic/CONTAINER_PollutionCleaner.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/gui/basic/CONTAINER_PollutionCleaner.java @@ -58,6 +58,7 @@ public class CONTAINER_PollutionCleaner extends GT_Container_BasicTank { super.detectAndSendChanges(); if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return; + Logger.INFO("TEST"); mReduction = ((GregtechMetaAtmosphericReconditioner) mTileEntity.getMetaTileEntity()).mPollutionReduction; Iterator var2 = this.crafters.iterator(); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java index f016288547..31fcc41cf4 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java @@ -1,8 +1,5 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; -import java.util.ArrayList; -import java.util.Collection; - import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.StructureDefinition; import gregtech.api.enums.ConfigCategories; @@ -17,14 +14,17 @@ import gregtech.api.metatileentity.implementations.*; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.*; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; +import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.util.minecraft.ItemUtils; -import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.*; +import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MatterFab; import gtPlusPlus.xmod.gregtech.api.gui.GUI_MatterFab; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import ic2.core.Ic2Items; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; @@ -34,6 +34,11 @@ import net.minecraftforge.fluids.FluidStack; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.*; + +import org.apache.commons.lang3.ArrayUtils; public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlockBase { @@ -41,11 +46,11 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo public static int sUUASpeedBonus = 4; public static int sDurationMultiplier = 3200; - private int mMatterProduced = 0; - private int mScrapProduced = 0; - private int mAmplifierProduced = 0; - private int mScrapUsed = 0; - private int mAmplifierUsed = 0; + public int mMatterProduced = 0; + public int mScrapProduced = 0; + public int mAmplifierProduced = 0; + public int mScrapUsed = 0; + public int mAmplifierUsed = 0; public static String mCasingName1 = "Matter Fabricator Casing"; public static String mCasingName2 = "Containment Casing"; @@ -71,6 +76,10 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo return this.mMatterProduced; } + public int getScrapProduced(){ + return this.mScrapProduced; + } + public GregtechMetaTileEntity_MassFabricator(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); mCasingName1 = ItemUtils.getLocalizedNameOfBlock(ModBlocks.blockCasingsMisc, 9); @@ -144,25 +153,17 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo return "MatterFabricator"; } - public static ItemStack getScrapPile() { - if (mScrap[0] == null) { - mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); - } - return mScrap[0]; - } - public static ItemStack getScrapBox() { - if (mScrap[1] == null) { - mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); - } - return mScrap[1]; - } - @Override public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) { return new GUI_MatterFab(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), "MatterFabricator.png"); } @Override + public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { + return new CONTAINER_MatterFab(aPlayerInventory, aBaseMetaTileEntity); + } + + @Override public void onConfigLoad(final GT_Config aConfig) { super.onConfigLoad(aConfig); sDurationMultiplier = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); @@ -178,9 +179,30 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo ArrayList<FluidStack> tFluids = getStoredFluids(); ItemStack[] tItemInputs = tItems.toArray(new ItemStack[tItems.size()]); FluidStack[] tFluidInputs = tFluids.toArray(new FluidStack[tFluids.size()]); + init(); return checkRecipeGeneric(tItemInputs, tFluidInputs, 4, 80, 00, 100); } + public static boolean sInit = false; + + public static void init() { + if (!sInit) { + if (mScrap[0] == null) { + mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); + } + if (mScrap[1] == null) { + mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); + } + if (mUU[0] == null) { + mUU[0] = Materials.UUAmplifier.getFluid(100); + } + if (mUU[1] == null) { + mUU[1] = Materials.UUMatter.getFluid(100); + } + sInit = true; + } + } + @Override public IStructureDefinition<GregtechMetaTileEntity_MassFabricator> getStructureDefinition() { if (STRUCTURE_DEFINITION == null) { @@ -282,28 +304,6 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo return new GregtechMetaTileEntity_MassFabricator(this.mName); } - public boolean doesHatchContainUUA() { - if (mUU[0] == null) { - mUU[0] = Materials.UUAmplifier.getFluid(100); - } - if (mUU[1] == null) { - mUU[1] = Materials.UUMatter.getFluid(100); - } - - if (mUU[0] != null && mUU[1] != null) { - for (GT_MetaTileEntity_Hatch_Input g : this.mInputHatches) { - if (g.getFluid() != null) { - if (g.mFluid.isFluidEqual(mUU[0])) { - return true; - } - } - } - } - - return false; - } - - /** * Special Recipe Handling */ @@ -316,49 +316,332 @@ public class GregtechMetaTileEntity_MassFabricator extends GregtechMeta_MultiBlo } @Override - public boolean checkRecipeGeneric( + public boolean checkRecipeGeneric(ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, int aEUPercent, int aSpeedBonusPercent, int aOutputChanceRoll) { + if (this.mMode == MODE_SCRAP) { + return checkRecipeScrap(aItemInputs, aFluidInputs, getMaxParallelRecipes(), aEUPercent, aSpeedBonusPercent, aOutputChanceRoll); + } + else { + return checkRecipeUU(aItemInputs, aFluidInputs, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll); + } + } + + public boolean checkRecipeScrap( + ItemStack[] aItemInputs, FluidStack[] aFluidInputs, + int aMaxParallelRecipes, int aEUPercent, + int aSpeedBonusPercent, int aOutputChanceRoll) { + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + ItemStack aPotentialOutput = GT_ModHandler.getRecyclerOutput(GT_Utility.copyAmount(1, aItemInputs[0]), 0); + GT_Recipe tRecipe = new GTPP_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(1, aItemInputs[0])}, aPotentialOutput == null ? null : new ItemStack[]{aPotentialOutput}, null, new int[]{2000}, null, null, 40, MaterialUtils.getVoltageForTier(1), 0); + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + int parallelRecipes = 0; + // Count recipes to do in parallel, consuming input items and fluids and + // considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { + break; + } + log("Bumped EU from " + tTotalEUt + " to " + (tTotalEUt + tRecipeEUt) + ". "); + tTotalEUt += tRecipeEUt; + } + log("Broke at " + parallelRecipes + "."); + if (parallelRecipes > 0) { + // -- 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); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int) (tRecipe.mDuration * tTimeFactor); + this.mEUt = (int) Math.ceil(tTotalEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } + else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; + } + } + } + tOutputItems = removeNulls(tOutputItems); + for (ItemStack aOutputStack : tOutputItems) { + if (aOutputStack != null) { + mScrapProduced += aOutputStack.stackSize; + } + } + // Sanitize item stack size, splitting any stacks greater than max + // stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); + } + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) + tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + // Commit outputs + this.mOutputItems = tOutputItems; + updateSlots(); + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + log("" + mScrapProduced); + return true; + } + return false; + } + + public boolean checkRecipeUU( ItemStack[] aItemInputs, FluidStack[] aFluidInputs, int aMaxParallelRecipes, int aEUPercent, - int aSpeedBonusPercent, int aOutputChanceRoll) { + int aSpeedBonusPercent, int aOutputChanceRoll) { - if (this.mMode == MODE_SCRAP) { - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - long tEnergy = getMaxInputEnergy(); - GT_Recipe c = new GTPP_Recipe(false, new ItemStack[] { GT_Utility.copyAmount(1, aItemInputs[0]) }, - GT_ModHandler.getRecyclerOutput(GT_Utility.copyAmount(64, aItemInputs[0]), 0) == null ? null - : new ItemStack[] { ItemList.IC2_Scrap.get(1) }, - null, new int[] { 2000 }, null, null, 100, - (int) gregtech.api.enums.GT_Values.V[2], 0); - - // EU discount - float tRecipeEUt = (c.mEUt * aEUPercent) / 100.0f; - float tTotalEUt = 0.0f; - - int parallelRecipes = 0; - // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits - for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { - if (!c.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) { - log("Broke at "+parallelRecipes+"."); - break; + // 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[]{}; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + long tEnergy = getMaxInputEnergy(); + log("Running checkRecipeGeneric(0)"); + + GT_Recipe tRecipe = findRecipe( + getBaseMetaTileEntity(), mLastRecipe, false, + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + + log("Running checkRecipeGeneric(1)"); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + if (tRecipe == null) { + log("BAD RETURN - 1"); + return false; + } + + aMaxParallelRecipes = this.canBufferOutputs(tRecipe, aMaxParallelRecipes); + if (aMaxParallelRecipes == 0) { + log("BAD RETURN - 2"); + return false; + } + + // EU discount + float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; + float tTotalEUt = 0.0f; + + int parallelRecipes = 0; + + log("parallelRecipes: "+parallelRecipes); + log("aMaxParallelRecipes: "+aMaxParallelRecipes); + log("tTotalEUt: "+tTotalEUt); + log("tVoltage: "+tVoltage); + log("tRecipeEUt: "+tRecipeEUt); + // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits + for (; parallelRecipes < aMaxParallelRecipes && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) { + if (!tRecipe.isRecipeInputEqual(true, true, aFluidInputs, aItemInputs)) { + log("Broke at "+parallelRecipes+"."); + break; + } + log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); + tTotalEUt += tRecipeEUt; + } + + if (parallelRecipes == 0) { + log("BAD RETURN - 3"); + 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); + float tTimeFactor = 100.0f / (100.0f + aSpeedBonusPercent); + this.mMaxProgresstime = (int)(tRecipe.mDuration * tTimeFactor); + + this.mEUt = (int)Math.ceil(tTotalEUt); + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + // Overclock + if (this.mEUt <= 16) { + this.mEUt = (this.mEUt * (1 << tTier - 1) * (1 << tTier - 1)); + this.mMaxProgresstime = (this.mMaxProgresstime / (1 << tTier - 1)); + } else { + while (this.mEUt <= gregtech.api.enums.GT_Values.V[(tTier - 1)]) { + this.mEUt *= 4; + this.mMaxProgresstime /= 4; + } + } + + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); + } + + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + + // Collect fluid outputs + FluidStack[] tOutputFluids = new FluidStack[tRecipe.mFluidOutputs.length]; + for (int h = 0; h < tRecipe.mFluidOutputs.length; h++) { + if (tRecipe.getFluidOutput(h) != null) { + tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); + tOutputFluids[h].amount *= parallelRecipes; + } + } + + // Collect output item types + ItemStack[] tOutputItems = new ItemStack[tRecipe.mOutputs.length]; + for (int h = 0; h < tRecipe.mOutputs.length; h++) { + if (tRecipe.getOutput(h) != null) { + tOutputItems[h] = tRecipe.getOutput(h).copy(); + tOutputItems[h].stackSize = 0; + } + } + + // Set output item stack sizes (taking output chance into account) + for (int f = 0; f < tOutputItems.length; f++) { + if (tRecipe.mOutputs[f] != null && tOutputItems[f] != null) { + for (int g = 0; g < parallelRecipes; g++) { + if (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) < tRecipe.getOutputChance(f)) + tOutputItems[f].stackSize += tRecipe.mOutputs[f].stackSize; } - log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); - tTotalEUt += tRecipeEUt; } + } - if (parallelRecipes == 0) { - this.mEUt = (int) gregtech.api.enums.GT_Values.V[tTier]; - this.mMaxProgresstime = 10; - return true; + tOutputItems = removeNulls(tOutputItems); + + + int aMatterProduced = 0; + int aAmplifierProduced = 0; + int aScrapUsed = 0; + int aAmplifierUsed = 0; + + for (int i=0; i<parallelRecipes; i++) { + //Logger.INFO("Trying to bump stats "+i); + for (ItemStack aInput : tRecipe.mInputs) { + if (aInput != null && GT_Utility.areStacksEqual(aInput, mScrap[0], true)) { + aScrapUsed += aInput.stackSize; + //Logger.INFO("Found Scrap to use."); + } + } + for (FluidStack aInput : tRecipe.mFluidInputs) { + if (aInput != null && GT_Utility.areFluidsEqual(aInput, mUU[0], true)) { + aAmplifierUsed += aInput.amount; + //Logger.INFO("Found UU-A to use."); + } } - - return super.checkRecipeGeneric(c, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll, true); + for (FluidStack aOutput : tRecipe.mFluidOutputs) { + if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[0], true)) { + aAmplifierProduced += aOutput.amount; + //Logger.INFO("Found UU-A as Output."); + } + if (aOutput != null && GT_Utility.areFluidsEqual(aOutput, mUU[1], true)) { + aMatterProduced += aOutput.amount; + //Logger.INFO("Found UU-M as Output."); + } + } + } + + this.mMatterProduced += aMatterProduced; + this.mAmplifierProduced += aAmplifierProduced; + this.mScrapUsed += aScrapUsed; + this.mAmplifierUsed += aAmplifierUsed; + + // Sanitize item stack size, splitting any stacks greater than max stack size + List<ItemStack> splitStacks = new ArrayList<ItemStack>(); + for (ItemStack tItem : tOutputItems) { + while (tItem.getMaxStackSize() < tItem.stackSize) { + ItemStack tmp = tItem.copy(); + tmp.stackSize = tmp.getMaxStackSize(); + tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize(); + splitStacks.add(tmp); + } + } + + if (splitStacks.size() > 0) { + ItemStack[] tmp = new ItemStack[splitStacks.size()]; + tmp = splitStacks.toArray(tmp); + tOutputItems = ArrayUtils.addAll(tOutputItems, tmp); } + + // Strip empty stacks + List<ItemStack> tSList = new ArrayList<ItemStack>(); + for (ItemStack tS : tOutputItems) { + if (tS.stackSize > 0) tSList.add(tS); + } + tOutputItems = tSList.toArray(new ItemStack[tSList.size()]); + + // Commit outputs + this.mOutputItems = tOutputItems; + this.mOutputFluids = tOutputFluids; - //Return normal Recipe handling - return super.checkRecipeGeneric(aItemInputs, aFluidInputs, getMaxParallelRecipes(), getEuDiscountForParallelism(), aSpeedBonusPercent, aOutputChanceRoll, true); - } + updateSlots(); + + // Play sounds (GT++ addition - GT multiblocks play no sounds) + startProcess(); + + log("GOOD RETURN - 1"); + return true; + + } @Override public int getMaxParallelRecipes() { |