From 5a4f0bfa3d1826d9a5634baea76f90333d2ae628 Mon Sep 17 00:00:00 2001 From: BlueWeabo Date: Mon, 24 Jul 2023 19:11:34 +0300 Subject: Make Parallel Helper do better chanced output calculation for paralleled chanced recipes (#2130) * better calculation * roll for each parallel * skip rolling for recipes with chance at 100% * address not setting as null when stcksize is 0 --- .../java/gregtech/api/util/GT_ParallelHelper.java | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/main/java/gregtech') diff --git a/src/main/java/gregtech/api/util/GT_ParallelHelper.java b/src/main/java/gregtech/api/util/GT_ParallelHelper.java index 47b8ba17fb..07439967d3 100644 --- a/src/main/java/gregtech/api/util/GT_ParallelHelper.java +++ b/src/main/java/gregtech/api/util/GT_ParallelHelper.java @@ -413,19 +413,7 @@ public class GT_ParallelHelper { // If we want to calculate outputs we do it here if (mCalculateOutputs && mCurrentParallel > 0) { if (mRecipe.mOutputs != null) { - mItemOutputs = new ItemStack[mRecipe.mOutputs.length]; - for (int i = 0; i < mRecipe.mOutputs.length; i++) { - if (mRecipe.getOutputChance(i) >= XSTR.XSTR_INSTANCE.nextInt(10000)) { - if (mRecipe.getOutput(i) == null) { - mItemOutputs[i] = null; - } else { - ItemStack tItem = mRecipe.getOutput(i) - .copy(); - tItem.stackSize *= mCurrentParallel; - mItemOutputs[i] = tItem; - } - } - } + calculateItemOutputs(); } if (mRecipe.mFluidOutputs != null) { mFluidOutputs = new FluidStack[mRecipe.mFluidOutputs.length]; @@ -442,4 +430,32 @@ public class GT_ParallelHelper { } } } + + protected void calculateItemOutputs() { + mItemOutputs = new ItemStack[mRecipe.mOutputs.length]; + for (int i = 0; i < mRecipe.mOutputs.length; i++) { + if (mRecipe.getOutputChance(i) >= 10000) { + ItemStack item = mRecipe.getOutput(i) + .copy(); + item.stackSize *= mCurrentParallel; + mItemOutputs[i] = item; + continue; + } + int items = 0; + int itemStackSize = mRecipe.getOutput(i).stackSize; + for (int roll = 0; roll < mCurrentParallel; roll++) { + if (mRecipe.getOutputChance(i) >= XSTR.XSTR_INSTANCE.nextInt(10000)) { + items += itemStackSize; + } + } + ItemStack item = mRecipe.getOutput(i) + .copy(); + if (items == 0) { + item = null; + } else { + item.stackSize = items; + } + mItemOutputs[i] = item; + } + } } -- cgit