From abb5eceeb35a6d93cd06a8b66a3054614721de6a Mon Sep 17 00:00:00 2001 From: Thiakil Date: Sun, 31 Mar 2024 10:03:27 +0800 Subject: [PATCH] cache active attribute to avoid map lookups --- .../mekanism/common/tile/base/TileEntityMekanism.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java b/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java index 25ab698d2d2..28414fe6f8a 100644 --- a/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java +++ b/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java @@ -175,6 +175,7 @@ public abstract class TileEntityMekanism extends CapabilityTileEntity implements private boolean canBeUpgraded; private boolean isDirectional; private boolean isActivatable; + private AttributeStateActive activeAttribute; private boolean hasSecurity; private boolean hasSound; private boolean hasGui; @@ -317,7 +318,8 @@ private void setSupportedTypes(Block block) { hasSound = Attribute.has(block, AttributeSound.class); hasGui = Attribute.has(block, AttributeGui.class); hasSecurity = Attribute.has(block, AttributeSecurity.class); - isActivatable = hasSound || Attribute.has(block, AttributeStateActive.class); + activeAttribute = Attribute.get(block, AttributeStateActive.class); + isActivatable = hasSound || activeAttribute != null; supportsComparator = Attribute.has(block, AttributeComparator.class); supportsComputers = Mekanism.hooks.computerCompatEnabled() && Attribute.has(block, AttributeComputerIntegration.class); hasChunkloader = this instanceof IChunkLoader; @@ -585,7 +587,7 @@ public static void tickServer(Level level, BlockPos pos, BlockState state, TileE tile.updateDelay--; if (tile.updateDelay == 0 && tile.getClientActive() != tile.currentActive) { //If it doesn't match, and we are done with the delay period, then update it - level.setBlockAndUpdate(pos, Attribute.setActive(state, tile.currentActive)); + level.setBlockAndUpdate(pos, tile.activeAttribute.setActive(state, tile.currentActive)); } } } @@ -1321,14 +1323,13 @@ public boolean getActive() { } private boolean getClientActive() { - return isActivatable() && Attribute.isActive(getBlockState()); + return activeAttribute != null && activeAttribute.isActive(getBlockState()); } @Override public void setActive(boolean active) { if (isActivatable() && active != currentActive) { BlockState state = getBlockState(); - AttributeStateActive activeAttribute = Attribute.get(state, AttributeStateActive.class); if (activeAttribute != null) { currentActive = active; if (getClientActive() != active) {