3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Treat all properties as string properties

There isn't a real need to check for boolean and int properties
Dieser Commit ist enthalten in:
davchoo 2023-01-30 15:07:35 -05:00
Ursprung d99cb468f1
Commit 00a453fe42
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 501B6F4FD961CF9A

Datei anzeigen

@ -28,7 +28,6 @@ package org.geysermc.geyser.registry.mappings.versions;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.steveice10.mc.protocol.data.game.Identifier; 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.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
@ -236,8 +235,7 @@ public class MappingsReader_v1 extends MappingsReader {
} }
private CustomBlockMapping createCustomBlockMapping(CustomBlockData.Builder customBlockDataBuilder, Map<String, CustomBlockComponents> componentsMap, String identifier, boolean overrideItem) { private CustomBlockMapping createCustomBlockMapping(CustomBlockData.Builder customBlockDataBuilder, Map<String, CustomBlockComponents> componentsMap, String identifier, boolean overrideItem) {
Map<String, LinkedHashSet<String>> stringValuesMap = new Object2ObjectOpenHashMap<>(); Map<String, LinkedHashSet<String>> valuesMap = new Object2ObjectOpenHashMap<>();
Map<String, LinkedHashSet<Integer>> intValuesMap = new Object2ObjectOpenHashMap<>();
List<CustomBlockPermutation> permutations = new ArrayList<>(); List<CustomBlockPermutation> permutations = new ArrayList<>();
Map<String, Function<CustomBlockState.Builder, CustomBlockState>> blockStateBuilders = new Object2ObjectOpenHashMap<>(); Map<String, Function<CustomBlockState.Builder, CustomBlockState>> blockStateBuilders = new Object2ObjectOpenHashMap<>();
@ -256,33 +254,18 @@ public class MappingsReader_v1 extends MappingsReader {
String property = parts[0]; String property = parts[0];
String value = parts[1]; String value = parts[1];
// Figure out what property type we are dealing with valuesMap.computeIfAbsent(property, k -> new LinkedHashSet<>())
if (value.equals("true") || value.equals("false")) { .add(value);
customBlockDataBuilder.booleanProperty(property);
conditions[i] = String.format("q.block_property('%s') == %s", property, value); conditions[i] = String.format("q.block_property('%s') == '%s'", property, value);
blockStateBuilder = blockStateBuilder.andThen(builder -> builder.booleanProperty(property, value.equals("true"))); blockStateBuilder = blockStateBuilder.andThen(builder -> builder.stringProperty(property, value));
} 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));
}
} }
permutations.add(new CustomBlockPermutation(entry.getValue(), String.join(" && ", conditions))); permutations.add(new CustomBlockPermutation(entry.getValue(), String.join(" && ", conditions)));
blockStateBuilders.put(state, blockStateBuilder.andThen(CustomBlockState.Builder::build)); blockStateBuilders.put(state, blockStateBuilder.andThen(CustomBlockState.Builder::build));
} }
// Define properties for the custom block
stringValuesMap.forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<>(value))); valuesMap.forEach((key, value) -> customBlockDataBuilder.stringProperty(key, new ArrayList<>(value)));
intValuesMap.forEach((key, value) -> customBlockDataBuilder.intProperty(key, new ArrayList<>(value)));
CustomBlockData customBlockData = customBlockDataBuilder CustomBlockData customBlockData = customBlockDataBuilder
.permutations(permutations) .permutations(permutations)