From 00a453fe42841073766830f8a435c1329fcff7cb Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Mon, 30 Jan 2023 15:07:35 -0500 Subject: [PATCH] Treat all properties as string properties There isn't a real need to check for boolean and int properties --- .../mappings/versions/MappingsReader_v1.java | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) 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 0db39fe39..853808afc 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 @@ -28,7 +28,6 @@ package org.geysermc.geyser.registry.mappings.versions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.github.steveice10.mc.protocol.data.game.Identifier; -import com.google.common.base.CharMatcher; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.geysermc.geyser.GeyserImpl; @@ -236,8 +235,7 @@ public class MappingsReader_v1 extends MappingsReader { } private CustomBlockMapping createCustomBlockMapping(CustomBlockData.Builder customBlockDataBuilder, Map componentsMap, String identifier, boolean overrideItem) { - Map> stringValuesMap = new Object2ObjectOpenHashMap<>(); - Map> intValuesMap = new Object2ObjectOpenHashMap<>(); + Map> valuesMap = new Object2ObjectOpenHashMap<>(); List permutations = new ArrayList<>(); Map> blockStateBuilders = new Object2ObjectOpenHashMap<>(); @@ -256,33 +254,18 @@ public class MappingsReader_v1 extends MappingsReader { String property = parts[0]; String value = parts[1]; - // Figure out what property type we are dealing with - if (value.equals("true") || value.equals("false")) { - customBlockDataBuilder.booleanProperty(property); + valuesMap.computeIfAbsent(property, k -> new LinkedHashSet<>()) + .add(value); - conditions[i] = String.format("q.block_property('%s') == %s", property, value); - blockStateBuilder = blockStateBuilder.andThen(builder -> builder.booleanProperty(property, value.equals("true"))); - } else if (CharMatcher.inRange('0', '9').matchesAllOf(value)) { - int intValue = Integer.parseInt(value); - intValuesMap.computeIfAbsent(property, k -> new LinkedHashSet<>()) - .add(intValue); - - conditions[i] = String.format("q.block_property('%s') == %s", property, value); - blockStateBuilder = blockStateBuilder.andThen(builder -> builder.intProperty(property, intValue)); - } else { - stringValuesMap.computeIfAbsent(property, k -> new LinkedHashSet<>()) - .add(value); - - conditions[i] = String.format("q.block_property('%s') == '%s'", property, value); - blockStateBuilder = blockStateBuilder.andThen(builder -> builder.stringProperty(property, value)); - } + conditions[i] = String.format("q.block_property('%s') == '%s'", property, value); + blockStateBuilder = blockStateBuilder.andThen(builder -> builder.stringProperty(property, value)); } + permutations.add(new CustomBlockPermutation(entry.getValue(), String.join(" && ", conditions))); blockStateBuilders.put(state, blockStateBuilder.andThen(CustomBlockState.Builder::build)); } - // Define properties for the custom block - stringValuesMap.forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<>(value))); - intValuesMap.forEach((key, value) -> customBlockDataBuilder.intProperty(key, new ArrayList<>(value))); + + valuesMap.forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<>(value))); CustomBlockData customBlockData = customBlockDataBuilder .permutations(permutations)