From d00886e12a225df70828d473a8c214c8046e1298 Mon Sep 17 00:00:00 2001 From: davchoo Date: Thu, 28 Jul 2022 23:24:01 -0400 Subject: [PATCH] Fix adding duplicate block states for custom blocks with 0 properties Remove defaultBlockState CustomBlockState field from GeyserCustomBlockData since it creates a circular reference --- .../geyser/level/block/GeyserCustomBlockData.java | 12 +++++------- .../registry/populator/BlockRegistryPopulator.java | 7 ------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java index a7085c3e8..de97d38d4 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java @@ -49,8 +49,7 @@ public class GeyserCustomBlockData implements CustomBlockData { Map> properties; List permutations; - @EqualsAndHashCode.Exclude // Otherwise this will a StackOverflowError in hashCode/equals - CustomBlockState defaultBlockState; + Map defaultProperties; private GeyserCustomBlockData(CustomBlockDataBuilder builder) { this.name = builder.name; @@ -60,10 +59,9 @@ public class GeyserCustomBlockData implements CustomBlockData { this.components = builder.components; - Object2ObjectMap defaultProperties; if (!builder.properties.isEmpty()) { this.properties = Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(builder.properties)); - defaultProperties = new Object2ObjectOpenHashMap<>(this.properties.size()); + Object2ObjectMap defaultProperties = new Object2ObjectOpenHashMap<>(this.properties.size()); for (CustomBlockProperty property : properties.values()) { if (property.values().isEmpty() || property.values().size() > 16) { throw new IllegalStateException(property.name() + " must contain 1 to 16 values."); @@ -73,10 +71,10 @@ public class GeyserCustomBlockData implements CustomBlockData { } defaultProperties.put(property.name(), property.values().get(0)); } - this.defaultBlockState = new GeyserCustomBlockState(this, Object2ObjectMaps.unmodifiable(defaultProperties)); + this.defaultProperties = Object2ObjectMaps.unmodifiable(defaultProperties); } else { this.properties = Object2ObjectMaps.emptyMap(); - this.defaultBlockState = new GeyserCustomBlockState(this, Object2ObjectMaps.emptyMap()); + this.defaultProperties = Object2ObjectMaps.emptyMap(); } if (!builder.permutations.isEmpty()) { @@ -113,7 +111,7 @@ public class GeyserCustomBlockData implements CustomBlockData { @Override public @NonNull CustomBlockState defaultBlockState() { - return defaultBlockState; + return new GeyserCustomBlockState(this, defaultProperties); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index d88985df2..fadc21dae 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -111,13 +111,6 @@ public class BlockRegistryPopulator { } private static void generateCustomBlockStates(CustomBlockData customBlock, List blockStates, List customExtBlockStates, int stateVersion) { - if (customBlock.properties().isEmpty()) { - blockStates.add(NbtMap.builder() - .putString("name", customBlock.identifier()) - .putInt("version", stateVersion) - .putCompound("states", NbtMap.EMPTY) - .build()); - } int totalPermutations = 1; for (CustomBlockProperty property : customBlock.properties().values()) { totalPermutations *= property.values().size();