Merge pull request #2168 from abel1502/abel-strand-caster-fix

Strand caster fix
This commit is contained in:
HbmMods 2025-05-23 08:12:46 +02:00 committed by GitHub
commit 4fc41c631d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
@ -60,13 +61,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();
}
@ -76,65 +75,70 @@ 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 >= 9 || worldObj.getWorldTime() >= lastCastTick + 200)) {
if(mold != null) {
ItemMold.Mold mold = this.getInstalledMold();
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();
this.amount -= moldsToCast * mold.getCost();
ItemStack out = mold.getOutput(type);
int remaining = out.stackSize * moldsToCast;
final int maxStackSize = out.getMaxStackSize();
for (int i = 1; i < 7; i++) {
if (remaining <= 0) {
break;
}
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;
}
}
}
markChanged();
water.setFill(water.getFill() - getWaterRequired() * itemsCasted);
steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted);
lastCastTick = worldObj.getWorldTime();
if (slots[i] == null) {
slots[i] = new ItemStack(out.getItem(), 0, out.getItemDamage());
}
if (slots[i].isItemEqual(out)) {
int toDeposit = Math.min(remaining, maxStackSize - slots[i].stackSize);
slots[i].stackSize += toDeposit;
remaining -= toDeposit;
}
}
markChanged();
water.setFill(water.getFill() - getWaterRequired() * moldsToCast);
steam.setFill(steam.getFill() + getWaterRequired() * moldsToCast);
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 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 moldsToCast;
}
public DirPos[] getFluidConPos() {