2021-07-13 01:19:40 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2021-07-13 01:19:40 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.registry.populator;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
2022-06-24 20:48:28 +00:00
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
2021-07-13 01:19:40 +00:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.nukkitx.nbt.*;
|
2022-08-07 16:09:54 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544;
|
2022-11-29 02:53:17 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
|
2023-02-05 18:29:28 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v567.Bedrock_v567;
|
2021-09-04 17:36:09 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
|
|
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
2021-07-13 01:19:40 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
2021-09-19 19:20:42 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectIntPair;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.level.block.BlockStateValues;
|
2021-11-28 16:03:45 +00:00
|
|
|
import org.geysermc.geyser.level.physics.PistonBehavior;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.BlockRegistries;
|
|
|
|
import org.geysermc.geyser.registry.type.BlockMapping;
|
|
|
|
import org.geysermc.geyser.registry.type.BlockMappings;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.util.BlockUtils;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.InputStream;
|
2022-02-06 22:15:12 +00:00
|
|
|
import java.util.ArrayDeque;
|
|
|
|
import java.util.Deque;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
2021-07-13 01:19:40 +00:00
|
|
|
import java.util.function.BiFunction;
|
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
|
2021-07-22 02:14:00 +00:00
|
|
|
/**
|
|
|
|
* Populates the block registries.
|
|
|
|
*/
|
2022-08-07 16:09:54 +00:00
|
|
|
public final class BlockRegistryPopulator {
|
2021-07-13 01:19:40 +00:00
|
|
|
/**
|
|
|
|
* Stores the raw blocks JSON until it is no longer needed.
|
|
|
|
*/
|
|
|
|
private static JsonNode BLOCKS_JSON;
|
|
|
|
|
|
|
|
public static void populate() {
|
|
|
|
registerJavaBlocks();
|
|
|
|
registerBedrockBlocks();
|
|
|
|
|
|
|
|
BLOCKS_JSON = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void registerBedrockBlocks() {
|
2022-08-07 16:09:54 +00:00
|
|
|
BiFunction<String, NbtMapBuilder, String> emptyMapper = (bedrockIdentifier, statesBuilder) -> null;
|
|
|
|
ImmutableMap<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> blockMappers = ImmutableMap.<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>>builder()
|
2022-11-29 02:53:17 +00:00
|
|
|
.put(ObjectIntPair.of("1_19_20", Bedrock_v544.V544_CODEC.getProtocolVersion()), emptyMapper)
|
|
|
|
.put(ObjectIntPair.of("1_19_50", Bedrock_v560.V560_CODEC.getProtocolVersion()), emptyMapper)
|
2023-02-05 18:29:28 +00:00
|
|
|
.put(ObjectIntPair.of("1_19_60", Bedrock_v567.V567_CODEC.getProtocolVersion()), emptyMapper)
|
2023-03-14 19:37:57 +00:00
|
|
|
.put(ObjectIntPair.of("1_19_70", 575), (bedrockIdentifier, statesBuilder) -> {
|
|
|
|
if (bedrockIdentifier.equals("minecraft:wool")) {
|
|
|
|
String color = (String) statesBuilder.remove("color");
|
|
|
|
if ("silver".equals(color)) {
|
|
|
|
color = "light_gray";
|
|
|
|
}
|
|
|
|
return "minecraft:" + color + "_wool";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
})
|
2022-11-29 02:53:17 +00:00
|
|
|
.build();
|
2022-08-07 16:09:54 +00:00
|
|
|
|
|
|
|
for (Map.Entry<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> palette : blockMappers.entrySet()) {
|
2021-07-13 01:19:40 +00:00
|
|
|
NbtList<NbtMap> blocksTag;
|
2021-12-03 16:01:06 +00:00
|
|
|
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(String.format("bedrock/block_palette.%s.nbt", palette.getKey().key()));
|
|
|
|
NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) {
|
2021-07-13 01:19:40 +00:00
|
|
|
NbtMap blockPalette = (NbtMap) nbtInputStream.readTag();
|
|
|
|
blocksTag = (NbtList<NbtMap>) blockPalette.getList("blocks", NbtType.COMPOUND);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to get blocks from runtime block states", e);
|
|
|
|
}
|
|
|
|
// New since 1.16.100 - find the block runtime ID by the order given to us in the block palette,
|
|
|
|
// as we no longer send a block palette
|
|
|
|
Object2IntMap<NbtMap> blockStateOrderedMap = new Object2IntOpenHashMap<>(blocksTag.size());
|
|
|
|
|
|
|
|
int stateVersion = -1;
|
|
|
|
for (int i = 0; i < blocksTag.size(); i++) {
|
2022-08-07 16:09:54 +00:00
|
|
|
NbtMapBuilder builder = blocksTag.get(i).toBuilder();
|
|
|
|
builder.remove("name_hash"); // Quick workaround - was added in 1.19.20
|
|
|
|
NbtMap tag = builder.build();
|
2021-07-13 01:19:40 +00:00
|
|
|
if (blockStateOrderedMap.containsKey(tag)) {
|
|
|
|
throw new AssertionError("Duplicate block states in Bedrock palette: " + tag);
|
|
|
|
}
|
|
|
|
blockStateOrderedMap.put(tag, i);
|
|
|
|
if (stateVersion == -1) {
|
|
|
|
stateVersion = tag.getInt("version");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int airRuntimeId = -1;
|
|
|
|
int commandBlockRuntimeId = -1;
|
|
|
|
int javaRuntimeId = -1;
|
|
|
|
int waterRuntimeId = -1;
|
2021-09-10 01:20:25 +00:00
|
|
|
int movingBlockRuntimeId = -1;
|
2021-07-13 01:19:40 +00:00
|
|
|
Iterator<Map.Entry<String, JsonNode>> blocksIterator = BLOCKS_JSON.fields();
|
|
|
|
|
2022-08-07 16:09:54 +00:00
|
|
|
BiFunction<String, NbtMapBuilder, String> stateMapper = blockMappers.getOrDefault(palette.getKey(), emptyMapper);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-09-04 17:45:32 +00:00
|
|
|
int[] javaToBedrockBlocks = new int[BLOCKS_JSON.size()];
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
Map<String, NbtMap> flowerPotBlocks = new Object2ObjectOpenHashMap<>();
|
|
|
|
Object2IntMap<NbtMap> itemFrames = new Object2IntOpenHashMap<>();
|
|
|
|
|
2021-09-04 17:36:09 +00:00
|
|
|
IntSet jigsawStateIds = new IntOpenHashSet();
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
BlockMappings.BlockMappingsBuilder builder = BlockMappings.builder();
|
|
|
|
while (blocksIterator.hasNext()) {
|
|
|
|
javaRuntimeId++;
|
|
|
|
Map.Entry<String, JsonNode> entry = blocksIterator.next();
|
|
|
|
String javaId = entry.getKey();
|
|
|
|
|
2021-08-12 00:16:10 +00:00
|
|
|
int bedrockRuntimeId = blockStateOrderedMap.getOrDefault(buildBedrockState(entry.getValue(), stateVersion, stateMapper), -1);
|
2021-07-13 01:19:40 +00:00
|
|
|
if (bedrockRuntimeId == -1) {
|
2022-05-25 23:41:31 +00:00
|
|
|
throw new RuntimeException("Unable to find " + javaId + " Bedrock runtime ID! Built NBT tag: \n" +
|
|
|
|
buildBedrockState(entry.getValue(), stateVersion, stateMapper));
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (javaId) {
|
2021-09-10 18:10:56 +00:00
|
|
|
case "minecraft:air" -> airRuntimeId = bedrockRuntimeId;
|
|
|
|
case "minecraft:water[level=0]" -> waterRuntimeId = bedrockRuntimeId;
|
|
|
|
case "minecraft:command_block[conditional=false,facing=north]" -> commandBlockRuntimeId = bedrockRuntimeId;
|
|
|
|
case "minecraft:moving_piston[facing=north,type=normal]" -> movingBlockRuntimeId = bedrockRuntimeId;
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 17:36:09 +00:00
|
|
|
if (javaId.contains("jigsaw")) {
|
|
|
|
jigsawStateIds.add(bedrockRuntimeId);
|
|
|
|
}
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
boolean waterlogged = entry.getKey().contains("waterlogged=true")
|
|
|
|
|| javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");
|
|
|
|
|
|
|
|
if (waterlogged) {
|
|
|
|
int finalJavaRuntimeId = javaRuntimeId;
|
|
|
|
BlockRegistries.WATERLOGGED.register(set -> set.add(finalJavaRuntimeId));
|
|
|
|
}
|
|
|
|
|
2021-07-15 22:03:41 +00:00
|
|
|
String cleanJavaIdentifier = BlockUtils.getCleanIdentifier(entry.getKey());
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
// Get the tag needed for non-empty flower pots
|
|
|
|
if (entry.getValue().get("pottable") != null) {
|
2021-08-12 00:16:10 +00:00
|
|
|
flowerPotBlocks.put(cleanJavaIdentifier.intern(), blocksTag.get(bedrockRuntimeId));
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 17:45:32 +00:00
|
|
|
javaToBedrockBlocks[javaRuntimeId] = bedrockRuntimeId;
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (commandBlockRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find command block in palette");
|
|
|
|
}
|
|
|
|
builder.commandBlockRuntimeId(commandBlockRuntimeId);
|
|
|
|
|
|
|
|
if (waterRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find water in palette");
|
|
|
|
}
|
|
|
|
builder.bedrockWaterId(waterRuntimeId);
|
|
|
|
|
|
|
|
if (airRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find air in palette");
|
|
|
|
}
|
|
|
|
builder.bedrockAirId(airRuntimeId);
|
|
|
|
|
2021-09-10 01:20:25 +00:00
|
|
|
if (movingBlockRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find moving block in palette");
|
|
|
|
}
|
|
|
|
builder.bedrockMovingBlockId(movingBlockRuntimeId);
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
// Loop around again to find all item frame runtime IDs
|
|
|
|
for (Object2IntMap.Entry<NbtMap> entry : blockStateOrderedMap.object2IntEntrySet()) {
|
|
|
|
String name = entry.getKey().getString("name");
|
|
|
|
if (name.equals("minecraft:frame") || name.equals("minecraft:glow_frame")) {
|
|
|
|
itemFrames.put(entry.getKey(), entry.getIntValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
builder.bedrockBlockStates(blocksTag);
|
|
|
|
|
2021-09-19 19:20:42 +00:00
|
|
|
BlockRegistries.BLOCKS.register(palette.getKey().valueInt(), builder.blockStateVersion(stateVersion)
|
2021-09-04 17:45:32 +00:00
|
|
|
.javaToBedrockBlocks(javaToBedrockBlocks)
|
2021-07-13 01:19:40 +00:00
|
|
|
.itemFrames(itemFrames)
|
|
|
|
.flowerPotBlocks(flowerPotBlocks)
|
2021-09-04 17:36:09 +00:00
|
|
|
.jigsawStateIds(jigsawStateIds)
|
2021-07-13 01:19:40 +00:00
|
|
|
.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void registerJavaBlocks() {
|
|
|
|
JsonNode blocksJson;
|
2021-12-03 16:01:06 +00:00
|
|
|
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) {
|
2021-11-20 21:34:30 +00:00
|
|
|
blocksJson = GeyserImpl.JSON_MAPPER.readTree(stream);
|
2021-07-13 01:19:40 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to load Java block mappings", e);
|
|
|
|
}
|
|
|
|
|
2021-09-04 17:36:09 +00:00
|
|
|
BlockRegistries.JAVA_BLOCKS.set(new BlockMapping[blocksJson.size()]); // Set array size to number of blockstates
|
|
|
|
|
2021-12-08 01:05:44 +00:00
|
|
|
Deque<String> cleanIdentifiers = new ArrayDeque<>();
|
2021-07-22 03:18:31 +00:00
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
int javaRuntimeId = -1;
|
|
|
|
int bellBlockId = -1;
|
|
|
|
int cobwebBlockId = -1;
|
|
|
|
int furnaceRuntimeId = -1;
|
|
|
|
int furnaceLitRuntimeId = -1;
|
2021-09-10 01:20:25 +00:00
|
|
|
int honeyBlockRuntimeId = -1;
|
|
|
|
int slimeBlockRuntimeId = -1;
|
2021-07-13 01:19:40 +00:00
|
|
|
int spawnerRuntimeId = -1;
|
|
|
|
int uniqueJavaId = -1;
|
|
|
|
int waterRuntimeId = -1;
|
|
|
|
Iterator<Map.Entry<String, JsonNode>> blocksIterator = blocksJson.fields();
|
|
|
|
while (blocksIterator.hasNext()) {
|
|
|
|
javaRuntimeId++;
|
|
|
|
Map.Entry<String, JsonNode> entry = blocksIterator.next();
|
|
|
|
String javaId = entry.getKey();
|
|
|
|
|
|
|
|
// TODO fix this, (no block should have a null hardness)
|
|
|
|
BlockMapping.BlockMappingBuilder builder = BlockMapping.builder();
|
|
|
|
JsonNode hardnessNode = entry.getValue().get("block_hardness");
|
|
|
|
if (hardnessNode != null) {
|
2022-09-27 23:24:50 +00:00
|
|
|
builder.hardness(hardnessNode.floatValue());
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode canBreakWithHandNode = entry.getValue().get("can_break_with_hand");
|
|
|
|
if (canBreakWithHandNode != null) {
|
|
|
|
builder.canBreakWithHand(canBreakWithHandNode.booleanValue());
|
|
|
|
} else {
|
|
|
|
builder.canBreakWithHand(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode collisionIndexNode = entry.getValue().get("collision_index");
|
|
|
|
if (hardnessNode != null) {
|
|
|
|
builder.collisionIndex(collisionIndexNode.intValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode pickItemNode = entry.getValue().get("pick_item");
|
|
|
|
if (pickItemNode != null) {
|
2021-08-12 00:16:10 +00:00
|
|
|
builder.pickItem(pickItemNode.textValue().intern());
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 22:09:27 +00:00
|
|
|
if (javaId.equals("minecraft:obsidian") || javaId.equals("minecraft:crying_obsidian") || javaId.startsWith("minecraft:respawn_anchor") || javaId.startsWith("minecraft:reinforced_deepslate")) {
|
2021-09-10 01:20:25 +00:00
|
|
|
builder.pistonBehavior(PistonBehavior.BLOCK);
|
|
|
|
} else {
|
|
|
|
JsonNode pistonBehaviorNode = entry.getValue().get("piston_behavior");
|
|
|
|
if (pistonBehaviorNode != null) {
|
|
|
|
builder.pistonBehavior(PistonBehavior.getByName(pistonBehaviorNode.textValue()));
|
|
|
|
} else {
|
|
|
|
builder.pistonBehavior(PistonBehavior.NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode hasBlockEntityNode = entry.getValue().get("has_block_entity");
|
|
|
|
if (hasBlockEntityNode != null) {
|
|
|
|
builder.isBlockEntity(hasBlockEntityNode.booleanValue());
|
|
|
|
} else {
|
|
|
|
builder.isBlockEntity(false);
|
|
|
|
}
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
BlockStateValues.storeBlockStateValues(entry.getKey(), javaRuntimeId, entry.getValue());
|
|
|
|
|
2021-07-17 13:43:25 +00:00
|
|
|
String cleanJavaIdentifier = BlockUtils.getCleanIdentifier(entry.getKey());
|
2021-07-13 01:19:40 +00:00
|
|
|
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
|
|
|
|
|
2021-12-08 01:05:44 +00:00
|
|
|
if (!cleanJavaIdentifier.equals(cleanIdentifiers.peekLast())) {
|
2021-07-13 01:19:40 +00:00
|
|
|
uniqueJavaId++;
|
2021-08-12 00:16:10 +00:00
|
|
|
cleanIdentifiers.add(cleanJavaIdentifier.intern());
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 13:33:38 +00:00
|
|
|
builder.javaIdentifier(javaId);
|
|
|
|
builder.javaBlockId(uniqueJavaId);
|
|
|
|
|
|
|
|
BlockRegistries.JAVA_IDENTIFIERS.register(javaId, javaRuntimeId);
|
|
|
|
BlockRegistries.JAVA_BLOCKS.register(javaRuntimeId, builder.build());
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
// Keeping this here since this is currently unchanged between versions
|
2021-10-12 01:14:06 +00:00
|
|
|
// It's possible to only have this store differences in names, but the key set of all Java names is used in sending command suggestions
|
|
|
|
BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.register(cleanJavaIdentifier.intern(), bedrockIdentifier.intern());
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
if (javaId.startsWith("minecraft:bell[")) {
|
|
|
|
bellBlockId = uniqueJavaId;
|
|
|
|
|
|
|
|
} else if (javaId.contains("cobweb")) {
|
|
|
|
cobwebBlockId = uniqueJavaId;
|
|
|
|
|
|
|
|
} else if (javaId.startsWith("minecraft:furnace[facing=north")) {
|
|
|
|
if (javaId.contains("lit=true")) {
|
|
|
|
furnaceLitRuntimeId = javaRuntimeId;
|
|
|
|
} else {
|
|
|
|
furnaceRuntimeId = javaRuntimeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (javaId.startsWith("minecraft:spawner")) {
|
|
|
|
spawnerRuntimeId = javaRuntimeId;
|
|
|
|
|
|
|
|
} else if ("minecraft:water[level=0]".equals(javaId)) {
|
|
|
|
waterRuntimeId = javaRuntimeId;
|
2021-09-10 01:20:25 +00:00
|
|
|
} else if (javaId.equals("minecraft:honey_block")) {
|
|
|
|
honeyBlockRuntimeId = javaRuntimeId;
|
|
|
|
} else if (javaId.equals("minecraft:slime_block")) {
|
|
|
|
slimeBlockRuntimeId = javaRuntimeId;
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bellBlockId == -1) {
|
|
|
|
throw new AssertionError("Unable to find bell in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_BELL_ID = bellBlockId;
|
|
|
|
|
|
|
|
if (cobwebBlockId == -1) {
|
|
|
|
throw new AssertionError("Unable to find cobwebs in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_COBWEB_ID = cobwebBlockId;
|
|
|
|
|
|
|
|
if (furnaceRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find furnace in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_FURNACE_ID = furnaceRuntimeId;
|
|
|
|
|
|
|
|
if (furnaceLitRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find lit furnace in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_FURNACE_LIT_ID = furnaceLitRuntimeId;
|
2021-09-10 01:20:25 +00:00
|
|
|
|
|
|
|
if (honeyBlockRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find honey block in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_HONEY_BLOCK_ID = honeyBlockRuntimeId;
|
|
|
|
|
|
|
|
if (slimeBlockRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find slime block in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_SLIME_BLOCK_ID = slimeBlockRuntimeId;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
if (spawnerRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find spawner in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_SPAWNER_ID = spawnerRuntimeId;
|
|
|
|
|
|
|
|
if (waterRuntimeId == -1) {
|
|
|
|
throw new AssertionError("Unable to find Java water in palette");
|
|
|
|
}
|
|
|
|
BlockStateValues.JAVA_WATER_ID = waterRuntimeId;
|
|
|
|
|
2021-12-08 01:05:44 +00:00
|
|
|
BlockRegistries.CLEAN_JAVA_IDENTIFIERS.set(cleanIdentifiers.toArray(new String[0]));
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
BLOCKS_JSON = blocksJson;
|
2022-06-24 20:48:28 +00:00
|
|
|
|
|
|
|
JsonNode blockInteractionsJson;
|
|
|
|
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/interactions.json")) {
|
|
|
|
blockInteractionsJson = GeyserImpl.JSON_MAPPER.readTree(stream);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to load Java block interaction mappings", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockRegistries.INTERACTIVE.set(toBlockStateSet((ArrayNode) blockInteractionsJson.get("always_consumes")));
|
|
|
|
BlockRegistries.INTERACTIVE_MAY_BUILD.set(toBlockStateSet((ArrayNode) blockInteractionsJson.get("requires_may_build")));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static IntSet toBlockStateSet(ArrayNode node) {
|
|
|
|
IntSet blockStateSet = new IntOpenHashSet(node.size());
|
|
|
|
for (JsonNode javaIdentifier : node) {
|
|
|
|
blockStateSet.add(BlockRegistries.JAVA_IDENTIFIERS.get().getInt(javaIdentifier.textValue()));
|
|
|
|
}
|
|
|
|
return blockStateSet;
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static NbtMap buildBedrockState(JsonNode node, int blockStateVersion, BiFunction<String, NbtMapBuilder, String> statesMapper) {
|
|
|
|
NbtMapBuilder tagBuilder = NbtMap.builder();
|
|
|
|
String bedrockIdentifier = node.get("bedrock_identifier").textValue();
|
|
|
|
tagBuilder.putString("name", bedrockIdentifier)
|
|
|
|
.putInt("version", blockStateVersion);
|
|
|
|
|
|
|
|
NbtMapBuilder statesBuilder = NbtMap.builder();
|
|
|
|
|
|
|
|
// check for states
|
|
|
|
if (node.has("bedrock_states")) {
|
|
|
|
Iterator<Map.Entry<String, JsonNode>> statesIterator = node.get("bedrock_states").fields();
|
|
|
|
|
|
|
|
while (statesIterator.hasNext()) {
|
|
|
|
Map.Entry<String, JsonNode> stateEntry = statesIterator.next();
|
|
|
|
JsonNode stateValue = stateEntry.getValue();
|
|
|
|
switch (stateValue.getNodeType()) {
|
2021-09-10 18:10:56 +00:00
|
|
|
case BOOLEAN -> statesBuilder.putBoolean(stateEntry.getKey(), stateValue.booleanValue());
|
|
|
|
case STRING -> statesBuilder.putString(stateEntry.getKey(), stateValue.textValue());
|
|
|
|
case NUMBER -> statesBuilder.putInt(stateEntry.getKey(), stateValue.intValue());
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String newIdentifier = statesMapper.apply(bedrockIdentifier, statesBuilder);
|
|
|
|
if (newIdentifier != null) {
|
|
|
|
tagBuilder.putString("name", newIdentifier);
|
|
|
|
}
|
|
|
|
tagBuilder.put("states", statesBuilder.build());
|
|
|
|
return tagBuilder.build();
|
|
|
|
}
|
|
|
|
}
|