Merge pull request #1710 from abel1502/abel-strand-caster

Improve strand caster
This commit is contained in:
HbmMods 2024-10-01 07:55:52 +02:00 committed by GitHub
commit a4e321f4c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,6 +35,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
public FluidTank water;
public FluidTank steam;
private long lastCastTick = 0;
public String getName() {
return "container.machineStrandCaster";
@ -81,31 +82,41 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
ItemMold.Mold mold = this.getInstalledMold();
if(canProcess()) {
int itemsCasted = Math.min(amount / mold.getCost(), 9);
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;
}
}
int minAmount = mold.getCost() * 9;
// Makes it flush the buffers after 10 seconds of inactivity
if(worldObj.getWorldTime() >= lastCastTick + 200) {
minAmount = mold.getCost();
}
markChanged();
water.setFill(water.getFill() - getWaterRequired() * itemsCasted);
steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted);
if(this.amount >= minAmount) {
int itemsCasted = amount / mold.getCost();
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();
}
}
}
@ -120,7 +131,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
public boolean canProcess() {
ItemMold.Mold mold = this.getInstalledMold();
if(type != null && mold != null && this.amount >= mold.getCost() * 9 && mold.getOutput(type) != null) {
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() && steam.getFill() < steam.getMaxFill();
@ -270,6 +281,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
super.writeToNBT(nbt);
water.writeToNBT(nbt, "w");
steam.writeToNBT(nbt, "s");
nbt.setLong("t", lastCastTick);
}
@Override
@ -277,6 +289,7 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
super.readFromNBT(nbt);
water.readFromNBT(nbt, "w");
steam.readFromNBT(nbt, "s");
lastCastTick = nbt.getLong("t");
}
@Override