mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-23 07:16:39 +01:00
Remove try/catch from BlockTranslator and ItemTranslator
This commit is contained in:
parent
e60f47f65d
commit
54f6fada12
2 changed files with 115 additions and 126 deletions
|
@ -100,42 +100,37 @@ public class ItemRegistry {
|
|||
int itemIndex = 0;
|
||||
Iterator<Map.Entry<String, JsonNode>> iterator = items.fields();
|
||||
while (iterator.hasNext()) {
|
||||
try {
|
||||
Map.Entry<String, JsonNode> entry = iterator.next();
|
||||
if (entry.getValue().has("tool_type")) {
|
||||
if (entry.getValue().has("tool_tier")) {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
entry.getValue().get("tool_tier").textValue(),
|
||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
"",
|
||||
entry.getValue().get("is_block").booleanValue()));
|
||||
}
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ItemEntry(
|
||||
Map.Entry<String, JsonNode> entry = iterator.next();
|
||||
if (entry.getValue().has("tool_type")) {
|
||||
if (entry.getValue().has("tool_tier")) {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
entry.getValue().get("tool_tier").textValue(),
|
||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
"",
|
||||
entry.getValue().get("is_block").booleanValue()));
|
||||
}
|
||||
if (entry.getKey().equals("minecraft:barrier")) {
|
||||
BARRIER_INDEX = itemIndex;
|
||||
}
|
||||
|
||||
itemIndex++;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception in item registry! " + e.toString());
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||
}
|
||||
if (entry.getKey().equals("minecraft:barrier")) {
|
||||
BARRIER_INDEX = itemIndex;
|
||||
}
|
||||
|
||||
itemIndex++;
|
||||
}
|
||||
|
||||
/* Load creative items */
|
||||
|
|
|
@ -117,104 +117,98 @@ public class BlockTranslator {
|
|||
int spawnerRuntimeId = -1;
|
||||
Iterator<Map.Entry<String, JsonNode>> blocksIterator = blocks.fields();
|
||||
while (blocksIterator.hasNext()) {
|
||||
try {
|
||||
javaRuntimeId++;
|
||||
Map.Entry<String, JsonNode> entry = blocksIterator.next();
|
||||
String javaId = entry.getKey();
|
||||
CompoundTag blockTag = buildBedrockState(entry.getValue());
|
||||
javaRuntimeId++;
|
||||
Map.Entry<String, JsonNode> entry = blocksIterator.next();
|
||||
String javaId = entry.getKey();
|
||||
CompoundTag blockTag = buildBedrockState(entry.getValue());
|
||||
|
||||
// TODO fix this, (no block should have a null hardness)
|
||||
JsonNode hardnessNode = entry.getValue().get("block_hardness");
|
||||
if (hardnessNode != null) {
|
||||
JAVA_RUNTIME_ID_TO_HARDNESS.put(javaRuntimeId, hardnessNode.doubleValue());
|
||||
}
|
||||
|
||||
try {
|
||||
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue());
|
||||
} catch (Exception e) {
|
||||
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, false);
|
||||
}
|
||||
|
||||
JsonNode toolTypeNode = entry.getValue().get("tool_type");
|
||||
if (toolTypeNode != null) {
|
||||
JAVA_RUNTIME_ID_TO_TOOL_TYPE.put(javaRuntimeId, toolTypeNode.textValue());
|
||||
}
|
||||
|
||||
if (javaId.contains("wool")) {
|
||||
JAVA_RUNTIME_WOOL_IDS.add(javaRuntimeId);
|
||||
}
|
||||
|
||||
if (javaId.contains("cobweb")) {
|
||||
cobwebRuntimeId = javaRuntimeId;
|
||||
}
|
||||
|
||||
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
||||
|
||||
// Used for adding all "special" Java block states to block state map
|
||||
String identifier;
|
||||
String bedrock_identifer = entry.getValue().get("bedrock_identifier").asText();
|
||||
for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
|
||||
identifier = clazz.getAnnotation(BlockEntity.class).regex();
|
||||
// Endswith, or else the block bedrock gets picked up for bed
|
||||
if (bedrock_identifer.endsWith(identifier) && !identifier.equals("")) {
|
||||
JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaRuntimeId, clazz.getAnnotation(BlockEntity.class).name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
||||
|
||||
// Get the tag needed for non-empty flower pots
|
||||
if (entry.getValue().get("pottable") != null) {
|
||||
BlockStateValues.getFlowerPotBlocks().put(entry.getKey().split("\\[")[0], buildBedrockState(entry.getValue()));
|
||||
}
|
||||
|
||||
if ("minecraft:water[level=0]".equals(javaId)) {
|
||||
waterRuntimeId = bedrockRuntimeId;
|
||||
}
|
||||
boolean waterlogged = entry.getKey().contains("waterlogged=true")
|
||||
|| javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");
|
||||
|
||||
if (waterlogged) {
|
||||
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, javaRuntimeId);
|
||||
WATERLOGGED.add(javaRuntimeId);
|
||||
} else {
|
||||
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId);
|
||||
}
|
||||
|
||||
CompoundTag runtimeTag = blockStateMap.remove(blockTag);
|
||||
if (runtimeTag != null) {
|
||||
addedStatesMap.put(blockTag, bedrockRuntimeId);
|
||||
paletteList.add(runtimeTag);
|
||||
} else {
|
||||
int duplicateRuntimeId = addedStatesMap.getOrDefault(blockTag, -1);
|
||||
if (duplicateRuntimeId == -1) {
|
||||
GeyserConnector.getInstance().getLogger().debug("Mapping " + javaId + " was not found for bedrock edition!");
|
||||
} else {
|
||||
JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, duplicateRuntimeId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, bedrockRuntimeId);
|
||||
|
||||
if (javaId.startsWith("minecraft:furnace[facing=north")) {
|
||||
if (javaId.contains("lit=true")) {
|
||||
furnaceLitRuntimeId = javaRuntimeId;
|
||||
} else {
|
||||
furnaceRuntimeId = javaRuntimeId;
|
||||
}
|
||||
}
|
||||
|
||||
if (javaId.startsWith("minecraft:spawner")) {
|
||||
spawnerRuntimeId = javaRuntimeId;
|
||||
}
|
||||
|
||||
bedrockRuntimeId++;
|
||||
} catch (Exception e) {
|
||||
// REMOVE AFTER 1.16 UPDATE PROBABLY
|
||||
System.out.println("Block translator error! " + e.toString());
|
||||
e.printStackTrace();
|
||||
// TODO fix this, (no block should have a null hardness)
|
||||
JsonNode hardnessNode = entry.getValue().get("block_hardness");
|
||||
if (hardnessNode != null) {
|
||||
JAVA_RUNTIME_ID_TO_HARDNESS.put(javaRuntimeId, hardnessNode.doubleValue());
|
||||
}
|
||||
|
||||
try {
|
||||
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue());
|
||||
} catch (Exception e) {
|
||||
JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, false);
|
||||
}
|
||||
|
||||
JsonNode toolTypeNode = entry.getValue().get("tool_type");
|
||||
if (toolTypeNode != null) {
|
||||
JAVA_RUNTIME_ID_TO_TOOL_TYPE.put(javaRuntimeId, toolTypeNode.textValue());
|
||||
}
|
||||
|
||||
if (javaId.contains("wool")) {
|
||||
JAVA_RUNTIME_WOOL_IDS.add(javaRuntimeId);
|
||||
}
|
||||
|
||||
if (javaId.contains("cobweb")) {
|
||||
cobwebRuntimeId = javaRuntimeId;
|
||||
}
|
||||
|
||||
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
||||
|
||||
// Used for adding all "special" Java block states to block state map
|
||||
String identifier;
|
||||
String bedrock_identifer = entry.getValue().get("bedrock_identifier").asText();
|
||||
for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
|
||||
identifier = clazz.getAnnotation(BlockEntity.class).regex();
|
||||
// Endswith, or else the block bedrock gets picked up for bed
|
||||
if (bedrock_identifer.endsWith(identifier) && !identifier.equals("")) {
|
||||
JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaRuntimeId, clazz.getAnnotation(BlockEntity.class).name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
||||
|
||||
// Get the tag needed for non-empty flower pots
|
||||
if (entry.getValue().get("pottable") != null) {
|
||||
BlockStateValues.getFlowerPotBlocks().put(entry.getKey().split("\\[")[0], buildBedrockState(entry.getValue()));
|
||||
}
|
||||
|
||||
if ("minecraft:water[level=0]".equals(javaId)) {
|
||||
waterRuntimeId = bedrockRuntimeId;
|
||||
}
|
||||
boolean waterlogged = entry.getKey().contains("waterlogged=true")
|
||||
|| javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");
|
||||
|
||||
if (waterlogged) {
|
||||
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, javaRuntimeId);
|
||||
WATERLOGGED.add(javaRuntimeId);
|
||||
} else {
|
||||
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId);
|
||||
}
|
||||
|
||||
CompoundTag runtimeTag = blockStateMap.remove(blockTag);
|
||||
if (runtimeTag != null) {
|
||||
addedStatesMap.put(blockTag, bedrockRuntimeId);
|
||||
paletteList.add(runtimeTag);
|
||||
} else {
|
||||
int duplicateRuntimeId = addedStatesMap.getOrDefault(blockTag, -1);
|
||||
if (duplicateRuntimeId == -1) {
|
||||
GeyserConnector.getInstance().getLogger().debug("Mapping " + javaId + " was not found for bedrock edition!");
|
||||
} else {
|
||||
JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, duplicateRuntimeId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, bedrockRuntimeId);
|
||||
|
||||
if (javaId.startsWith("minecraft:furnace[facing=north")) {
|
||||
if (javaId.contains("lit=true")) {
|
||||
furnaceLitRuntimeId = javaRuntimeId;
|
||||
} else {
|
||||
furnaceRuntimeId = javaRuntimeId;
|
||||
}
|
||||
}
|
||||
|
||||
if (javaId.startsWith("minecraft:spawner")) {
|
||||
spawnerRuntimeId = javaRuntimeId;
|
||||
}
|
||||
|
||||
bedrockRuntimeId++;
|
||||
}
|
||||
|
||||
if (cobwebRuntimeId == -1) {
|
||||
|
|
Loading…
Reference in a new issue