Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 22:40:18 +01:00
Merge pull request #3 from davchoo/feature/blocky
Fix block registry scanning in MappingsReader
Dieser Commit ist enthalten in:
Commit
d14ca99a52
@ -97,8 +97,9 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||||||
String identifier = Identifier.formalize(entry.getKey());
|
String identifier = Identifier.formalize(entry.getKey());
|
||||||
CustomBlockMapping customBlockMapping = this.readBlockMappingEntry(identifier, entry.getValue());
|
CustomBlockMapping customBlockMapping = this.readBlockMappingEntry(identifier, entry.getValue());
|
||||||
consumer.accept(identifier, customBlockMapping);
|
consumer.accept(identifier, customBlockMapping);
|
||||||
} catch (InvalidCustomMappingsFileException e) {
|
} catch (Exception e) {
|
||||||
GeyserImpl.getInstance().getLogger().error("Error in registering blocks for custom mapping file: " + file.toString(), e);
|
GeyserImpl.getInstance().getLogger().error("Error in registering blocks for custom mapping file: " + file.toString());
|
||||||
|
GeyserImpl.getInstance().getLogger().error("due to entry: " + entry, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -187,13 +188,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
|
// 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();
|
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())) {
|
// Create the data for the overall block
|
||||||
throw new InvalidCustomMappingsFileException("Block entry for " + identifier + " has only_override_states set to true, but has no state_overrides.");
|
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<String, CustomBlockComponents> componentsMap = new LinkedHashMap<>();
|
Map<String, CustomBlockComponents> componentsMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
JsonNode stateOverrides = node.get("state_overrides");
|
||||||
if (stateOverrides != null && stateOverrides.isObject()) {
|
if (stateOverrides != null && stateOverrides.isObject()) {
|
||||||
// Load components for specific Java block states
|
// Load components for specific Java block states
|
||||||
Iterator<Map.Entry<String, JsonNode>> fields = stateOverrides.fields();
|
Iterator<Map.Entry<String, JsonNode>> fields = stateOverrides.fields();
|
||||||
@ -206,11 +216,15 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||||||
componentsMap.put(state, createCustomBlockComponents(overrideEntry.getValue(), state, name));
|
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) {
|
if (!onlyOverrideStates) {
|
||||||
// Create components for any remaining Java block states
|
// Create components for any remaining Java block states
|
||||||
BlockRegistries.JAVA_IDENTIFIERS.get().keySet()
|
BlockRegistries.JAVA_IDENTIFIERS.get().keySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(s -> s.startsWith(identifier))
|
.filter(s -> s.startsWith(identifier + "["))
|
||||||
.filter(Predicate.not(componentsMap::containsKey))
|
.filter(Predicate.not(componentsMap::containsKey))
|
||||||
.forEach(state -> componentsMap.put(state, createCustomBlockComponents(null, state, name)));
|
.forEach(state -> componentsMap.put(state, createCustomBlockComponents(null, state, name)));
|
||||||
}
|
}
|
||||||
@ -219,18 +233,11 @@ public class MappingsReader_v1 extends MappingsReader {
|
|||||||
throw new InvalidCustomMappingsFileException("Unknown Java block: " + identifier);
|
throw new InvalidCustomMappingsFileException("Unknown Java block: " + identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the data for the overall block
|
// We pass in the first state and just use the hitbox from that as the default
|
||||||
CustomBlockData.Builder customBlockDataBuilder = new CustomBlockDataBuilder()
|
// Each state will have its own so this is fine
|
||||||
.name(name)
|
String firstState = componentsMap.keySet().iterator().next();
|
||||||
// We pass in the first state and just use the hitbox from that as the default
|
customBlockDataBuilder.components(createCustomBlockComponents(node, firstState, name));
|
||||||
// Each state will have its own so this is fine
|
|
||||||
.components(createCustomBlockComponents(node, componentsMap.keySet().iterator().next(), 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);
|
return createCustomBlockMapping(customBlockDataBuilder, componentsMap, identifier, !onlyOverrideStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class CustomSkullRegistryPopulator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
skinHashes.forEach((skinHash) -> {
|
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.");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren