From 82ca849f75cd6d4e3160c619b552b37ddd8dc1c4 Mon Sep 17 00:00:00 2001 From: GTNH-Colen <54497873+GTNH-Colen@users.noreply.github.com> Date: Wed, 21 Dec 2022 18:56:41 +0000 Subject: Fix recipe yield by changing shallow to deep copies of objects. --- .../technus/tectech/recipe/EyeOfHarmonyRecipe.java | 18 +++++++++++++++--- .../multi/GT_MetaTileEntity_EM_EyeOfHarmony.java | 20 ++++++++++---------- .../github/technus/tectech/util/ItemStackLong.java | 6 ++++++ 3 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java index 2ec4ffabb1..aa71c388d8 100644 --- a/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java +++ b/src/main/java/com/github/technus/tectech/recipe/EyeOfHarmonyRecipe.java @@ -67,12 +67,24 @@ public class EyeOfHarmonyRecipe { this.miningTimeSeconds = miningTimeSeconds; } - public List getOutputItems() { - return outputItems; + // Return clone of list. + public ArrayList getOutputItems() { + ArrayList copyOutputList = new ArrayList<>(); + for (ItemStackLong itemStackLong : outputItems) { + copyOutputList.add(new ItemStackLong(itemStackLong)); + } + + return copyOutputList; } public FluidStack[] getOutputFluids() { - return outputFluids; + ArrayList copyOutputList = new ArrayList<>(); + + for (FluidStack fluidStack : outputFluids) { + copyOutputList.add(fluidStack.copy()); + } + + return copyOutputList.toArray(new FluidStack[0]); } public long getHydrogenRequirement() { diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java index 8599a97432..72d9e80bf4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_EyeOfHarmony.java @@ -1694,8 +1694,8 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl public boolean processRecipe(EyeOfHarmonyRecipe recipeObject) { - if ((getHydrogenStored() < currentRecipe.getHydrogenRequirement()) - && (getHeliumStored() < currentRecipe.getHeliumRequirement())) { + // todo: fix changing the tier of block causing multi to unform + if ((getHydrogenStored() < currentRecipe.getHydrogenRequirement()) || (getHeliumStored() < currentRecipe.getHeliumRequirement())) { return false; } @@ -1731,18 +1731,18 @@ public class GT_MetaTileEntity_EM_EyeOfHarmony extends GT_MetaTileEntity_Multibl validFluidMap.put(Materials.Helium.getGas(1), 0L); double yield = recipeYieldCalculator(); - yield = 1; //todo debug, remove. successChance = 1; // todo debug, remove. - mOutputFluids = recipeObject.getOutputFluids().clone(); - - // Iterate over item output list and apply yield values. - for (ItemStackLong itemStack : recipeObject.getOutputItems()) { - itemStack.stackSize *= yield; - outputItems.add(itemStack); - } + // Return copies of the output objects. + mOutputFluids = recipeObject.getOutputFluids(); + outputItems = recipeObject.getOutputItems(); if (yield != 1.0) { + // Iterate over item output list and apply yield values. + for (ItemStackLong itemStackLong : outputItems) { + itemStackLong.stackSize *= yield; + } + // Iterate over fluid output list and apply yield values. for (FluidStack fluidStack : mOutputFluids) { fluidStack.amount *= yield; diff --git a/src/main/java/com/github/technus/tectech/util/ItemStackLong.java b/src/main/java/com/github/technus/tectech/util/ItemStackLong.java index e245cc94bf..68a7bafd04 100644 --- a/src/main/java/com/github/technus/tectech/util/ItemStackLong.java +++ b/src/main/java/com/github/technus/tectech/util/ItemStackLong.java @@ -11,4 +11,10 @@ public class ItemStackLong { this.itemStack = itemStack; this.stackSize = stackSize; } + + // Copy constructor. + public ItemStackLong(ItemStackLong itemStackLong) { + this.itemStack = itemStackLong.itemStack; + this.stackSize = itemStackLong.stackSize; + } } -- cgit