Skip to content

Commit

Permalink
Merge pull request #1948 from Dash1269/ntmain-rotaryfurnace-fix
Browse files Browse the repository at this point in the history
Fix rotary furnace not saving output material
  • Loading branch information
HbmMods authored Feb 20, 2025
2 parents 4fd9d5b + b28cb31 commit c855f67
Showing 1 changed file with 61 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.hbm.inventory.material.MaterialShapes;
import com.hbm.inventory.material.Mats;
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.RotaryFurnaceRecipe;
import com.hbm.lib.Library;
Expand Down Expand Up @@ -42,7 +43,7 @@
import net.minecraftforge.common.util.ForgeDirection;

public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable, IConditionalInvAccess {

public FluidTank[] tanks;
public boolean isProgressing;
public float progress;
Expand All @@ -52,7 +53,7 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
public boolean isVenting;
public MaterialStack output;
public static final int maxOutput = MaterialShapes.BLOCK.q(16);

public int anim;
public int lastAnim;

Expand All @@ -71,12 +72,12 @@ public String getName() {

@Override
public void updateEntity() {

ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);

if(!worldObj.isRemote) {

tanks[0].setType(3, slots);

for(DirPos pos : getSteamPos()) {
Expand All @@ -86,16 +87,16 @@ public void updateEntity() {
if(tanks[0].getTankType() != Fluids.NONE) for(DirPos pos : getFluidPos()) {
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(this.output != null) {

int prev = this.output.amount;
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);
this.output = leftover;

if(prev != this.output.amount) {
this.output = leftover;
NBTTagCompound data = new NBTTagCompound();
Expand All @@ -107,72 +108,72 @@ public void updateEntity() {
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));
}

if(output.amount <= 0) this.output = null;
}

RotaryFurnaceRecipe recipe = RotaryFurnaceRecipes.getRecipe(slots[0], slots[1], slots[2]);
this.isProgressing = false;

if(recipe != null) {

if(this.burnTime <= 0 && slots[4] != null && TileEntityFurnace.isItemFuel(slots[4])) {
this.maxBurnTime = this.burnTime = TileEntityFurnace.getItemBurnTime(slots[4]) / 2;
this.decrStackSize(4, 1);
this.markChanged();
}

if(this.canProcess(recipe)) {
this.progress += 1F / recipe.duration;
tanks[1].setFill(tanks[1].getFill() - recipe.steam);
steamUsed += recipe.steam;
this.isProgressing = true;

if(this.progress >= 1F) {
this.progress -= 1F;
this.consumeItems(recipe);

if(this.output == null) {
this.output = recipe.output.copy();
} else {
this.output.amount += recipe.output.amount;
}
this.markDirty();
}

} else {
this.progress = 0;
}

if(this.steamUsed >= 100) {
int steamReturn = this.steamUsed / 100;
int canReturn = tanks[2].getMaxFill() - tanks[2].getFill();
int doesReturn = Math.min(steamReturn, canReturn);
this.steamUsed -= doesReturn * 100;
tanks[2].setFill(tanks[2].getFill() + doesReturn);
}

} else {
this.progress = 0;
}

this.isVenting = false;
if(this.burnTime > 0) {
this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 10F);
this.burnTime--;
}

this.networkPackNT(50);

} else {

if(this.burnTime > 0 && MainRegistry.proxy.me().getDistance(xCoord, yCoord, zCoord) < 25) {
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);
}

if(isVenting && worldObj.getTotalWorldTime() % 2 == 0) {

NBTTagCompound fx = new NBTTagCompound();
fx.setString("type", "tower");
fx.setFloat("lift", 10F);
Expand Down Expand Up @@ -202,7 +203,7 @@ public void updateEntity() {
buf.writeFloat(progress);
buf.writeInt(burnTime);
buf.writeInt(maxBurnTime);

if(this.output != null) {
buf.writeBoolean(true);
buf.writeInt(this.output.material.id);
Expand All @@ -211,7 +212,7 @@ public void updateEntity() {
buf.writeBoolean(false);
}
}

@Override public void deserialize(ByteBuf buf) {
super.deserialize(buf);
tanks[0].deserialize(buf);
Expand All @@ -222,14 +223,14 @@ public void updateEntity() {
progress = buf.readFloat();
burnTime = buf.readInt();
maxBurnTime = buf.readInt();

if(buf.readBoolean()) {
this.output = new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt());
} else {
this.output = null;
}
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
Expand All @@ -239,8 +240,12 @@ public void readFromNBT(NBTTagCompound nbt) {
this.progress = nbt.getFloat("prog");
this.burnTime = nbt.getInteger("burn");
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
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
Expand All @@ -250,32 +255,36 @@ public void writeToNBT(NBTTagCompound nbt) {
nbt.setFloat("prog", progress);
nbt.setInteger("burn", burnTime);
nbt.setInteger("maxBurn", maxBurnTime);
if (this.output != null) {
nbt.setInteger("outType", this.output.material.id);
nbt.setInteger("outAmount", this.output.amount);
}
}

public DirPos[] getSteamPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);

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, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite())
};
}

public DirPos[] getFluidPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);

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)
};
}

public boolean canProcess(RotaryFurnaceRecipe recipe) {

if(this.burnTime <= 0) return false;

if(recipe.fluid != null) {
if(this.tanks[0].getTankType() != recipe.fluid.type) return false;
if(this.tanks[0].getFill() < recipe.fluid.fill) return false;
Expand All @@ -284,19 +293,19 @@ public boolean canProcess(RotaryFurnaceRecipe recipe) {
if(tanks[1].getFill() < recipe.steam) return false;
if(tanks[2].getMaxFill() - tanks[2].getFill() < recipe.steam / 100) return false;
if(this.steamUsed > 100) return false;

if(this.output != null) {
if(this.output.material != recipe.output.material) return false;
if(this.output.amount + recipe.output.amount > this.maxOutput) return false;
}

return true;
}

public void consumeItems(RotaryFurnaceRecipe recipe) {

for(AStack aStack : recipe.ingredients) {

for(int i = 0; i < 3; i++) {
ItemStack stack = slots[i];
if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) {
Expand All @@ -305,19 +314,19 @@ public void consumeItems(RotaryFurnaceRecipe recipe) {
}
}
}

if(recipe.fluid != null) {
this.tanks[0].setFill(tanks[0].getFill() - recipe.fluid.fill);
}
}

@Override
public void pollute(PollutionType type, float amount) {
FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison;

int fluidAmount = (int) Math.ceil(amount * 100);
tank.setFill(tank.getFill() + fluidAmount);

if(tank.getFill() > tank.getMaxFill()) {
int overflow = tank.getFill() - tank.getMaxFill();
tank.setFill(tank.getMaxFill());
Expand All @@ -332,12 +341,12 @@ public void pollute(PollutionType type, float amount) {

@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; }

AxisAlignedBB bb = null;

@Override
public AxisAlignedBB getRenderBoundingBox() {

if(bb == null) {
bb = AxisAlignedBB.getBoundingBox(
xCoord - 2,
Expand All @@ -348,10 +357,10 @@ public AxisAlignedBB getRenderBoundingBox() {
zCoord + 3
);
}

return bb;
}

@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
Expand All @@ -364,7 +373,7 @@ public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);
BlockPos core = new BlockPos(xCoord, yCoord, zCoord);

//Red
if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1).offset(rot, -2))) return new int[] {0};
//Yellow
Expand All @@ -373,7 +382,7 @@ public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) {
if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1))) return new int[] {2};
//Fuel
if(side == dir.ordinal() && pos.equals(core.clone().offset(dir, 1).offset(rot, -1))) return new int[] {4};

return new int[] { };
}

Expand Down

0 comments on commit c855f67

Please sign in to comment.