Skip to content

Commit

Permalink
cache active attribute to avoid map lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Mar 31, 2024
1 parent 9f291f5 commit abb5ece
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit abb5ece

Please sign in to comment.