From 880d8e528ed8a9d16ae3004b237b46b82f2c5f90 Mon Sep 17 00:00:00 2001 From: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 5 Jan 2023 21:54:08 -0800 Subject: [PATCH] Fix collide box and warn for >16 props --- .../geyser/level/block/GeyserCustomBlockData.java | 9 ++++++--- .../registry/mappings/versions/MappingsReader_v1.java | 10 ++++++---- 2 files changed, 12 insertions(+), 7 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 ba0fdf17d..a454687f3 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 @@ -26,10 +26,10 @@ package org.geysermc.geyser.level.block; import it.unimi.dsi.fastutil.objects.*; -import lombok.EqualsAndHashCode; import lombok.Value; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.Constants; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockPermutation; import org.geysermc.geyser.api.block.custom.CustomBlockState; @@ -63,12 +63,15 @@ public class GeyserCustomBlockData implements CustomBlockData { this.properties = Object2ObjectMaps.unmodifiable(new Object2ObjectArrayMap<>(builder.properties)); 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."); + if (property.values().size() > 16) { + GeyserImpl.getInstance().getLogger().warning(property.name() + " contains more than 16 values, but BDS specifies it should not. This may break in future versions."); } if (property.values().stream().distinct().count() != property.values().size()) { throw new IllegalStateException(property.name() + " has duplicate values."); } + if (property.values().isEmpty()) { + throw new IllegalStateException(property.name() + " contains no values."); + } defaultProperties.put(property.name(), property.values().get(0)); } this.defaultProperties = Object2ObjectMaps.unmodifiable(defaultProperties); diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index a2afc6b3f..99aa08902 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -26,7 +26,6 @@ package org.geysermc.geyser.registry.mappings.versions; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.base.CharMatcher; @@ -286,7 +285,10 @@ public class MappingsReader_v1 extends MappingsReader { Set booleanValuesSet = new HashSet<>(); Map> stateKeyBools = new HashMap<>(); + for (String state : usedStateKeys) { + if (!state.contains("[")) continue; + String[] pairs = splitStateString(state); for (String pair : pairs) { @@ -411,9 +413,9 @@ public class MappingsReader_v1 extends MappingsReader { float cornerY = clamp((float) boundingBox.getMiddleY() * 16 - offsetY, 0, 16); float cornerZ = clamp((float) boundingBox.getMiddleZ() * 16 - 8 - offsetZ, -8, 8); - float sizeX = clamp((float) boundingBox.getSizeX() * 16, -8, 8); + float sizeX = clamp((float) boundingBox.getSizeX() * 16, 0, 16); float sizeY = clamp((float) boundingBox.getSizeY() * 16, 0, 16); - float sizeZ = clamp((float) boundingBox.getSizeZ() * 16, -8, 8); + float sizeZ = clamp((float) boundingBox.getSizeZ() * 16, 0, 16); BoxComponent boxComponent = new BoxComponent(cornerX, cornerY, cornerZ, sizeX, sizeY, sizeZ); @@ -479,7 +481,7 @@ public class MappingsReader_v1 extends MappingsReader { } public float clamp(float value, float min, float max) { - return Math.max(min, Math.min(value, max)); + return Math.max(min, Math.min(max, value)); } }