From 93638c3889e92781fd9468a1683060202130a84f Mon Sep 17 00:00:00 2001 From: abel1502 Date: Fri, 23 May 2025 00:40:45 +0300 Subject: [PATCH 1/4] Fix strand caster Also refactor it in the process, for good measure --- .../TileEntityMachineStrandCaster.java | 105 +++++++++--------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java index bc7eb46b6..56cc4629d 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java @@ -60,13 +60,11 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase this.lastAmount = this.amount; } - if(this.amount >= this.getCapacity()) { - // In case of overfill problems, spit out the excess as scrap - if(amount > getCapacity()) { - ItemStack scrap = ItemScraps.create(new Mats.MaterialStack(type, Math.max(amount - getCapacity(), 0))); - EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 2, zCoord + 0.5, scrap); - worldObj.spawnEntityInWorld(item); - } + // In case of overfill problems, spit out the excess as scrap + if(amount > getCapacity()) { + ItemStack scrap = ItemScraps.create(new Mats.MaterialStack(type, Math.max(amount - getCapacity(), 0))); + EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 2, zCoord + 0.5, scrap); + worldObj.spawnEntityInWorld(item); this.amount = this.getCapacity(); } @@ -78,63 +76,70 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase ItemMold.Mold mold = this.getInstalledMold(); - if(mold != null) { - - int itemsCasted = amount / mold.getCost(); - - if(canProcess(itemsCasted)) { - int minAmount = mold.getCost() * 9; - - // Makes it flush the buffers after 10 seconds of inactivity - if(worldObj.getWorldTime() >= lastCastTick + 200) { - minAmount = mold.getCost(); - } - - if(this.amount >= minAmount) { - - for(int j = 0; j < itemsCasted; j++) { - this.amount -= mold.getCost(); - - ItemStack out = mold.getOutput(type); - - for(int i = 1; i < 7; i++) { - if(slots[i] == null) { - slots[i] = out.copy(); - break; - } - - if(slots[i].isItemEqual(out) && slots[i].stackSize + out.stackSize <= out.getMaxStackSize()) { - slots[i].stackSize += out.stackSize; - break; - } - - } + if (mold != null) { + int itemsCasted = maxProcessable(); + + // Makes it flush the buffers after 10 seconds of inactivity, or when they're full + if (itemsCasted == 10 || worldObj.getWorldTime() >= lastCastTick + 200) { + + this.amount -= itemsCasted * mold.getCost(); + + ItemStack out = mold.getOutput(type); + int remaining = out.stackSize * itemsCasted; + out.stackSize = out.getMaxStackSize(); + + for (int i = 1; i < 7; i++) { + if (remaining <= 0) { + break; + } + + if (slots[i] == null) { + slots[i] = new ItemStack(out.getItem(), 0, out.getItemDamage()); + } + + if (slots[i].isItemEqual(out)) { + int toDeposit = Math.min(remaining, out.stackSize - slots[i].stackSize); + slots[i].stackSize += toDeposit; + remaining -= toDeposit; } - markChanged(); - - water.setFill(water.getFill() - getWaterRequired() * itemsCasted); - steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted); - - lastCastTick = worldObj.getWorldTime(); } + + markChanged(); + + water.setFill(water.getFill() - getWaterRequired() * itemsCasted); + steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted); } + + lastCastTick = worldObj.getWorldTime(); } networkPackNT(150); } } - public boolean canProcess(int itemsCasted) { + private int maxProcessable() { ItemMold.Mold mold = this.getInstalledMold(); - if(type != null && mold != null && mold.getOutput(type) != null) { - for(int i = 1; i < 7; i++) { - if(slots[i] == null || slots[i].isItemEqual(mold.getOutput(type)) && slots[i].stackSize + mold.getOutput(type).stackSize <= mold.getOutput(type).getMaxStackSize()) - return water.getFill() >= getWaterRequired() * itemsCasted && steam.getFill() + getWaterRequired() <= steam.getMaxFill(); + if (type == null || mold == null || mold.getOutput(type) != null) { + return 0; + } + int freeSlots = 0; + final int stackLimit = mold.getOutput(type).getMaxStackSize(); + + for (int i = 1; i < 7; i++) { + if (slots[i] == null) { + freeSlots += stackLimit; + } else if (slots[i].isItemEqual(mold.getOutput(type))) { + freeSlots += stackLimit - slots[i].stackSize; } } - return false; + int itemsCasted = amount / mold.getCost(); + itemsCasted = Math.min(itemsCasted, freeSlots / mold.getOutput(type).stackSize); + itemsCasted = Math.min(itemsCasted, water.getFill() / getWaterRequired()); + itemsCasted = Math.min(itemsCasted, (steam.getMaxFill() - steam.getFill()) / getWaterRequired()); + + return itemsCasted; } public DirPos[] getFluidConPos() { From 81ca498fa8019a9a3d0ab1871e8a896d04520d13 Mon Sep 17 00:00:00 2001 From: abel1502 Date: Fri, 23 May 2025 00:57:21 +0300 Subject: [PATCH 2/4] Fix strand caster 2: electric boogaloo Like, only cast if there is anything to cast, duh --- .../TileEntityMachineStrandCaster.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java index 56cc4629d..dbc955b2e 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java @@ -74,45 +74,43 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase this.updateConnections(); - ItemMold.Mold mold = this.getInstalledMold(); + int moldsToCast = maxProcessable(); + + // Makes it flush the buffers after 10 seconds of inactivity, or when they're full + if (moldsToCast > 0 && (moldsToCast == 10 || worldObj.getWorldTime() >= lastCastTick + 200)) { - if (mold != null) { - int itemsCasted = maxProcessable(); - - // Makes it flush the buffers after 10 seconds of inactivity, or when they're full - if (itemsCasted == 10 || worldObj.getWorldTime() >= lastCastTick + 200) { - - this.amount -= itemsCasted * mold.getCost(); + ItemMold.Mold mold = this.getInstalledMold(); + + this.amount -= moldsToCast * mold.getCost(); - ItemStack out = mold.getOutput(type); - int remaining = out.stackSize * itemsCasted; - out.stackSize = out.getMaxStackSize(); + ItemStack out = mold.getOutput(type); + int remaining = out.stackSize * moldsToCast; + out.stackSize = out.getMaxStackSize(); - for (int i = 1; i < 7; i++) { - if (remaining <= 0) { - break; - } - - if (slots[i] == null) { - slots[i] = new ItemStack(out.getItem(), 0, out.getItemDamage()); - } - - if (slots[i].isItemEqual(out)) { - int toDeposit = Math.min(remaining, out.stackSize - slots[i].stackSize); - slots[i].stackSize += toDeposit; - remaining -= toDeposit; - } + for (int i = 1; i < 7; i++) { + if (remaining <= 0) { + break; } - markChanged(); + if (slots[i] == null) { + slots[i] = new ItemStack(out.getItem(), 0, out.getItemDamage()); + } - water.setFill(water.getFill() - getWaterRequired() * itemsCasted); - steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted); + if (slots[i].isItemEqual(out)) { + int toDeposit = Math.min(remaining, out.stackSize - slots[i].stackSize); + slots[i].stackSize += toDeposit; + remaining -= toDeposit; + } } - lastCastTick = worldObj.getWorldTime(); + markChanged(); + + water.setFill(water.getFill() - getWaterRequired() * moldsToCast); + steam.setFill(steam.getFill() + getWaterRequired() * moldsToCast); } + lastCastTick = worldObj.getWorldTime(); + networkPackNT(150); } } @@ -134,12 +132,12 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase } } - int itemsCasted = amount / mold.getCost(); - itemsCasted = Math.min(itemsCasted, freeSlots / mold.getOutput(type).stackSize); - itemsCasted = Math.min(itemsCasted, water.getFill() / getWaterRequired()); - itemsCasted = Math.min(itemsCasted, (steam.getMaxFill() - steam.getFill()) / getWaterRequired()); + int moldsToCast = amount / mold.getCost(); + moldsToCast = Math.min(moldsToCast, freeSlots / mold.getOutput(type).stackSize); + moldsToCast = Math.min(moldsToCast, water.getFill() / getWaterRequired()); + moldsToCast = Math.min(moldsToCast, (steam.getMaxFill() - steam.getFill()) / getWaterRequired()); - return itemsCasted; + return moldsToCast; } public DirPos[] getFluidConPos() { From d3e839a9bb2dc41ad76c86ca60df776a2f1d8ffd Mon Sep 17 00:00:00 2001 From: abel1502 Date: Fri, 23 May 2025 01:08:27 +0300 Subject: [PATCH 3/4] Don't modify the out stack Just in case, IDK --- .../hbm/tileentity/machine/TileEntityMachineStrandCaster.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java index dbc955b2e..4155303d4 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java @@ -85,7 +85,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase ItemStack out = mold.getOutput(type); int remaining = out.stackSize * moldsToCast; - out.stackSize = out.getMaxStackSize(); + final int maxStackSize = out.getMaxStackSize(); for (int i = 1; i < 7; i++) { if (remaining <= 0) { @@ -97,7 +97,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase } if (slots[i].isItemEqual(out)) { - int toDeposit = Math.min(remaining, out.stackSize - slots[i].stackSize); + int toDeposit = Math.min(remaining, maxStackSize - slots[i].stackSize); slots[i].stackSize += toDeposit; remaining -= toDeposit; } From 41189e5f25c734e866e9fa5f773118835636ac25 Mon Sep 17 00:00:00 2001 From: abel1502 Date: Fri, 23 May 2025 01:42:12 +0300 Subject: [PATCH 4/4] I fixed it so good it stopped working But now it does again. I'm just silly like that sometimes --- .../machine/TileEntityMachineStrandCaster.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java index 4155303d4..84c56ab7c 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineStrandCaster.java @@ -11,6 +11,7 @@ import com.hbm.inventory.material.Mats; import com.hbm.items.ModItems; import com.hbm.items.machine.ItemMold; import com.hbm.items.machine.ItemScraps; +import com.hbm.main.MainRegistry; import com.hbm.tileentity.IGUIProvider; import com.hbm.util.fauxpointtwelve.DirPos; import cpw.mods.fml.relauncher.Side; @@ -77,7 +78,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase int moldsToCast = maxProcessable(); // Makes it flush the buffers after 10 seconds of inactivity, or when they're full - if (moldsToCast > 0 && (moldsToCast == 10 || worldObj.getWorldTime() >= lastCastTick + 200)) { + if (moldsToCast > 0 && (moldsToCast >= 9 || worldObj.getWorldTime() >= lastCastTick + 200)) { ItemMold.Mold mold = this.getInstalledMold(); @@ -107,9 +108,9 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase water.setFill(water.getFill() - getWaterRequired() * moldsToCast); steam.setFill(steam.getFill() + getWaterRequired() * moldsToCast); - } - lastCastTick = worldObj.getWorldTime(); + lastCastTick = worldObj.getWorldTime(); + } networkPackNT(150); } @@ -117,7 +118,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase private int maxProcessable() { ItemMold.Mold mold = this.getInstalledMold(); - if (type == null || mold == null || mold.getOutput(type) != null) { + if (type == null || mold == null || mold.getOutput(type) == null) { return 0; }