Plain block state flags

- lazily computed BukkitBlockState flags are bytes instead of volatile Booleans
This commit is contained in:
Brian Neumann-Fopiano committed 2026-09-28 11:17:51 -04:00
1 parent bc618e20ec
commit badca54e5d
1 file changed
+98 -91
@@ -57,29 +57,32 @@ public final class BukkitBlockState implements NativeBlockState {
// the canonical NMS state): a hit skips getAsString(), which built the full property // the canonical NMS state): a hit skips getAsString(), which built the full property
// string on EVERY of() call — the dominant cost of the 99.9% hit case. // string on EVERY of() call — the dominant cost of the 99.9% hit case.
private static final ConcurrentHashMap<BlockData, BukkitBlockState> DATA_CACHE = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<BlockData, BukkitBlockState> DATA_CACHE = new ConcurrentHashMap<>();
private static final byte UNKNOWN = 0;
private static final byte FALSE = 1;
private static final byte TRUE = 2;
private final BlockData data; private final BlockData data;
private final String key; private final String key;
private final String namespace; private final String namespace;
private volatile String materialKey; private String materialKey;
private volatile Boolean air; private byte air;
private volatile Boolean solid; private byte solid;
private volatile Boolean occluding; private byte occluding;
private volatile Boolean fluid; private byte fluid;
private volatile Boolean water; private byte water;
private volatile Boolean waterLogged; private byte waterLogged;
private volatile Boolean lit; private byte lit;
private volatile Boolean updatable; private byte updatable;
private volatile Boolean foliage; private byte foliage;
private volatile Boolean treeBlock; private byte treeBlock;
private volatile Boolean foliagePlantable; private byte foliagePlantable;
private volatile Boolean decorant; private byte decorant;
private volatile Boolean storage; private byte storage;
private volatile Boolean storageChest; private byte storageChest;
private volatile Boolean ore; private byte ore;
private volatile Boolean deepSlate; private byte deepSlate;
private volatile Boolean vineBlock; private byte vineBlock;
private volatile Boolean tileEntity; private byte tileEntity;
private BukkitBlockState(BlockData data, String key) { private BukkitBlockState(BlockData data, String key) {
this.data = data; this.data = data;
@@ -87,6 +90,10 @@ public final class BukkitBlockState implements NativeBlockState {
this.namespace = BlockStateKey.namespace(key); this.namespace = BlockStateKey.namespace(key);
} }
private static byte flag(boolean value) {
return value ? TRUE : FALSE;
}
public static BukkitBlockState of(BlockData data) { public static BukkitBlockState of(BlockData data) {
if (data instanceof IrisCustomData custom) { if (data instanceof IrisCustomData custom) {
return new BukkitBlockState(data, custom.getCustom().toString()); return new BukkitBlockState(data, custom.getCustom().toString());
@@ -198,32 +205,32 @@ public final class BukkitBlockState implements NativeBlockState {
@Override @Override
public boolean isAir() { public boolean isAir() {
Boolean cached = air; byte cached = air;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isAir(data); cached = flag(BukkitBlockResolution.isAir(data));
air = cached; air = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isSolid() { public boolean isSolid() {
Boolean cached = solid; byte cached = solid;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isSolid(data); cached = flag(BukkitBlockResolution.isSolid(data));
solid = cached; solid = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isOccluding() { public boolean isOccluding() {
Boolean cached = occluding; byte cached = occluding;
if (cached == null) { if (cached == UNKNOWN) {
cached = data.getMaterial().isOccluding(); cached = flag(data.getMaterial().isOccluding());
occluding = cached; occluding = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
@@ -248,142 +255,142 @@ public final class BukkitBlockState implements NativeBlockState {
@Override @Override
public boolean isFluid() { public boolean isFluid() {
Boolean cached = fluid; byte cached = fluid;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isFluid(data); cached = flag(BukkitBlockResolution.isFluid(data));
fluid = cached; fluid = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isWater() { public boolean isWater() {
Boolean cached = water; byte cached = water;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isWater(data); cached = flag(BukkitBlockResolution.isWater(data));
water = cached; water = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isWaterLogged() { public boolean isWaterLogged() {
Boolean cached = waterLogged; byte cached = waterLogged;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isWaterLogged(data); cached = flag(BukkitBlockResolution.isWaterLogged(data));
waterLogged = cached; waterLogged = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isLit() { public boolean isLit() {
Boolean cached = lit; byte cached = lit;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isLit(data); cached = flag(BukkitBlockResolution.isLit(data));
lit = cached; lit = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isUpdatable() { public boolean isUpdatable() {
Boolean cached = updatable; byte cached = updatable;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isUpdatable(data); cached = flag(BukkitBlockResolution.isUpdatable(data));
updatable = cached; updatable = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isFoliage() { public boolean isFoliage() {
Boolean cached = foliage; byte cached = foliage;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isFoliage(data); cached = flag(BukkitBlockResolution.isFoliage(data));
foliage = cached; foliage = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isTreeBlock() { public boolean isTreeBlock() {
Boolean cached = treeBlock; byte cached = treeBlock;
if (cached == null) { if (cached == UNKNOWN) {
cached = Tag.LOGS.isTagged(data.getMaterial()) || Tag.LEAVES.isTagged(data.getMaterial()); cached = flag(Tag.LOGS.isTagged(data.getMaterial()) || Tag.LEAVES.isTagged(data.getMaterial()));
treeBlock = cached; treeBlock = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isFoliagePlantable() { public boolean isFoliagePlantable() {
Boolean cached = foliagePlantable; byte cached = foliagePlantable;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isFoliagePlantable(data); cached = flag(BukkitBlockResolution.isFoliagePlantable(data));
foliagePlantable = cached; foliagePlantable = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isDecorant() { public boolean isDecorant() {
Boolean cached = decorant; byte cached = decorant;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isDecorant(data); cached = flag(BukkitBlockResolution.isDecorant(data));
decorant = cached; decorant = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isStorage() { public boolean isStorage() {
Boolean cached = storage; byte cached = storage;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isStorage(data); cached = flag(BukkitBlockResolution.isStorage(data));
storage = cached; storage = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isStorageChest() { public boolean isStorageChest() {
Boolean cached = storageChest; byte cached = storageChest;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isStorageChest(data); cached = flag(BukkitBlockResolution.isStorageChest(data));
storageChest = cached; storageChest = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isOre() { public boolean isOre() {
Boolean cached = ore; byte cached = ore;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isOre(data); cached = flag(BukkitBlockResolution.isOre(data));
ore = cached; ore = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isDeepSlate() { public boolean isDeepSlate() {
Boolean cached = deepSlate; byte cached = deepSlate;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isDeepSlate(data); cached = flag(BukkitBlockResolution.isDeepSlate(data));
deepSlate = cached; deepSlate = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
public boolean isVineBlock() { public boolean isVineBlock() {
Boolean cached = vineBlock; byte cached = vineBlock;
if (cached == null) { if (cached == UNKNOWN) {
cached = BukkitBlockResolution.isVineBlock(data); cached = flag(BukkitBlockResolution.isVineBlock(data));
vineBlock = cached; vineBlock = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override
@@ -398,12 +405,12 @@ public final class BukkitBlockState implements NativeBlockState {
@Override @Override
public boolean hasTileEntity() { public boolean hasTileEntity() {
Boolean cached = tileEntity; byte cached = tileEntity;
if (cached == null) { if (cached == UNKNOWN) {
cached = INMS.get().hasTile(data.getMaterial()); cached = flag(INMS.get().hasTile(data.getMaterial()));
tileEntity = cached; tileEntity = cached;
} }
return cached; return cached == TRUE;
} }
@Override @Override