Skip to content

Commit

Permalink
Fixed custom block handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Jan 2, 2024
1 parent a60e932 commit ef99461
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,32 @@ public BlockStateRewriter(final BlockProperties[] blockProperties, final boolean
this.legacyBlockStateIdMappings.defaultReturnValue(-1);

final List<BedrockBlockState> bedrockBlockStates = new ArrayList<>(BedrockProtocol.MAPPINGS.getBedrockBlockStates());
final List<BedrockBlockState> customBlockStates = new ArrayList<>();
final Map<BlockState, Integer> javaBlockStates = BedrockProtocol.MAPPINGS.getJavaBlockStates();
final Map<BlockState, BlockState> bedrockToJavaBlockStates = BedrockProtocol.MAPPINGS.getBedrockToJavaBlockStates();
final Map<String, String> blockTags = BedrockProtocol.MAPPINGS.getBedrockBlockTags();
final Set<String> bedrockBlockIdentifiers = bedrockBlockStates.stream().map(BedrockBlockState::namespacedIdentifier).collect(Collectors.toSet());
final List<BedrockBlockState> customBlockStates = new ArrayList<>();

final Map<String, CompoundTag> effectiveBlockProperties = new HashMap<>();
for (BlockProperties blockProperty : blockProperties) {
final String identifier = Key.namespaced(blockProperty.name().toLowerCase(Locale.ROOT));
if (bedrockBlockIdentifiers.contains(identifier)) {
continue; // Mojang client does not allow overriding vanilla block states
}

if (!effectiveBlockProperties.containsKey(identifier)) {
effectiveBlockProperties.put(identifier, blockProperty.properties());
}
}

for (Map.Entry<String, CompoundTag> blockProperty : effectiveBlockProperties.entrySet()) {
if (!(blockProperty.getValue().get("menu_category") instanceof CompoundTag)) { // Mojang client crashes if this tag is missing
throw new IllegalStateException("Missing menu_category tag for " + blockProperty.getKey());
}

final Map<String, Set<Tag>> propertiesMap = new LinkedHashMap<>();
if (blockProperty.properties().get("properties") instanceof ListTag) {
final ListTag properties = blockProperty.properties().get("properties");
if (blockProperty.getValue().get("properties") instanceof ListTag) { // https://wiki.bedrock.dev/blocks/block-states.html
final ListTag properties = blockProperty.getValue().get("properties");
if (CompoundTag.class.equals(properties.getElementType())) {
for (Tag propertyTag : properties) {
final CompoundTag property = (CompoundTag) propertyTag;
Expand All @@ -82,8 +99,8 @@ public BlockStateRewriter(final BlockProperties[] blockProperties, final boolean
}
}
}
if (blockProperty.properties().get("traits") instanceof ListTag) { // https://wiki.bedrock.dev/blocks/block-traits.html
final ListTag traits = blockProperty.properties().get("traits");
if (blockProperty.getValue().get("traits") instanceof ListTag) { // https://wiki.bedrock.dev/blocks/block-traits.html
final ListTag traits = blockProperty.getValue().get("traits");
if (CompoundTag.class.equals(traits.getElementType())) {
for (Tag traitTag : traits) {
final CompoundTag trait = (CompoundTag) traitTag;
Expand Down Expand Up @@ -138,7 +155,7 @@ public BlockStateRewriter(final BlockProperties[] blockProperties, final boolean

for (CompoundTag combination : combinations) {
final CompoundTag blockStateTag = new CompoundTag();
blockStateTag.put("name", new StringTag(blockProperty.name()));
blockStateTag.put("name", new StringTag(blockProperty.getKey()));
blockStateTag.put("states", combination);
blockStateTag.put("network_id", new IntTag(BlockStateHasher.hash(blockStateTag)));

Expand Down

0 comments on commit ef99461

Please sign in to comment.