From e9f676e7a87f0bcb6f12d522bba57be8a8b121f9 Mon Sep 17 00:00:00 2001 From: Matthias Mann Date: Wed, 29 Apr 2015 21:26:05 +0200 Subject: [PATCH] #2345 remember the random chance value when the recipe couldn't be started --- .../machine/AbstractPoweredTaskEntity.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java index d22fcf50..1c995edb 100644 --- a/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java +++ b/src/main/java/crazypants/enderio/machine/AbstractPoweredTaskEntity.java @@ -9,7 +9,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import crazypants.enderio.machine.IMachineRecipe.ResultStack; -import crazypants.enderio.network.PacketHandler; import crazypants.enderio.power.IInternalPowerReceiver; import crazypants.util.IProgressTile; @@ -22,6 +21,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt protected int ticksSinceCheckedRecipe = 0; protected boolean startFailed = false; + protected float nextChance = Float.NaN; public AbstractPoweredTaskEntity(SlotDefinition slotDefinition) { super(slotDefinition); @@ -118,11 +118,20 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt } ticksSinceCheckedRecipe = 0; - float chance = random.nextFloat(); + // Get a new chance when we don't have one yet + // If a recipe could not be started we will try with the same chance next time + if(Float.isNaN(nextChance)) { + nextChance = random.nextFloat(); + } + // Then see if we need to start a new one - IMachineRecipe nextRecipe = canStartNextTask(chance); + IMachineRecipe nextRecipe = canStartNextTask(nextChance); if(nextRecipe != null) { - boolean started = startNextTask(nextRecipe, chance); + boolean started = startNextTask(nextRecipe, nextChance); + if(started) { + // this chance value has been used up + nextChance = Float.NaN; + } sendTaskProgressPacket(); startFailed = !started; } else { @@ -166,8 +175,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt lastCompletedRecipe = currentTask.getRecipe(); ResultStack[] output = currentTask.getCompletedResult(); if(output != null && output.length > 0) { - ResultStack[] results = currentTask.getCompletedResult(); - mergeResults(results); + mergeResults(output); } } markDirty();