avoid repeated smeltery structure checks (#329)

This commit is contained in:
Pxx500 authored and GitHub committed 2026-09-05 22:38:44 +02:00
1 parent 034fede7ed
commit 7c1bf6724d
3 files changed
+42 -18

No files matched your search

@@ -25,7 +25,6 @@ import net.minecraftforge.fluids.FluidTankInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mantle.blocks.iface.IServantLogic;
import tconstruct.library.TConstructRegistry;
import tconstruct.smeltery.itemblocks.LavaTankItemBlock;
import tconstruct.smeltery.logic.LavaTankLogic;
@@ -246,11 +245,17 @@ public class LavaTankBlock extends BlockContainer {
}
/* Updates */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block nBlockID) {
TileEntity logic = world.getTileEntity(x, y, z);
if (logic instanceof IServantLogic) {
((IServantLogic) logic).notifyMasterOfChange();
}
if (!SmelteryBlock.isStructureChange(nBlockID)) return;
SmelteryBlock.notifyMasterOfStructureChange(world, x, y, z);
}
@Override
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
SmelteryBlock.notifyMasterOfStructureChange(world, x, y, z);
super.onBlockPreDestroy(world, x, y, z, meta);
}
@Override
@@ -8,6 +8,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -26,6 +27,7 @@ import mantle.blocks.iface.IServantLogic;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.smeltery.SmelteryProxyCommon;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.smeltery.logic.SmelteryDrainLogic;
import tconstruct.smeltery.logic.SmelteryLogic;
import tconstruct.smeltery.model.SmelteryRender;
@@ -232,7 +234,25 @@ public class SmelteryBlock extends InventoryBlock {
/* Updating */
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
// System.out.println("Neighbor changed");
if (!isStructureChange(block)) return;
notifyMasterOfStructureChange(world, x, y, z);
}
@Override
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
notifyMasterOfStructureChange(world, x, y, z);
super.onBlockPreDestroy(world, x, y, z, meta);
}
static boolean isStructureChange(Block block) {
return block == Blocks.air || block == TinkerSmeltery.smeltery
|| block == TinkerSmeltery.smelteryNether
|| block == TinkerSmeltery.lavaTank
|| block == TinkerSmeltery.lavaTankNether;
}
static void notifyMasterOfStructureChange(World world, int x, int y, int z) {
TileEntity logic = world.getTileEntity(x, y, z);
if (logic instanceof IServantLogic) {
((IServantLogic) logic).notifyMasterOfChange();
@@ -241,17 +261,6 @@ public class SmelteryBlock extends InventoryBlock {
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block blockID, int meta) {
// TE is not valid anymore at this point. :/
TileEntity logic = world.getTileEntity(x, y, z);
if (logic instanceof IServantLogic) {
((IServantLogic) logic).notifyMasterOfChange();
}
super.breakBlock(world, x, y, z, blockID, meta);
}
// Comparator
public boolean hasComparatorInputOverride() {
@@ -86,6 +86,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
public int[] activeTemps; // values are multiplied by 10
public int[] meltingTemps; // values are multiplied by 10
private int tick;
private boolean structureCheckQueued;
public final List<FluidStack> moltenMetal = Collections.synchronizedList(new ArrayList<>());
public int maxLiquid;
@@ -287,6 +288,8 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
/* Updating */
@Override
public void updateEntity() {
checkStructureIfQueued();
tick++;
if (tick == 60) {
tick = 0;
@@ -329,6 +332,13 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
}
}
private void checkStructureIfQueued() {
if (structureCheckQueued) {
structureCheckQueued = false;
checkValidPlacement();
}
}
void detectEntities() {
if (!validStructure || minPos == null || maxPos == null) return;
@@ -680,7 +690,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
/* Multiblock */
@Override
public void notifyChange(IServantLogic servant, int x, int y, int z) {
checkValidPlacement();
structureCheckQueued = true;
}
public void checkValidPlacement() {