From 117cdf282d0379fffbdc10af5eda050019a4a321 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sat, 20 Jun 2020 22:24:45 -0400 Subject: [PATCH] Begin updating Geyser. Requires manual MCProtocolLib compile --- connector/pom.xml | 2 +- .../org/geysermc/connector/entity/Entity.java | 4 +- .../entity/attribute/AttributeType.java | 24 +-- .../connector/entity/type/EntityType.java | 3 +- .../network/session/GeyserSession.java | 7 +- .../BedrockAdventureSettingsTranslator.java | 2 +- .../bedrock/BedrockInteractTranslator.java | 4 +- ...BedrockInventoryTransactionTranslator.java | 12 +- .../BedrockItemFrameDropItemTranslator.java | 2 +- .../translators/item/ItemRegistry.java | 55 +++--- .../java/JavaJoinGameTranslator.java | 2 +- .../java/JavaRespawnTranslator.java | 4 +- .../java/world/JavaMapDataTranslator.java | 3 +- .../world/JavaSpawnParticleTranslator.java | 3 +- .../world/block/BlockTranslator.java | 158 ++++++++++-------- .../connector/utils/DimensionUtils.java | 25 ++- .../connector/utils/MessageUtils.java | 62 +++---- 17 files changed, 198 insertions(+), 174 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 34798931e..0f1e60819 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -105,7 +105,7 @@ com.github.steveice10 mcprotocollib - 013e8e6dc4 + 1.16-rc1-SNAPSHOT compile diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 0b7b23fee..aa38441c7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -67,7 +67,7 @@ public class Entity { protected long entityId; protected long geyserId; - protected int dimension; + protected String dimension; protected Vector3f position; protected Vector3f motion; @@ -100,7 +100,7 @@ public class Entity { this.rotation = rotation; this.valid = false; - this.dimension = 0; + this.dimension = "minecraft:overworld"; setPosition(position); diff --git a/connector/src/main/java/org/geysermc/connector/entity/attribute/AttributeType.java b/connector/src/main/java/org/geysermc/connector/entity/attribute/AttributeType.java index 2061b8953..1d692e2a7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/attribute/AttributeType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/attribute/AttributeType.java @@ -33,20 +33,20 @@ import lombok.Getter; public enum AttributeType { // Universal Attributes - FOLLOW_RANGE("generic.followRange", "minecraft:follow_range", 0f, 2048f, 32f), - KNOCKBACK_RESISTANCE("generic.knockbackResistance", "minecraft:knockback_resistance", 0f, 1f, 0f), - MOVEMENT_SPEED("generic.movementSpeed", "minecraft:movement", 0f, 1024f, 0.1f), - FLYING_SPEED("generic.flyingSpeed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f), - ATTACK_DAMAGE("generic.attackDamage", "minecraft:attack_damage", 0f, 2048f, 1f), - HORSE_JUMP_STRENGTH("horse.jumpStrength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f), + FOLLOW_RANGE("minecraft:generic.follow_range", "minecraft:follow_range", 0f, 2048f, 32f), + KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", "minecraft:knockback_resistance", 0f, 1f, 0f), + MOVEMENT_SPEED("minecraft:generic.movement_speed", "minecraft:movement", 0f, 1024f, 0.1f), + FLYING_SPEED("minecraft:generic.flying_speed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f), + ATTACK_DAMAGE("minecraft:generic.attack_damage", "minecraft:attack_damage", 0f, 2048f, 1f), + HORSE_JUMP_STRENGTH("minecraft:horse.jump_strength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f), // Java Attributes - ARMOR("generic.armor", null, 0f, 30f, 0f), - ARMOR_TOUGHNESS("generic.armorToughness", null, 0F, 20f, 0f), - ATTACK_KNOCKBACK("generic.attackKnockback", null, 1.5f, Float.MAX_VALUE, 0f), - ATTACK_SPEED("generic.attackSpeed", null, 0f, 1024f, 4f), - LUCK("generic.luck", null, -1024f, 1024f, 0f), - MAX_HEALTH("generic.maxHealth", null, 0f, 1024f, 20f), + ARMOR("minecraft:generic.armor", null, 0f, 30f, 0f), + ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", null, 0F, 20f, 0f), + ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", null, 1.5f, Float.MAX_VALUE, 0f), + ATTACK_SPEED("minecraft:generic.attack_speed", null, 0f, 1024f, 4f), + LUCK("minecraft:generic.luck", null, -1024f, 1024f, 0f), + MAX_HEALTH("minecraft:generic.max_health", null, 0f, 1024f, 20f), // Bedrock Attributes ABSORPTION(null, "minecraft:absorption", 0f, Float.MAX_VALUE, 0f), diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 3acc17c37..77d7f5c9e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -68,7 +68,7 @@ public enum EntityType { CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), SKELETON(AbstractSkeletonEntity.class, 34, 1.8f, 0.6f, 0.6f, 1.62f), SPIDER(SpiderEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f), - ZOMBIE_PIGMAN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f), + ZOMBIFIED_PIGLIN(MonsterEntity.class, 36, 1.8f, 0.6f, 0.6f, 1.62f), SLIME(SlimeEntity.class, 37, 0.51f), ENDERMAN(EndermanEntity.class, 38, 2.9f, 0.6f), SILVERFISH(MonsterEntity.class, 39, 0.3f, 0.4f), @@ -150,7 +150,6 @@ public enum EntityType { COD(AbstractFishEntity.class, 112, 0.25f, 0.5f), PANDA(PandaEntity.class, 113, 1.25f, 1.125f, 1.825f), FOX(FoxEntity.class, 121, 0.5f, 1.25f), - BEE(BeeEntity.class, 122, 0.6f, 0.6f), /** * Item frames are handled differently since they are a block in Bedrock. diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 24ef2faaa..a1caf2783 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -68,10 +68,7 @@ import org.geysermc.connector.network.translators.EntityIdentifierRegistry; import org.geysermc.connector.network.translators.PacketTranslatorRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.world.block.BlockTranslator; -import org.geysermc.connector.utils.ChunkUtils; -import org.geysermc.connector.utils.LocaleUtils; -import org.geysermc.connector.utils.MathUtils; -import org.geysermc.connector.utils.SkinUtils; +import org.geysermc.connector.utils.*; import org.geysermc.floodgate.util.BedrockData; import org.geysermc.floodgate.util.EncryptionUtil; @@ -503,7 +500,7 @@ public class GeyserSession implements CommandSender { startGamePacket.setRotation(Vector2f.from(1, 1)); startGamePacket.setSeed(-1); - startGamePacket.setDimensionId(playerEntity.getDimension()); + startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(playerEntity.getDimension())); startGamePacket.setGeneratorId(1); startGamePacket.setLevelGamemode(0); startGamePacket.setDifficulty(1); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAdventureSettingsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAdventureSettingsTranslator.java index 75a1547f5..6ee70cb32 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAdventureSettingsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAdventureSettingsTranslator.java @@ -44,7 +44,7 @@ public class BedrockAdventureSettingsTranslator extends PacketTranslator break; } ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), - InteractAction.INTERACT, Hand.MAIN_HAND); + InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking()); session.sendDownstreamPacket(interactPacket); break; case DAMAGE: ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(), - InteractAction.ATTACK, Hand.MAIN_HAND); + InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); session.sendDownstreamPacket(attackPacket); break; case LEAVE_VEHICLE: diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index bdf900d88..cdb141084 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -82,9 +82,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator> iterator = items.fields(); while (iterator.hasNext()) { - Map.Entry 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").booleanValue())); + try { + Map.Entry 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 ToolItemEntry( + ITEM_ENTRIES.put(itemIndex, new ItemEntry( 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())); + entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue())); + } + if (entry.getKey().equals("minecraft:barrier")) { + BARRIER_INDEX = itemIndex; } - } 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").booleanValue())); - } - if (entry.getKey().equals("minecraft:barrier")) { - BARRIER_INDEX = itemIndex; - } - itemIndex++; + itemIndex++; + } catch (Exception e) { + System.out.println("Exception in item registry! " + e.toString()); + e.printStackTrace(); + } } /* Load creative items */ diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 8d8c0affb..9b44cdd37 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -80,7 +80,7 @@ public class JavaJoinGameTranslator extends PacketTranslator stopRainPacket.setPosition(Vector3f.ZERO); session.sendUpstreamPacket(stopRainPacket); - if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) { + if (!entity.getDimension().equals(packet.getDimension())) { DimensionUtils.switchDimension(session, packet.getDimension()); } else { if (session.isManyDimPackets()) { //reloading world - int fakeDim = entity.getDimension() == 0 ? -1 : 0; + String fakeDim = entity.getDimension().equals("minecraft:overworld") ? "minecraft:nether" : "minecraft:overworld"; DimensionUtils.switchDimension(session, fakeDim); DimensionUtils.switchDimension(session, packet.getDimension()); } else { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java index 5a3ebabaf..2aee7bc02 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -35,6 +35,7 @@ import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.BedrockMapIcon; +import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.MapColor; @Translator(packet = ServerMapDataPacket.class) @@ -45,7 +46,7 @@ public class JavaMapDataTranslator extends PacketTranslator boolean shouldStore = false; mapItemDataPacket.setUniqueMapId(packet.getMapId()); - mapItemDataPacket.setDimensionId(session.getPlayerEntity().getDimension()); + mapItemDataPacket.setDimensionId(DimensionUtils.javaToBedrock(session.getPlayerEntity().getDimension())); mapItemDataPacket.setLocked(packet.isLocked()); mapItemDataPacket.setScale(packet.getScale()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnParticleTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnParticleTranslator.java index 63512047f..d4c269b08 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnParticleTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaSpawnParticleTranslator.java @@ -40,6 +40,7 @@ import org.geysermc.connector.network.translators.world.block.BlockTranslator; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnParticlePacket; import com.nukkitx.math.vector.Vector3f; import org.geysermc.connector.network.translators.effect.EffectRegistry; +import org.geysermc.connector.utils.DimensionUtils; @Translator(packet = ServerSpawnParticlePacket.class) public class JavaSpawnParticleTranslator extends PacketTranslator { @@ -93,7 +94,7 @@ public class JavaSpawnParticleTranslator extends PacketTranslator> blocksIterator = blocks.fields(); while (blocksIterator.hasNext()) { - javaRuntimeId++; - Map.Entry entry = blocksIterator.next(); - String javaId = entry.getKey(); - CompoundTag blockTag = buildBedrockState(entry.getValue()); + try { + javaRuntimeId++; + Map.Entry 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()); - } - - JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND.put(javaRuntimeId, entry.getValue().get("can_break_with_hand").booleanValue()); - - 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; + // 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()); } - } - BlockStateValues.storeBlockStateValues(entry, javaRuntimeId); + 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); + } - // 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())); - } + JsonNode toolTypeNode = entry.getValue().get("tool_type"); + if (toolTypeNode != null) { + JAVA_RUNTIME_ID_TO_TOOL_TYPE.put(javaRuntimeId, toolTypeNode.textValue()); + } - 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 (javaId.contains("wool")) { + JAVA_RUNTIME_WOOL_IDS.add(javaRuntimeId); + } - if (waterlogged) { - BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, javaRuntimeId); - WATERLOGGED.add(javaRuntimeId); - } else { - BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId); - } + if (javaId.contains("cobweb")) { + cobwebRuntimeId = 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!"); + 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 { - JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, duplicateRuntimeId); + BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaRuntimeId); } - continue; - } - JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, bedrockRuntimeId); - if (javaId.startsWith("minecraft:furnace[facing=north")) { - if (javaId.contains("lit=true")) { - furnaceLitRuntimeId = javaRuntimeId; + CompoundTag runtimeTag = blockStateMap.remove(blockTag); + if (runtimeTag != null) { + addedStatesMap.put(blockTag, bedrockRuntimeId); + paletteList.add(runtimeTag); } else { - furnaceRuntimeId = javaRuntimeId; + 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:spawner")) { - spawnerRuntimeId = javaRuntimeId; - } + if (javaId.startsWith("minecraft:furnace[facing=north")) { + if (javaId.contains("lit=true")) { + furnaceLitRuntimeId = javaRuntimeId; + } else { + furnaceRuntimeId = javaRuntimeId; + } + } - bedrockRuntimeId++; + 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(); + } } if (cobwebRuntimeId == -1) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java index 6c8d9f944..b78a28ffe 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java @@ -36,10 +36,10 @@ public class DimensionUtils { // Changes if the above-bedrock Nether building workaround is applied private static int BEDROCK_NETHER_ID = 1; - public static void switchDimension(GeyserSession session, int javaDimension) { + public static void switchDimension(GeyserSession session, String javaDimension) { int bedrockDimension = javaToBedrock(javaDimension); Entity player = session.getPlayerEntity(); - if (bedrockDimension == player.getDimension()) + if (bedrockToJava(bedrockDimension) == player.getDimension()) return; session.getEntityCache().removeAllEntities(); @@ -55,7 +55,7 @@ public class DimensionUtils { changeDimensionPacket.setRespawn(true); changeDimensionPacket.setPosition(pos.toFloat()); session.sendUpstreamPacket(changeDimensionPacket); - player.setDimension(bedrockDimension); + player.setDimension(bedrockToJava(bedrockDimension)); player.setPosition(pos.toFloat()); session.setSpawned(false); session.setLastChunkPosition(null); @@ -83,14 +83,25 @@ public class DimensionUtils { * @param javaDimension Dimension ID to convert * @return Converted Bedrock edition dimension ID */ - public static int javaToBedrock(int javaDimension) { + public static int javaToBedrock(String javaDimension) { switch (javaDimension) { - case -1: + case "minecraft:nether": return BEDROCK_NETHER_ID; - case 1: + case "minecraft:the_end": return 2; default: - return javaDimension; + return 0; + } + } + + public static String bedrockToJava(int bedrockDimension) { + switch (bedrockDimension) { + case 1: + return "minecraft:nether"; + case 2: + return "minecraft:the_end"; + default: + return "minecraft:overworld"; } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 221a99176..6ab712431 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -210,13 +210,13 @@ public class MessageUtils { * @return Colour string to be used */ private static String getColorOrParent(MessageStyle style) { - ChatColor chatColor = style.getColor(); + String color = style.getColor(); - /*if (chatColor == ChatColor.NONE && style.getParent() != null) { + /*if (color == ChatColor.NONE && style.getParent() != null) { return getColorOrParent(style.getParent()); }*/ - return getColor(chatColor); + return getColor(color); } /** @@ -225,58 +225,58 @@ public class MessageUtils { * @param color ChatColor to convert * @return The converted color string */ - private static String getColor(ChatColor color) { + private static String getColor(String color) { String base = "\u00a7"; switch (color) { - case BLACK: + case ChatColor.BLACK: base += "0"; break; - case DARK_BLUE: + case ChatColor.DARK_BLUE: base += "1"; break; - case DARK_GREEN: + case ChatColor.DARK_GREEN: base += "2"; break; - case DARK_AQUA: + case ChatColor.DARK_AQUA: base += "3"; break; - case DARK_RED: + case ChatColor.DARK_RED: base += "4"; break; - case DARK_PURPLE: + case ChatColor.DARK_PURPLE: base += "5"; break; - case GOLD: + case ChatColor.GOLD: base += "6"; break; - case GRAY: + case ChatColor.GRAY: base += "7"; break; - case DARK_GRAY: + case ChatColor.DARK_GRAY: base += "8"; break; - case BLUE: + case ChatColor.BLUE: base += "9"; break; - case GREEN: + case ChatColor.GREEN: base += "a"; break; - case AQUA: + case ChatColor.AQUA: base += "b"; break; - case RED: + case ChatColor.RED: base += "c"; break; - case LIGHT_PURPLE: + case ChatColor.LIGHT_PURPLE: base += "d"; break; - case YELLOW: + case ChatColor.YELLOW: base += "e"; break; - case WHITE: + case ChatColor.WHITE: base += "f"; break; - case RESET: + case ChatColor.RESET: //case NONE: base += "r"; break; @@ -369,16 +369,16 @@ public class MessageUtils { } public static String toChatColor(TeamColor teamColor) { - for (ChatColor color : ChatColor.values()) { - if (color.name().equals(teamColor.name())) { - return getColor(color); - } - } - for (ChatFormat format : ChatFormat.values()) { - if (format.name().equals(teamColor.name())) { - return getFormat(Collections.singletonList(format)); - } - } +// for (ChatColor color : ChatColor.) { +// if (color.name().equals(teamColor.name())) { +// return getColor(color); +// } +// } +// for (ChatFormat format : ChatFormat.values()) { +// if (format.name().equals(teamColor.name())) { +// return getFormat(Collections.singletonList(format)); +// } +// } Not dealing with this return ""; }