Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 22:40:18 +01:00
Fix adding duplicate block states for custom blocks with 0 properties
Remove defaultBlockState CustomBlockState field from GeyserCustomBlockData since it creates a circular reference
Dieser Commit ist enthalten in:
Ursprung
36f540f401
Commit
d00886e12a
@ -49,8 +49,7 @@ public class GeyserCustomBlockData implements CustomBlockData {
|
|||||||
Map<String, CustomBlockProperty<?>> properties;
|
Map<String, CustomBlockProperty<?>> properties;
|
||||||
List<CustomBlockPermutation> permutations;
|
List<CustomBlockPermutation> permutations;
|
||||||
|
|
||||||
@EqualsAndHashCode.Exclude // Otherwise this will a StackOverflowError in hashCode/equals
|
Map<String, Object> defaultProperties;
|
||||||
CustomBlockState defaultBlockState;
|
|
||||||
|
|
||||||
private GeyserCustomBlockData(CustomBlockDataBuilder builder) {
|
private GeyserCustomBlockData(CustomBlockDataBuilder builder) {
|
||||||
this.name = builder.name;
|
this.name = builder.name;
|
||||||
@ -60,10 +59,9 @@ public class GeyserCustomBlockData implements CustomBlockData {
|
|||||||
|
|
||||||
this.components = builder.components;
|
this.components = builder.components;
|
||||||
|
|
||||||
Object2ObjectMap<String, Object> defaultProperties;
|
|
||||||
if (!builder.properties.isEmpty()) {
|
if (!builder.properties.isEmpty()) {
|
||||||
this.properties = Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(builder.properties));
|
this.properties = Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(builder.properties));
|
||||||
defaultProperties = new Object2ObjectOpenHashMap<>(this.properties.size());
|
Object2ObjectMap<String, Object> defaultProperties = new Object2ObjectOpenHashMap<>(this.properties.size());
|
||||||
for (CustomBlockProperty<?> property : properties.values()) {
|
for (CustomBlockProperty<?> property : properties.values()) {
|
||||||
if (property.values().isEmpty() || property.values().size() > 16) {
|
if (property.values().isEmpty() || property.values().size() > 16) {
|
||||||
throw new IllegalStateException(property.name() + " must contain 1 to 16 values.");
|
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));
|
defaultProperties.put(property.name(), property.values().get(0));
|
||||||
}
|
}
|
||||||
this.defaultBlockState = new GeyserCustomBlockState(this, Object2ObjectMaps.unmodifiable(defaultProperties));
|
this.defaultProperties = Object2ObjectMaps.unmodifiable(defaultProperties);
|
||||||
} else {
|
} else {
|
||||||
this.properties = Object2ObjectMaps.emptyMap();
|
this.properties = Object2ObjectMaps.emptyMap();
|
||||||
this.defaultBlockState = new GeyserCustomBlockState(this, Object2ObjectMaps.emptyMap());
|
this.defaultProperties = Object2ObjectMaps.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!builder.permutations.isEmpty()) {
|
if (!builder.permutations.isEmpty()) {
|
||||||
@ -113,7 +111,7 @@ public class GeyserCustomBlockData implements CustomBlockData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull CustomBlockState defaultBlockState() {
|
public @NonNull CustomBlockState defaultBlockState() {
|
||||||
return defaultBlockState;
|
return new GeyserCustomBlockState(this, defaultProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,13 +111,6 @@ public class BlockRegistryPopulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void generateCustomBlockStates(CustomBlockData customBlock, List<NbtMap> blockStates, List<CustomBlockState> customExtBlockStates, int stateVersion) {
|
private static void generateCustomBlockStates(CustomBlockData customBlock, List<NbtMap> blockStates, List<CustomBlockState> 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;
|
int totalPermutations = 1;
|
||||||
for (CustomBlockProperty<?> property : customBlock.properties().values()) {
|
for (CustomBlockProperty<?> property : customBlock.properties().values()) {
|
||||||
totalPermutations *= property.values().size();
|
totalPermutations *= property.values().size();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren