mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-02-24 15:00:48 +00:00
Fix strand caster
Also refactor it in the process, for good measure
This commit is contained in:
parent
6a7dabbb1e
commit
93638c3889
@ -60,13 +60,11 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
|
|||||||
this.lastAmount = this.amount;
|
this.lastAmount = this.amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.amount >= this.getCapacity()) {
|
// In case of overfill problems, spit out the excess as scrap
|
||||||
// In case of overfill problems, spit out the excess as scrap
|
if(amount > getCapacity()) {
|
||||||
if(amount > getCapacity()) {
|
ItemStack scrap = ItemScraps.create(new Mats.MaterialStack(type, Math.max(amount - getCapacity(), 0)));
|
||||||
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);
|
||||||
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 2, zCoord + 0.5, scrap);
|
worldObj.spawnEntityInWorld(item);
|
||||||
worldObj.spawnEntityInWorld(item);
|
|
||||||
}
|
|
||||||
this.amount = this.getCapacity();
|
this.amount = this.getCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,63 +76,70 @@ public class TileEntityMachineStrandCaster extends TileEntityFoundryCastingBase
|
|||||||
|
|
||||||
ItemMold.Mold mold = this.getInstalledMold();
|
ItemMold.Mold mold = this.getInstalledMold();
|
||||||
|
|
||||||
if(mold != null) {
|
if (mold != null) {
|
||||||
|
int itemsCasted = maxProcessable();
|
||||||
int itemsCasted = amount / mold.getCost();
|
|
||||||
|
// Makes it flush the buffers after 10 seconds of inactivity, or when they're full
|
||||||
if(canProcess(itemsCasted)) {
|
if (itemsCasted == 10 || worldObj.getWorldTime() >= lastCastTick + 200) {
|
||||||
int minAmount = mold.getCost() * 9;
|
|
||||||
|
this.amount -= itemsCasted * mold.getCost();
|
||||||
// Makes it flush the buffers after 10 seconds of inactivity
|
|
||||||
if(worldObj.getWorldTime() >= lastCastTick + 200) {
|
ItemStack out = mold.getOutput(type);
|
||||||
minAmount = mold.getCost();
|
int remaining = out.stackSize * itemsCasted;
|
||||||
}
|
out.stackSize = out.getMaxStackSize();
|
||||||
|
|
||||||
if(this.amount >= minAmount) {
|
for (int i = 1; i < 7; i++) {
|
||||||
|
if (remaining <= 0) {
|
||||||
for(int j = 0; j < itemsCasted; j++) {
|
break;
|
||||||
this.amount -= mold.getCost();
|
}
|
||||||
|
|
||||||
ItemStack out = mold.getOutput(type);
|
if (slots[i] == null) {
|
||||||
|
slots[i] = new ItemStack(out.getItem(), 0, out.getItemDamage());
|
||||||
for(int i = 1; i < 7; i++) {
|
}
|
||||||
if(slots[i] == null) {
|
|
||||||
slots[i] = out.copy();
|
if (slots[i].isItemEqual(out)) {
|
||||||
break;
|
int toDeposit = Math.min(remaining, out.stackSize - slots[i].stackSize);
|
||||||
}
|
slots[i].stackSize += toDeposit;
|
||||||
|
remaining -= toDeposit;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markChanged();
|
||||||
|
|
||||||
|
water.setFill(water.getFill() - getWaterRequired() * itemsCasted);
|
||||||
|
steam.setFill(steam.getFill() + getWaterRequired() * itemsCasted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastCastTick = worldObj.getWorldTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
networkPackNT(150);
|
networkPackNT(150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canProcess(int itemsCasted) {
|
private int maxProcessable() {
|
||||||
ItemMold.Mold mold = this.getInstalledMold();
|
ItemMold.Mold mold = this.getInstalledMold();
|
||||||
if(type != null && mold != null && mold.getOutput(type) != null) {
|
if (type == null || mold == null || mold.getOutput(type) != null) {
|
||||||
for(int i = 1; i < 7; i++) {
|
return 0;
|
||||||
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();
|
|
||||||
|
|
||||||
|
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() {
|
public DirPos[] getFluidConPos() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user