From 036064a72a4ee1b9ff0076e2ffa5c8f457b3eaa1 Mon Sep 17 00:00:00 2001 From: mica-alex <83238954+mica-alex@users.noreply.github.com> Date: Mon, 13 Apr 2026 16:50:12 -0400 Subject: [PATCH] Fix blocks displaying as wrong block types (IE model cache collision) IE's ConnModelReal uses a Guava cache keyed by ExtBlockstateAdapter, which compares block state property VALUES but not the Block identity. Blocks with the same facing and connection state (e.g. all blocks with no wires facing north) shared a single cache entry, causing the first block rendered to win and its model to display for all others. Fix: implement ICacheData on all TE base classes and pass the TE via IEProperties.TILEENTITY_PASSTHROUGH in the extended block state. IE reads getCacheData() and includes it in the cache key, ensuring each block type gets its own cached model. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../blocks/cutoffs/BlockCutoffSwitchBase.java | 9 +++++---- .../blocks/cutoffs/TileEntityCutoffSwitch.java | 11 ++++++++++- .../blocks/insulators/BlockInsulatorBase.java | 9 ++++++--- .../blocks/insulators/TileEntityInsulatorBase.java | 11 ++++++++++- .../transformers/BlockRealTransformerBase.java | 9 ++++++--- .../transformers/TileEntityRealTransformer.java | 13 +++++++++++-- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/BlockCutoffSwitchBase.java b/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/BlockCutoffSwitchBase.java index 159bcf4..eb72e62 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/BlockCutoffSwitchBase.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/BlockCutoffSwitchBase.java @@ -140,7 +140,7 @@ protected BlockStateContainer createBlockState() { return new ExtendedBlockState(this, new IProperty[]{ FACING, ACTIVE }, - new IUnlistedProperty[]{ IEProperties.CONNECTIONS }); + new IUnlistedProperty[]{ IEProperties.CONNECTIONS, IEProperties.TILEENTITY_PASSTHROUGH }); } @Override @@ -151,9 +151,10 @@ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, Block TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityImmersiveConnectable) { - state = ((IExtendedBlockState) state).withProperty( - IEProperties.CONNECTIONS, - ((TileEntityImmersiveConnectable) te).genConnBlockstate()); + state = ((IExtendedBlockState) state) + .withProperty(IEProperties.CONNECTIONS, + ((TileEntityImmersiveConnectable) te).genConnBlockstate()) + .withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te); } } return state; diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/TileEntityCutoffSwitch.java b/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/TileEntityCutoffSwitch.java index f387d31..cd86dd4 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/TileEntityCutoffSwitch.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/cutoffs/TileEntityCutoffSwitch.java @@ -7,6 +7,7 @@ import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable; import blusunrize.immersiveengineering.api.energy.wires.WireType; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockBounds; +import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ICacheData; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IRedstoneOutput; @@ -30,7 +31,7 @@ * mirroring the IE MV/LV Breaker Switch model across all three voltage tiers. */ public class TileEntityCutoffSwitch extends TileEntityImmersiveConnectable - implements IDirectionalTile, IBlockBounds, IHammerInteraction, IRedstoneOutput, ITickable { + implements IDirectionalTile, IBlockBounds, ICacheData, IHammerInteraction, IRedstoneOutput, ITickable { // ----------------------------------------------------------------------- // Constants @@ -407,6 +408,14 @@ public void readCustomNBT(NBTTagCompound nbt, boolean descPacket) { public Vec3d getConnectionOffset(Connection con) { return new Vec3d(0.5, 0.5, 0.5); } // ----------------------------------------------------------------------- + // ICacheData + + @Override + public Object[] getCacheData() + { + return new Object[]{ getClass().getName() }; + } + // IDirectionalTile // ----------------------------------------------------------------------- diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/insulators/BlockInsulatorBase.java b/src/main/java/com/micatechnologies/realgrid/blocks/insulators/BlockInsulatorBase.java index 7807c7f..fedb6fc 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/insulators/BlockInsulatorBase.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/insulators/BlockInsulatorBase.java @@ -80,7 +80,8 @@ public void getSubBlocks(CreativeTabs tab, NonNullList items) @Override protected BlockStateContainer createBlockState() { - return new ExtendedBlockState(this, new IProperty[]{FACING}, new IUnlistedProperty[]{IEProperties.CONNECTIONS}); + return new ExtendedBlockState(this, new IProperty[]{FACING}, + new IUnlistedProperty[]{IEProperties.CONNECTIONS, IEProperties.TILEENTITY_PASSTHROUGH}); } @Override @@ -91,8 +92,10 @@ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, Block TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityImmersiveConnectable) { - state = ((IExtendedBlockState) state).withProperty(IEProperties.CONNECTIONS, - ((TileEntityImmersiveConnectable) te).genConnBlockstate()); + state = ((IExtendedBlockState) state) + .withProperty(IEProperties.CONNECTIONS, + ((TileEntityImmersiveConnectable) te).genConnBlockstate()) + .withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te); } } return state; diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/insulators/TileEntityInsulatorBase.java b/src/main/java/com/micatechnologies/realgrid/blocks/insulators/TileEntityInsulatorBase.java index 8731c18..7cb5327 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/insulators/TileEntityInsulatorBase.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/insulators/TileEntityInsulatorBase.java @@ -7,6 +7,7 @@ import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable; import blusunrize.immersiveengineering.api.energy.wires.WireType; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockBounds; +import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ICacheData; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -23,7 +24,7 @@ * color-variant blocks can share this base without a separate class tier. */ public abstract class TileEntityInsulatorBase extends TileEntityImmersiveConnectable - implements IDirectionalTile, IBlockBounds + implements IDirectionalTile, IBlockBounds, ICacheData { public EnumFacing facing = EnumFacing.NORTH; public int colorVariant = 0; @@ -155,6 +156,14 @@ public void onBlockDestroyed() limitType = null; } + // === ICacheData === + + @Override + public Object[] getCacheData() + { + return new Object[]{ getClass().getName() }; + } + // === IDirectionalTile === @Override public EnumFacing getFacing() { return facing; } diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/transformers/BlockRealTransformerBase.java b/src/main/java/com/micatechnologies/realgrid/blocks/transformers/BlockRealTransformerBase.java index 2ecf94a..8b27c7b 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/transformers/BlockRealTransformerBase.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/transformers/BlockRealTransformerBase.java @@ -105,7 +105,8 @@ public void getDrops(NonNullList drops, IBlockAccess world, @Override protected BlockStateContainer createBlockState() { - return new ExtendedBlockState(this, new IProperty[]{FACING, DUMMY}, new IUnlistedProperty[]{IEProperties.CONNECTIONS}); + return new ExtendedBlockState(this, new IProperty[]{FACING, DUMMY}, + new IUnlistedProperty[]{IEProperties.CONNECTIONS, IEProperties.TILEENTITY_PASSTHROUGH}); } @Override @@ -116,8 +117,10 @@ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, Block TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityImmersiveConnectable) { - state = ((IExtendedBlockState) state).withProperty(IEProperties.CONNECTIONS, - ((TileEntityImmersiveConnectable) te).genConnBlockstate()); + state = ((IExtendedBlockState) state) + .withProperty(IEProperties.CONNECTIONS, + ((TileEntityImmersiveConnectable) te).genConnBlockstate()) + .withProperty(IEProperties.TILEENTITY_PASSTHROUGH, te); } } return state; diff --git a/src/main/java/com/micatechnologies/realgrid/blocks/transformers/TileEntityRealTransformer.java b/src/main/java/com/micatechnologies/realgrid/blocks/transformers/TileEntityRealTransformer.java index 4e9bd2a..e6f5777 100644 --- a/src/main/java/com/micatechnologies/realgrid/blocks/transformers/TileEntityRealTransformer.java +++ b/src/main/java/com/micatechnologies/realgrid/blocks/transformers/TileEntityRealTransformer.java @@ -7,9 +7,10 @@ import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection; import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable; import blusunrize.immersiveengineering.api.energy.wires.WireType; +import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockBounds; +import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ICacheData; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks; -import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IBlockBounds; import com.google.common.collect.ImmutableSet; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; @@ -30,7 +31,7 @@ * - Index 2: second HV connection (STEEL only, 2-wire variants only) */ public abstract class TileEntityRealTransformer extends TileEntityImmersiveConnectable - implements IDirectionalTile, IHasDummyBlocks, IBlockBounds + implements IDirectionalTile, IHasDummyBlocks, IBlockBounds, ICacheData { public EnumFacing facing = EnumFacing.NORTH; public int dummy = 0; @@ -473,6 +474,14 @@ public void breakDummies(BlockPos pos, IBlockState state) } } + // === ICacheData === + + @Override + public Object[] getCacheData() + { + return new Object[]{ getClass().getName() }; + } + // === IBlockBounds === @Override