Merge pull request #1948 from Dash1269/ntmain-rotaryfurnace-fix

Fix rotary furnace not saving output material
This commit is contained in:
HbmMods 2025-02-20 08:22:09 +01:00 committed by GitHub
commit c855f67cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,6 +12,7 @@ import com.hbm.inventory.gui.GUIMachineRotaryFurnace;
import com.hbm.inventory.material.MaterialShapes; import com.hbm.inventory.material.MaterialShapes;
import com.hbm.inventory.material.Mats; import com.hbm.inventory.material.Mats;
import com.hbm.inventory.material.Mats.MaterialStack; import com.hbm.inventory.material.Mats.MaterialStack;
import com.hbm.inventory.material.NTMMaterial;
import com.hbm.inventory.recipes.RotaryFurnaceRecipes; import com.hbm.inventory.recipes.RotaryFurnaceRecipes;
import com.hbm.inventory.recipes.RotaryFurnaceRecipes.RotaryFurnaceRecipe; import com.hbm.inventory.recipes.RotaryFurnaceRecipes.RotaryFurnaceRecipe;
import com.hbm.lib.Library; import com.hbm.lib.Library;
@ -42,7 +43,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable, IConditionalInvAccess { public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable, IConditionalInvAccess {
public FluidTank[] tanks; public FluidTank[] tanks;
public boolean isProgressing; public boolean isProgressing;
public float progress; public float progress;
@ -52,7 +53,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
public boolean isVenting; public boolean isVenting;
public MaterialStack output; public MaterialStack output;
public static final int maxOutput = MaterialShapes.BLOCK.q(16); public static final int maxOutput = MaterialShapes.BLOCK.q(16);
public int anim; public int anim;
public int lastAnim; public int lastAnim;
@ -71,12 +72,12 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
@Override @Override
public void updateEntity() { public void updateEntity() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
tanks[0].setType(3, slots); tanks[0].setType(3, slots);
for(DirPos pos : getSteamPos()) { for(DirPos pos : getSteamPos()) {
@ -86,16 +87,16 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
if(tanks[0].getTankType() != Fluids.NONE) for(DirPos pos : getFluidPos()) { if(tanks[0].getTankType() != Fluids.NONE) for(DirPos pos : getFluidPos()) {
this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
if(smoke.getFill() > 0) this.sendFluid(smoke, worldObj, xCoord + rot.offsetX, yCoord + 5, zCoord + rot.offsetZ, Library.POS_Y); if(smoke.getFill() > 0) this.sendFluid(smoke, worldObj, xCoord + rot.offsetX, yCoord + 5, zCoord + rot.offsetZ, Library.POS_Y);
if(this.output != null) { if(this.output != null) {
int prev = this.output.amount; int prev = this.output.amount;
Vec3 impact = Vec3.createVectorHelper(0, 0, 0); Vec3 impact = Vec3.createVectorHelper(0, 0, 0);
MaterialStack leftover = CrucibleUtil.pourSingleStack(worldObj, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 1.25D, zCoord + 0.5D + rot.offsetZ * 2.875D, 6, true, this.output, MaterialShapes.INGOT.q(1), impact); MaterialStack leftover = CrucibleUtil.pourSingleStack(worldObj, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 1.25D, zCoord + 0.5D + rot.offsetZ * 2.875D, 6, true, this.output, MaterialShapes.INGOT.q(1), impact);
this.output = leftover; this.output = leftover;
if(prev != this.output.amount) { if(prev != this.output.amount) {
this.output = leftover; this.output = leftover;
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
@ -107,31 +108,31 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
data.setFloat("len", Math.max(1F, yCoord + 1 - (float) (Math.ceil(impact.yCoord) - 1.125))); data.setFloat("len", Math.max(1F, yCoord + 1 - (float) (Math.ceil(impact.yCoord) - 1.125)));
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 0.75, zCoord + 0.5D + rot.offsetZ * 2.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50)); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 0.75, zCoord + 0.5D + rot.offsetZ * 2.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50));
} }
if(output.amount <= 0) this.output = null; if(output.amount <= 0) this.output = null;
} }
RotaryFurnaceRecipe recipe = RotaryFurnaceRecipes.getRecipe(slots[0], slots[1], slots[2]); RotaryFurnaceRecipe recipe = RotaryFurnaceRecipes.getRecipe(slots[0], slots[1], slots[2]);
this.isProgressing = false; this.isProgressing = false;
if(recipe != null) { if(recipe != null) {
if(this.burnTime <= 0 && slots[4] != null && TileEntityFurnace.isItemFuel(slots[4])) { if(this.burnTime <= 0 && slots[4] != null && TileEntityFurnace.isItemFuel(slots[4])) {
this.maxBurnTime = this.burnTime = TileEntityFurnace.getItemBurnTime(slots[4]) / 2; this.maxBurnTime = this.burnTime = TileEntityFurnace.getItemBurnTime(slots[4]) / 2;
this.decrStackSize(4, 1); this.decrStackSize(4, 1);
this.markChanged(); this.markChanged();
} }
if(this.canProcess(recipe)) { if(this.canProcess(recipe)) {
this.progress += 1F / recipe.duration; this.progress += 1F / recipe.duration;
tanks[1].setFill(tanks[1].getFill() - recipe.steam); tanks[1].setFill(tanks[1].getFill() - recipe.steam);
steamUsed += recipe.steam; steamUsed += recipe.steam;
this.isProgressing = true; this.isProgressing = true;
if(this.progress >= 1F) { if(this.progress >= 1F) {
this.progress -= 1F; this.progress -= 1F;
this.consumeItems(recipe); this.consumeItems(recipe);
if(this.output == null) { if(this.output == null) {
this.output = recipe.output.copy(); this.output = recipe.output.copy();
} else { } else {
@ -139,11 +140,11 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
} }
this.markDirty(); this.markDirty();
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
if(this.steamUsed >= 100) { if(this.steamUsed >= 100) {
int steamReturn = this.steamUsed / 100; int steamReturn = this.steamUsed / 100;
int canReturn = tanks[2].getMaxFill() - tanks[2].getFill(); int canReturn = tanks[2].getMaxFill() - tanks[2].getFill();
@ -151,28 +152,28 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
this.steamUsed -= doesReturn * 100; this.steamUsed -= doesReturn * 100;
tanks[2].setFill(tanks[2].getFill() + doesReturn); tanks[2].setFill(tanks[2].getFill() + doesReturn);
} }
} else { } else {
this.progress = 0; this.progress = 0;
} }
this.isVenting = false; this.isVenting = false;
if(this.burnTime > 0) { if(this.burnTime > 0) {
this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 10F); this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 10F);
this.burnTime--; this.burnTime--;
} }
this.networkPackNT(50); this.networkPackNT(50);
} else { } else {
if(this.burnTime > 0 && MainRegistry.proxy.me().getDistance(xCoord, yCoord, zCoord) < 25) { if(this.burnTime > 0 && MainRegistry.proxy.me().getDistance(xCoord, yCoord, zCoord) < 25) {
Random rand = worldObj.rand; Random rand = worldObj.rand;
worldObj.spawnParticle("flame", xCoord + 0.5 + dir.offsetX * 0.5 + rot.offsetX + rand.nextGaussian() * 0.25, yCoord + 0.375, zCoord + 0.5 + dir.offsetZ * 0.5 + rot.offsetZ + rand.nextGaussian() * 0.25, 0, 0, 0); worldObj.spawnParticle("flame", xCoord + 0.5 + dir.offsetX * 0.5 + rot.offsetX + rand.nextGaussian() * 0.25, yCoord + 0.375, zCoord + 0.5 + dir.offsetZ * 0.5 + rot.offsetZ + rand.nextGaussian() * 0.25, 0, 0, 0);
} }
if(isVenting && worldObj.getTotalWorldTime() % 2 == 0) { if(isVenting && worldObj.getTotalWorldTime() % 2 == 0) {
NBTTagCompound fx = new NBTTagCompound(); NBTTagCompound fx = new NBTTagCompound();
fx.setString("type", "tower"); fx.setString("type", "tower");
fx.setFloat("lift", 10F); fx.setFloat("lift", 10F);
@ -202,7 +203,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
buf.writeFloat(progress); buf.writeFloat(progress);
buf.writeInt(burnTime); buf.writeInt(burnTime);
buf.writeInt(maxBurnTime); buf.writeInt(maxBurnTime);
if(this.output != null) { if(this.output != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
buf.writeInt(this.output.material.id); buf.writeInt(this.output.material.id);
@ -211,7 +212,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
buf.writeBoolean(false); buf.writeBoolean(false);
} }
} }
@Override public void deserialize(ByteBuf buf) { @Override public void deserialize(ByteBuf buf) {
super.deserialize(buf); super.deserialize(buf);
tanks[0].deserialize(buf); tanks[0].deserialize(buf);
@ -222,14 +223,14 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
progress = buf.readFloat(); progress = buf.readFloat();
burnTime = buf.readInt(); burnTime = buf.readInt();
maxBurnTime = buf.readInt(); maxBurnTime = buf.readInt();
if(buf.readBoolean()) { if(buf.readBoolean()) {
this.output = new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt()); this.output = new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt());
} else { } else {
this.output = null; this.output = null;
} }
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@ -239,8 +240,12 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
this.progress = nbt.getFloat("prog"); this.progress = nbt.getFloat("prog");
this.burnTime = nbt.getInteger("burn"); this.burnTime = nbt.getInteger("burn");
this.maxBurnTime = nbt.getInteger("maxBurn"); this.maxBurnTime = nbt.getInteger("maxBurn");
if (nbt.hasKey("outType")) {
NTMMaterial mat = Mats.matById.get(nbt.getInteger("outType"));
this.output = new MaterialStack(mat, nbt.getInteger("outAmount"));
}
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
@ -250,32 +255,36 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
nbt.setFloat("prog", progress); nbt.setFloat("prog", progress);
nbt.setInteger("burn", burnTime); nbt.setInteger("burn", burnTime);
nbt.setInteger("maxBurn", maxBurnTime); nbt.setInteger("maxBurn", maxBurnTime);
if (this.output != null) {
nbt.setInteger("outType", this.output.material.id);
nbt.setInteger("outAmount", this.output.amount);
}
} }
public DirPos[] getSteamPos() { public DirPos[] getSteamPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 2, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 2, dir.getOpposite()),
new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite()) new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite())
}; };
} }
public DirPos[] getFluidPos() { public DirPos[] getFluidPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
return new DirPos[] { return new DirPos[] {
new DirPos(xCoord + dir.offsetX + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ + rot.offsetZ * 3, rot), new DirPos(xCoord + dir.offsetX + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ + rot.offsetZ * 3, rot),
new DirPos(xCoord - dir.offsetX + rot.offsetX * 3, yCoord, zCoord - dir.offsetZ + rot.offsetZ * 3, rot) new DirPos(xCoord - dir.offsetX + rot.offsetX * 3, yCoord, zCoord - dir.offsetZ + rot.offsetZ * 3, rot)
}; };
} }
public boolean canProcess(RotaryFurnaceRecipe recipe) { public boolean canProcess(RotaryFurnaceRecipe recipe) {
if(this.burnTime <= 0) return false; if(this.burnTime <= 0) return false;
if(recipe.fluid != null) { if(recipe.fluid != null) {
if(this.tanks[0].getTankType() != recipe.fluid.type) return false; if(this.tanks[0].getTankType() != recipe.fluid.type) return false;
if(this.tanks[0].getFill() < recipe.fluid.fill) return false; if(this.tanks[0].getFill() < recipe.fluid.fill) return false;
@ -284,19 +293,19 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
if(tanks[1].getFill() < recipe.steam) return false; if(tanks[1].getFill() < recipe.steam) return false;
if(tanks[2].getMaxFill() - tanks[2].getFill() < recipe.steam / 100) return false; if(tanks[2].getMaxFill() - tanks[2].getFill() < recipe.steam / 100) return false;
if(this.steamUsed > 100) return false; if(this.steamUsed > 100) return false;
if(this.output != null) { if(this.output != null) {
if(this.output.material != recipe.output.material) return false; if(this.output.material != recipe.output.material) return false;
if(this.output.amount + recipe.output.amount > this.maxOutput) return false; if(this.output.amount + recipe.output.amount > this.maxOutput) return false;
} }
return true; return true;
} }
public void consumeItems(RotaryFurnaceRecipe recipe) { public void consumeItems(RotaryFurnaceRecipe recipe) {
for(AStack aStack : recipe.ingredients) { for(AStack aStack : recipe.ingredients) {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
ItemStack stack = slots[i]; ItemStack stack = slots[i];
if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) { if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) {
@ -305,19 +314,19 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
} }
} }
} }
if(recipe.fluid != null) { if(recipe.fluid != null) {
this.tanks[0].setFill(tanks[0].getFill() - recipe.fluid.fill); this.tanks[0].setFill(tanks[0].getFill() - recipe.fluid.fill);
} }
} }
@Override @Override
public void pollute(PollutionType type, float amount) { public void pollute(PollutionType type, float amount) {
FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison; FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison;
int fluidAmount = (int) Math.ceil(amount * 100); int fluidAmount = (int) Math.ceil(amount * 100);
tank.setFill(tank.getFill() + fluidAmount); tank.setFill(tank.getFill() + fluidAmount);
if(tank.getFill() > tank.getMaxFill()) { if(tank.getFill() > tank.getMaxFill()) {
int overflow = tank.getFill() - tank.getMaxFill(); int overflow = tank.getFill() - tank.getMaxFill();
tank.setFill(tank.getMaxFill()); tank.setFill(tank.getMaxFill());
@ -332,12 +341,12 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
@Override public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) { return slot < 3 || slot == 4; } @Override public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) { return slot < 3 || slot == 4; }
@Override public boolean canExtractItem(int x, int y, int z, int slot, ItemStack stack, int side) { return false; } @Override public boolean canExtractItem(int x, int y, int z, int slot, ItemStack stack, int side) { return false; }
AxisAlignedBB bb = null; AxisAlignedBB bb = null;
@Override @Override
public AxisAlignedBB getRenderBoundingBox() { public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) { if(bb == null) {
bb = AxisAlignedBB.getBoundingBox( bb = AxisAlignedBB.getBoundingBox(
xCoord - 2, xCoord - 2,
@ -348,10 +357,10 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
zCoord + 3 zCoord + 3
); );
} }
return bb; return bb;
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() { public double getMaxRenderDistanceSquared() {
@ -364,7 +373,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP); ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
BlockPos core = new BlockPos(xCoord, yCoord, zCoord); BlockPos core = new BlockPos(xCoord, yCoord, zCoord);
//Red //Red
if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1).offset(rot, -2))) return new int[] {0}; if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1).offset(rot, -2))) return new int[] {0};
//Yellow //Yellow
@ -373,7 +382,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1))) return new int[] {2}; if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1))) return new int[] {2};
//Fuel //Fuel
if(side == dir.ordinal() && pos.equals(core.clone().offset(dir, 1).offset(rot, -1))) return new int[] {4}; if(side == dir.ordinal() && pos.equals(core.clone().offset(dir, 1).offset(rot, -1))) return new int[] {4};
return new int[] { }; return new int[] { };
} }