From a91b531f99d0769082916be415f58852e67f18b7 Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:00:05 -0500 Subject: [PATCH 1/3] Fix block registry scan in MappingsReader --- .../mappings/versions/MappingsReader_v1.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 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 853808afc..81224a5f9 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 @@ -187,13 +187,22 @@ public class MappingsReader_v1 extends MappingsReader { // If this is true, we will only register the states the user has specified rather than all the possible block states boolean onlyOverrideStates = node.has("only_override_states") && node.get("only_override_states").asBoolean(); - JsonNode stateOverrides = node.get("state_overrides"); - if (onlyOverrideStates && (stateOverrides == null || !stateOverrides.isObject())) { - throw new InvalidCustomMappingsFileException("Block entry for " + identifier + " has only_override_states set to true, but has no state_overrides."); + // Create the data for the overall block + CustomBlockData.Builder customBlockDataBuilder = new CustomBlockDataBuilder() + .name(name); + + if (BlockRegistries.JAVA_IDENTIFIERS.get().containsKey(identifier)) { + // There is only one Java block state to override + CustomBlockData blockData = customBlockDataBuilder + .components(createCustomBlockComponents(node, identifier, name)) + .build(); + return new CustomBlockMapping(blockData, Map.of(identifier, blockData.defaultBlockState()), identifier, !onlyOverrideStates); } Map componentsMap = new LinkedHashMap<>(); + + JsonNode stateOverrides = node.get("state_overrides"); if (stateOverrides != null && stateOverrides.isObject()) { // Load components for specific Java block states Iterator> fields = stateOverrides.fields(); @@ -206,11 +215,15 @@ public class MappingsReader_v1 extends MappingsReader { componentsMap.put(state, createCustomBlockComponents(overrideEntry.getValue(), state, name)); } } + if (componentsMap.isEmpty() && onlyOverrideStates) { + throw new InvalidCustomMappingsFileException("Block entry for " + identifier + " has only_override_states set to true, but has no state_overrides."); + } + if (!onlyOverrideStates) { // Create components for any remaining Java block states BlockRegistries.JAVA_IDENTIFIERS.get().keySet() .stream() - .filter(s -> s.startsWith(identifier)) + .filter(s -> s.startsWith(identifier + "[")) .filter(Predicate.not(componentsMap::containsKey)) .forEach(state -> componentsMap.put(state, createCustomBlockComponents(null, state, name))); } @@ -219,18 +232,11 @@ public class MappingsReader_v1 extends MappingsReader { throw new InvalidCustomMappingsFileException("Unknown Java block: " + identifier); } - // Create the data for the overall block - CustomBlockData.Builder customBlockDataBuilder = new CustomBlockDataBuilder() - .name(name) - // We pass in the first state and just use the hitbox from that as the default - // Each state will have its own so this is fine - .components(createCustomBlockComponents(node, componentsMap.keySet().iterator().next(), name)); + // We pass in the first state and just use the hitbox from that as the default + // Each state will have its own so this is fine + String firstState = componentsMap.keySet().iterator().next(); + customBlockDataBuilder.components(createCustomBlockComponents(node, firstState, name)); - if (componentsMap.size() == 1) { - // There are no other block states, so skip creating properties and permutations - CustomBlockData blockData = customBlockDataBuilder.build(); - return new CustomBlockMapping(blockData, Map.of(identifier, blockData.defaultBlockState()), identifier, !onlyOverrideStates); - } return createCustomBlockMapping(customBlockDataBuilder, componentsMap, identifier, !onlyOverrideStates); } From cbe72561253d54d7d43bb767744c976fc35cc82f Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:02:18 -0500 Subject: [PATCH 2/3] Skin hashes can have less than 64 characters? --- .../geyser/registry/populator/CustomSkullRegistryPopulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java index 6210f1081..bd1b4db99 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java @@ -116,7 +116,7 @@ public class CustomSkullRegistryPopulator { }); skinHashes.forEach((skinHash) -> { - if (!skinHash.matches("^[a-fA-F0-9]{64}$")) { + if (!skinHash.matches("^[a-fA-F0-9]+$")) { GeyserImpl.getInstance().getLogger().error("Skin hash " + skinHash + " does not match required format ^[a-fA-F0-9]{64}$ and will not be added as a custom block."); return; } From 7bc0bde37988ae3da902e92b34f21f1e370a7f7e Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:34:28 -0500 Subject: [PATCH 3/3] Include entry when logging exceptions from block mappings --- .../geyser/registry/mappings/versions/MappingsReader_v1.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 81224a5f9..052864656 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 @@ -97,8 +97,9 @@ public class MappingsReader_v1 extends MappingsReader { String identifier = Identifier.formalize(entry.getKey()); CustomBlockMapping customBlockMapping = this.readBlockMappingEntry(identifier, entry.getValue()); consumer.accept(identifier, customBlockMapping); - } catch (InvalidCustomMappingsFileException e) { - GeyserImpl.getInstance().getLogger().error("Error in registering blocks for custom mapping file: " + file.toString(), e); + } catch (Exception e) { + GeyserImpl.getInstance().getLogger().error("Error in registering blocks for custom mapping file: " + file.toString()); + GeyserImpl.getInstance().getLogger().error("due to entry: " + entry, e); } } });