diff --git a/README.md b/README.md index 17dabc0ac..daab3c055 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,15 @@ Links: - [x] Join detection from remote - [x] Online mode/auth support - [x] Chat/command support +- [ ] Scoreboard + - [x] Objective-based scoreboards + - [ ] Team-based scoreboards - [ ] Inventory support -- [ ] Movement support -- [ ] Entity support + - [x] Inventory viewing + - [x] NBT data (experimental) + - [ ] Inventory movement (transactions) +- [ ] Player movement support +- [x] Entity support (experimental) - [ ] Chunks - [ ] Block break/place support diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java new file mode 100644 index 000000000..65ebe98f2 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.entity; + +import com.flowpowered.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.Attribute; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; +import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; +import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import lombok.Getter; +import lombok.Setter; +import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Getter +@Setter +public class Entity { + + protected long entityId; + protected long geyserId; + + protected int dimension; + + protected Vector3f position; + protected Vector3f motion; + + // 1 - pitch, 2 - yaw, 3 - roll (head yaw) + protected Vector3f rotation; + + protected int scale = 1; + protected boolean movePending; + + protected EntityType entityType; + + protected boolean valid; + + protected Set passengers = new HashSet(); + protected Map attributes = new HashMap(); + + public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + this.entityId = entityId; + this.geyserId = geyserId; + this.entityType = entityType; + this.position = position; + this.motion = motion; + this.rotation = rotation; + + this.valid = false; + this.movePending = false; + } + + public void spawnEntity(GeyserSession session) { + AddEntityPacket addEntityPacket = new AddEntityPacket(); + addEntityPacket.setIdentifier("minecraft:" + entityType.name().toLowerCase()); + addEntityPacket.setRuntimeEntityId(geyserId); + addEntityPacket.setUniqueEntityId(geyserId); + addEntityPacket.setPosition(position); + addEntityPacket.setMotion(motion); + addEntityPacket.setRotation(rotation); + addEntityPacket.setEntityType(entityType.getType()); + addEntityPacket.getMetadata().putAll(getMetadata()); + + valid = true; + session.getUpstream().sendPacket(addEntityPacket); + + GeyserLogger.DEFAULT.debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + } + + public void despawnEntity(GeyserSession session) { + if (!valid) + return; + + RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket(); + removeEntityPacket.setUniqueEntityId(geyserId); + session.getUpstream().sendPacket(removeEntityPacket); + } + + public void moveRelative(double relX, double relY, double relZ, float pitch, float yaw) { + moveRelative(relX, relY, relZ, new Vector3f(pitch, yaw, 0)); + } + + public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) { + if (relX == 0 && relY != 0 && relZ != 0 && position.getX() == 0 && position.getY() == 0) + return; + + this.rotation = rotation; + this.position = new Vector3f(position.getX() + relX, position.getX() + relY, position.getX() + relZ); + this.movePending = true; + } + + public void moveAbsolute(Vector3f position, float pitch, float yaw) { + moveAbsolute(position, new Vector3f(pitch, yaw, 0)); + } + + public void moveAbsolute(Vector3f position, Vector3f rotation) { + if (position.getX() == 0 && position.getX() != 0 && position.getX() != 0 && rotation.getX() == 0 && rotation.getY() == 0) + return; + + this.position = position; + this.rotation = rotation; + this.movePending = true; + } + + + public EntityDataDictionary getMetadata() { + EntityDataDictionary dictionary = new EntityDataDictionary(); + dictionary.put(EntityData.NAMETAG, ""); + dictionary.put(EntityData.ENTITY_AGE, 0); + dictionary.put(EntityData.SCALE, 1f); + dictionary.put(EntityData.MAX_AIR, (short) 400); + dictionary.put(EntityData.AIR, (short) 0); + dictionary.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight()); + dictionary.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth()); + return dictionary; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/ExpOrbEntity.java b/connector/src/main/java/org/geysermc/connector/entity/ExpOrbEntity.java new file mode 100644 index 000000000..036829e8a --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/ExpOrbEntity.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.entity; + +import com.flowpowered.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class ExpOrbEntity extends Entity { + + private int amount; + + public ExpOrbEntity(int amount, long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + + this.amount = amount; + } + + @Override + public void spawnEntity(GeyserSession session) { + SpawnExperienceOrbPacket spawnExpOrbPacket = new SpawnExperienceOrbPacket(); + spawnExpOrbPacket.setPosition(position); + spawnExpOrbPacket.setAmount(amount); + + valid = true; + session.getUpstream().sendPacket(spawnExpOrbPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java new file mode 100644 index 000000000..eee33c177 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.entity; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; +import com.nukkitx.protocol.bedrock.data.ItemData; +import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; +import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; +import lombok.Getter; +import lombok.Setter; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +import java.util.Random; +import java.util.UUID; + +@Getter +@Setter +public class PlayerEntity extends Entity { + + private UUID uuid; + + private ItemData hand; + + private ItemData helmet; + private ItemData chestplate; + private ItemData leggings; + private ItemData boots; + + public PlayerEntity(UUID uuid, long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + + this.uuid = uuid; + } + + // TODO: Break this into an EquippableEntity class + public void updateEquipment(GeyserSession session) { + if (hand != null && helmet != null && chestplate != null && leggings != null ) + return; + + MobArmorEquipmentPacket armorEquipmentPacket = new MobArmorEquipmentPacket(); + armorEquipmentPacket.setRuntimeEntityId(geyserId); + armorEquipmentPacket.setHelmet(helmet); + armorEquipmentPacket.setChestplate(chestplate); + armorEquipmentPacket.setLeggings(leggings); + armorEquipmentPacket.setBoots(boots); + + session.getUpstream().sendPacket(armorEquipmentPacket); + } + + @Override + public void spawnEntity(GeyserSession session) { + AddPlayerPacket addPlayerPacket = new AddPlayerPacket(); + addPlayerPacket.setUniqueEntityId(geyserId); + addPlayerPacket.setUniqueEntityId(geyserId); + addPlayerPacket.setUuid(uuid); + addPlayerPacket.setUsername("Player" + new Random().nextInt(1000) + 1); // TODO: Cache player list values and set it here + addPlayerPacket.setPlatformChatId(""); + addPlayerPacket.setPosition(position); + addPlayerPacket.setMotion(motion); + addPlayerPacket.setRotation(rotation); + addPlayerPacket.setHand(hand); + addPlayerPacket.getMetadata().putAll(getMetadata()); + addPlayerPacket.setPlayerFlags(0); + addPlayerPacket.setCommandPermission(0); + addPlayerPacket.setWorldFlags(0); + addPlayerPacket.setPlayerPermission(0); + addPlayerPacket.setCustomFlags(0); + addPlayerPacket.setDeviceId("WIN10"); // TODO: Find this value + addPlayerPacket.getMetadata().putAll(getMetadata()); + + valid = true; + session.getUpstream().sendPacket(addPlayerPacket); + } +} 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 new file mode 100644 index 000000000..5525fb0e9 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.entity.type; + +import lombok.Getter; + +@Getter +public enum EntityType { + + CHICKEN(10, 0.7f, 0.4f), + COW(11, 1.4f, 0.9f), + PIG(12, 0.9f), + SHEEP(13, 1.3f, 0.9f), + WOLF(14, 0.85f, 0.6f), + VILLAGER(15, 1.8f, 0.6f, 0.6f, 1.62f), + MOOSHROOM(16, 1.4f, 0.9f), + SQUID(17, 0.8f), + RABBIT(18, 0.5f, 0.4f), + BAT(19, 0.9f, 0.5f), + IRON_GOLEM(20, 2.7f, 1.4f), + SNOW_GOLEM(21, 1.9f, 0.7f), + OCELOT(22, 0.35f, 0.3f), + HORSE(23, 1.6f, 1.3965f), + DONKEY(24, 1.6f, 1.3965f), + MULE(25, 1.6f, 1.3965f), + SKELETON_HORSE(26, 1.6f, 1.3965f), + ZOMBIE_HORSE(27, 1.6f, 1.3965f), + POLAR_BEAR(28, 1.4f, 1.3f), + LLAMA(29, 1.87f, 0.9f), + PARROT(30, 0.9f, 0.5f), + DOLPHIN(31, 0f), //TODO + ZOMBIE(32, 1.8f, 0.6f, 0.6f, 1.62f), + CREEPER(33, 1.7f, 0.6f, 0.6f, 1.62f), + SKELETON(34, 1.8f, 0.6f, 0.6f, 1.62f), + SPIDER(35, 0.9f, 1.4f, 1.4f, 1f), + ZOMBIE_PIGMAN(36, 1.8f, 0.6f, 0.6f, 1.62f), + SLIME(37, 0.51f), + ENDERMAN(38, 2.9f, 0.6f), + SILVERFISH(39, 0.3f, 0.4f), + CAVE_SPIDER(40, 0.5f, 0.7f), + GHAST(41, 4.0f), + MAGMA_CUBE(42, 0.51f), + BLAZE(43, 1.8f, 0.6f), + ZOMBIE_VILLAGER(44, 1.8f, 0.6f, 0.6f, 1.62f), + WITCH(45, 1.8f, 0.6f, 0.6f, 1.62f), + STRAY(46, 1.8f, 0.6f, 0.6f, 1.62f), + HUSK(47, 1.8f, 0.6f, 0.6f, 1.62f), + WITHER_SKELETON(48, 2.4f, 0.7f), + GUARDIAN(49, 0.85f), + ELDER_GUARDIAN(50, 1.9975f), + NPC(51, 1.8f, 0.6f, 0.6f, 1.62f), + WITHER(52, 3.5f, 0.9f), + ENDER_DRAGON(53, 4f, 13f), + SHULKER(54, 1f, 1f), + ENDERMITE(55, 0.3f, 0.4f), + AGENT(56, 0f), + VINDICATOR(57, 1.8f, 0.6f, 0.6f, 1.62f), + PILLAGER(114, 1.8f, 0.6f, 0.6f, 1.62f), + WANDERING_VILLAGER(118, 1.8f, 0.6f, 0.6f, 1.62f), + RAVAGER(59, 1.9f, 1.2f), + + ARMOR_STAND(61, 0f), + TRIPOD_CAMERA(62, 0f), + PLAYER(63, 1.8f, 0.6f, 0.6f, 1.62f), + ITEM(64, 0.25f, 0.25f), + PRIMED_TNT(65, 0.98f, 0.98f), + FALLING_BLOCK(66, 0.98f, 0.98f), + MOVING_BLOCK(67, 0f), + EXPERIENCE_BOTTLE(68, 0.25f, 0.25f), + EXPERIENCE_ORB(69, 0f), + EYE_OF_ENDER(70, 0f), + ENDER_CRYSTAL(71, 0f), + FIREWORK_ROCKET(72, 0f), + TRIDENT(73, 0f), + + SHULKER_BULLET(76, 0f), + FISHING_HOOK(77, 0f), + CHALKBOARD(78, 0f), + DRAGON_FIREBALL(79, 0f), + ARROW(80, 0.25f, 0.25f), + SNOWBALL(81, 0f), + EGG(82, 0f), + PAINTING(83, 0f), + MINECART(84, 0f), + LARGE_FIREBALL(85, 0f), + SPLASH_POTION(86, 0f), + ENDER_PEARL(87, 0f), + LEASH_KNOT(88, 0f), + WITHER_SKULL(89, 0f), + BOAT(90, 0.7f, 1.6f, 1.6f, 0.35f), + WITHER_SKULL_DANGEROUS(91, 0f), + LIGHTNING_BOLT(93, 0f), + SMALL_FIREBALL(94, 0f), + AREA_EFFECT_CLOUD(95, 0f), + HOPPER_MINECART(96, 0f), + TNT_MINECART(97, 0f), + CHEST_MINECART(98, 0f), + + COMMAND_BLOCK_MINECART(100, 0f), + LINGERING_POTION(101, 0f), + LLAMA_SPIT(102, 0f), + EVOKER_FANGS(103, 0f), + EVOKER(104, 0f), + VEX(105, 0f), + ICE_BOMB(106, 0f), + BALLOON(107, 0f), //TODO + PUFFERFISH(108, 0.7f, 0.7f), + SALMON(109, 0.5f, 0.7f), + TROPICAL_FISH(111, 0.6f, 0.6f), + COD(112, 0.25f, 0.5f); + + private final int type; + private final float height; + private final float width; + private final float length; + private final float offset; + + EntityType(int type, float height) { + this(type, height, 0f); + } + + EntityType(int type, float height, float width) { + this(type, height, width, width); + } + + EntityType(int type, float height, float width, float length) { + this(type, height, width, length, 0f); + } + + EntityType(int type, float height, float width, float length, float offset) { + this.type = type; + this.height = height; + this.width = width; + this.length = length; + this.offset = offset + 0.00001f; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java index ed988dcc1..801f670cd 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java @@ -33,32 +33,40 @@ import lombok.Setter; public class Inventory { @Getter - private int id; + protected int id; @Getter @Setter - private boolean open; + protected boolean open; @Getter - private WindowType windowType; + protected WindowType windowType; @Getter - private int size; + protected int size; @Getter @Setter - private String title; + protected String title; @Getter @Setter - private ItemStack[] items; + protected ItemStack[] items; public Inventory(int id, WindowType windowType, int size) { + this("Inventory", id, windowType, size); + } + + public Inventory(String title, int id, WindowType windowType, int size) { + this.title = title; this.id = id; this.windowType = windowType; this.size = size; - this.title = "Inventory"; this.items = new ItemStack[size]; } + + public ItemStack getItem(int slot) { + return items[slot]; + } } diff --git a/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java b/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java new file mode 100644 index 000000000..424570b9e --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/inventory/PlayerInventory.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.inventory; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import lombok.Getter; +import lombok.Setter; + +public class PlayerInventory extends Inventory { + + @Getter + @Setter + private int heldItemSlot; + + public PlayerInventory() { + super(0, null, 45); + + heldItemSlot = 0; + } + + public ItemStack getItemInHand() { + return items[heldItemSlot]; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index 018228d30..0ac0f997c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -92,6 +92,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { c.setSubMotd(pong.getSubMotd()); c.setPlayerCount(pong.getPlayerCount()); c.setMaximumPlayerCount(pong.getMaximumPlayerCount()); + c.setIpv4Port(config.getBedrock().getPort()); return c; diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 7a0f46162..8b4c188ce 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -139,4 +139,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { return translateAndDefault(packet); } + @Override + public boolean handle(MobEquipmentPacket packet) { + return translateAndDefault(packet); + } } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/DataCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/DataCache.java new file mode 100644 index 000000000..58d33a736 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/DataCache.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.session.cache; + +import lombok.Getter; + +import java.util.HashMap; +import java.util.Map; + +public class DataCache { + + @Getter + private Map cachedValues = new HashMap(); +} diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java new file mode 100644 index 000000000..e2bf53c33 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/EntityCache.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.session.cache; + +import lombok.Getter; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +/** + * Each session has its own EntityCache in the occasion that an entity packet is sent specifically + * for that player (e.g. seeing vanished players from /vanish) + */ +public class EntityCache { + + private GeyserSession session; + + @Getter + private Map entities = new HashMap(); + + private Map entityIdTranslations = new HashMap(); + + @Getter + private AtomicLong nextEntityId = new AtomicLong(2L); + + public EntityCache(GeyserSession session) { + this.session = session; + } + + public void spawnEntity(Entity entity) { + entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY()); + entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId()); + entities.put(entity.getGeyserId(), entity); + entity.spawnEntity(session); + } + + public void removeEntity(Entity entity) { + if (entity == null) + return; + + entityIdTranslations.remove(entity.getGeyserId()); + entity.despawnEntity(session); + } + + public Entity getEntityByGeyserId(long geyserId) { + return entities.get(geyserId); + } + + public Entity getEntityByJavaId(long javaId) { + return entities.get(entityIdTranslations.get(javaId)); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/InventoryCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/InventoryCache.java index b6c8b501a..4eea1de2f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/InventoryCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/InventoryCache.java @@ -52,9 +52,6 @@ public class InventoryCache { public InventoryCache(GeyserSession session) { this.session = session; - - // This is the player's inventory - inventories.put(0, new Inventory(0, null, 45)); } public Inventory getPlayerInventory() { diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java index 01efa9693..147a5355d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java @@ -29,7 +29,7 @@ import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; import lombok.Getter; import lombok.Setter; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.Scoreboard; public class ScoreboardCache { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 4357f9f65..0edcd59d4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -30,11 +30,24 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; @@ -46,10 +59,12 @@ import com.nukkitx.nbt.stream.NBTOutputStream; import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.packet.AnimatePacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; +import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; import com.nukkitx.protocol.bedrock.packet.TextPacket; import lombok.Getter; import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslator; import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator; +import org.geysermc.connector.network.translators.bedrock.BedrockMobEquipmentTranslator; import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator; import org.geysermc.connector.network.translators.inventory.GenericInventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator; @@ -57,11 +72,24 @@ import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.java.JavaChatTranslator; import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator; import org.geysermc.connector.network.translators.java.entity.JavaEntityDestroyTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityHeadLookTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityMetadataTranslator; import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionRotationTranslator; import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityPropertiesTranslator; +import org.geysermc.connector.network.translators.java.entity.JavaEntityRotationTranslator; import org.geysermc.connector.network.translators.java.entity.JavaEntityTeleportTranslator; import org.geysermc.connector.network.translators.java.entity.JavaEntityVelocityTranslator; +import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerPositionRotationTranslator; import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnGlobalEntityTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnMobTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnObjectTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPaintingTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPlayerTranslator; +import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator; +import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator; +import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator; import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator; import org.geysermc.connector.network.translators.java.window.JavaOpenWindowTranslator; import org.geysermc.connector.network.translators.java.window.JavaSetSlotTranslator; @@ -104,20 +132,38 @@ public class TranslatorsInit { Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator()); Registry.registerJava(ServerTitlePacket.class, new JavaTitleTranslator()); Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator()); + Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator()); Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator()); Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator()); Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator()); + Registry.registerJava(ServerEntityPropertiesPacket.class, new JavaEntityPropertiesTranslator()); + Registry.registerJava(ServerEntityRotationPacket.class, new JavaEntityRotationTranslator()); + Registry.registerJava(ServerEntityHeadLookPacket.class, new JavaEntityHeadLookTranslator()); + Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator()); + + Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); + Registry.registerJava(ServerSpawnGlobalEntityPacket.class, new JavaSpawnGlobalEntityTranslator()); + Registry.registerJava(ServerSpawnMobPacket.class, new JavaSpawnMobTranslator()); + Registry.registerJava(ServerSpawnObjectPacket.class, new JavaSpawnObjectTranslator()); + Registry.registerJava(ServerSpawnPaintingPacket.class, new JavaSpawnPaintingTranslator()); + Registry.registerJava(ServerSpawnPlayerPacket.class, new JavaSpawnPlayerTranslator()); + + Registry.registerJava(ServerPlayerPositionRotationPacket.class, new JavaPlayerPositionRotationTranslator()); + Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator()); Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator()); - Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator()); Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator()); Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator()); + Registry.registerJava(ServerScoreboardObjectivePacket.class, new JavaScoreboardObjectiveTranslator()); + Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaDisplayScoreboardTranslator()); + Registry.registerJava(ServerUpdateScorePacket.class, new JavaUpdateScoreTranslator()); Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator()); Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator()); + Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator()); itemTranslator = new ItemTranslator(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index c453c31a3..cc2ab4d07 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -23,7 +23,6 @@ * @link https://github.com/GeyserMC/Geyser */ - package org.geysermc.connector.network.translators.bedrock; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java new file mode 100644 index 000000000..7ae5a4ee0 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMobEquipmentTranslator.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.bedrock; + +import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket; +import com.nukkitx.protocol.bedrock.data.ContainerId; +import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class BedrockMobEquipmentTranslator extends PacketTranslator { + + @Override + public void translate(MobEquipmentPacket packet, GeyserSession session) { + if (packet.getHotbarSlot() > 8) + return; + + if (packet.getContainerId() != ContainerId.INVENTORY) + return; + + session.getInventory().setHeldItemSlot(packet.getHotbarSlot()); + + ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot()); + session.getDownstream().getSession().send(changeHeldItemPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index a1fd95179..4579c9faa 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.translators.item; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.github.steveice10.mc.protocol.data.message.Message; import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag; import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; @@ -40,6 +41,7 @@ import com.github.steveice10.opennbt.tag.builtin.ShortTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.nukkitx.protocol.bedrock.data.ItemData; +import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.Remapper; import org.geysermc.connector.utils.Toolbox; @@ -53,12 +55,10 @@ public class ItemTranslator { public ItemStack translateToJava(ItemData data) { JavaItem javaItem = getJavaItem(data); - // TODO: Fix NBT - // if (data.getTag() == null) { - // return new ItemStack(javaItem.getId(), data.getCount()); - // } - // return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag())); - return new ItemStack(javaItem.getId(), data.getCount()); + if (data.getTag() == null) { + return new ItemStack(javaItem.getId(), data.getCount()); + } + return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag())); } public ItemData translateToBedrock(ItemStack stack) { @@ -68,13 +68,10 @@ public class ItemTranslator { } BedrockItem bedrockItem = getBedrockItem(stack); - - // TODO: Fix NBT - //if (stack.getNBT() == null) { - // return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount()); - // } - // return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT())); - return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount()); + if (stack.getNBT() == null) { + return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount()); + } + return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT())); } public BedrockItem getBedrockItem(ItemStack stack) { @@ -284,24 +281,23 @@ public class ItemTranslator { if (tag instanceof StringTag) { StringTag stringTag = (StringTag) tag; - return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), stringTag.getValue()); + return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), MessageUtils.getBedrockMessage(Message.fromString(stringTag.getValue()))); } if (tag instanceof ListTag) { ListTag listTag = (ListTag) tag; + if (listTag.getName().equalsIgnoreCase("Lore")) { + List tags = new ArrayList<>(); + for (Object value : listTag.getValue()) { + if (!(value instanceof Tag)) + continue; - List tags = new ArrayList(); - for (Object value : listTag.getValue()) { - if (!(value instanceof Tag)) - continue; - - Tag tagValue = (Tag) value; - com.nukkitx.nbt.tag.Tag bedrockTag = translateToBedrockNBT(tagValue); - if (bedrockTag != null) - tags.add(bedrockTag); + com.nukkitx.nbt.tag.StringTag bedrockTag = (com.nukkitx.nbt.tag.StringTag) translateToBedrockNBT((Tag) value); + if (bedrockTag != null) + tags.add(bedrockTag); + } + return new com.nukkitx.nbt.tag.ListTag<>(listTag.getName(), com.nukkitx.nbt.tag.StringTag.class, tags); } - // TODO: Fix unchecked call here - return new com.nukkitx.nbt.tag.ListTag(listTag.getName(), listTag.getElementType(), tags); } if (tag instanceof CompoundTag) { 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 a43fd4a43..29c4b4b22 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 @@ -26,9 +26,11 @@ package org.geysermc.connector.network.translators.java; import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -38,9 +40,14 @@ public class JavaJoinGameTranslator extends PacketTranslator> 4; int chunkZ = pos.getFloorZ() >> 4; @@ -52,10 +59,11 @@ public class JavaJoinGameTranslator extends PacketTranslator { titlePacket.setType(SetTitlePacket.Type.SET_ACTIONBAR_MESSAGE); titlePacket.setText(packet.getActionBar().getFullText()); break; + case TIMES: + titlePacket.setFadeInTime(packet.getFadeIn()); + titlePacket.setFadeOutTime(packet.getFadeOut()); + titlePacket.setStayTime(packet.getStay()); + break; } - titlePacket.setFadeInTime(packet.getFadeIn()); - titlePacket.setFadeOutTime(packet.getFadeOut()); - titlePacket.setStayTime(packet.getStay()); - session.getUpstream().sendPacket(titlePacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java index a9885d330..ed741f95a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java @@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.java.entity; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket; import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -35,10 +36,8 @@ public class JavaEntityDestroyTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityHeadLookPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + entity.setRotation(new Vector3f(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw())); + + MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket(); + moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId()); + moveEntityAbsolutePacket.setRotation(entity.getRotation()); + moveEntityAbsolutePacket.setPosition(entity.getPosition()); + moveEntityAbsolutePacket.setOnGround(true); + + session.getUpstream().sendPacket(moveEntityAbsolutePacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java new file mode 100644 index 000000000..c0451eb7e --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityMetadataTranslator.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; +import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaEntityMetadataTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityMetadataPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + if (entity.isValid()) { + // TODO: Make this actually useful lol + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); + entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); + entityDataPacket.getMetadata().putAll(entity.getMetadata()); + + session.getUpstream().sendPacket(entityDataPacket); + } else { + entity.spawnEntity(session); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java index 713a24323..e97c40dab 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityPositionRotationTranslator.java @@ -25,9 +25,9 @@ package org.geysermc.connector.network.translators.java.entity; -import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -35,13 +35,25 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityPropertiesPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java new file mode 100644 index 000000000..77ed8855e --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityRotationTranslator.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket; +import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaEntityRotationTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityRotationPacket packet, GeyserSession session) { + Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); + if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { + entity = session.getPlayerEntity(); + } + if (entity == null) + return; + + entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getPitch(), packet.getYaw()); + + Vector3f rotation = new Vector3f(entity.getRotation().getX() / (360d / 256d), entity.getRotation().getY() / (360d / 256d), + entity.getRotation().getZ() / (360d / 256d)); + if (entity.isMovePending()) { + MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket(); + moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId()); + moveEntityAbsolutePacket.setPosition(entity.getPosition()); + moveEntityAbsolutePacket.setRotation(rotation); + entity.setMovePending(false); + + session.getUpstream().sendPacket(moveEntityAbsolutePacket); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java index c5ec98fc0..eb7262d67 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityTeleportTranslator.java @@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java.entity; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.geysermc.connector.entity.Entity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -35,13 +36,25 @@ public class JavaEntityTeleportTranslator extends PacketTranslator { + + @Override + public void translate(ServerPlayerPositionRotationPacket packet, GeyserSession session) { + Entity entity = session.getPlayerEntity(); + if (entity == null) + return; + + if (!session.isLoggedIn()) + return; + + if (session.isSpawned()) + return; + + ServerJoinGamePacket javaJoinPacket = (ServerJoinGamePacket) session.getJavaPacketCache().getCachedValues().remove("java_join_packet"); + + PlayStatusPacket playStatus = new PlayStatusPacket(); + playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS); + session.getUpstream().sendPacketImmediately(playStatus); + + entity.moveAbsolute(new Vector3f(packet.getX(), packet.getY(), packet.getZ()), packet.getPitch(), packet.getYaw()); + + SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket(); + playerGameTypePacket.setGamemode(javaJoinPacket.getGameMode().ordinal()); + session.getUpstream().sendPacket(playerGameTypePacket); + + SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); + entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); + entityDataPacket.getMetadata().putAll(entity.getMetadata()); + + session.getUpstream().sendPacket(entityDataPacket); + session.getPlayerEntity().setEntityId(javaJoinPacket.getEntityId()); + + MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); + movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); + movePlayerPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ())); + movePlayerPacket.setRotation(new Vector3f(packet.getPitch(), packet.getYaw(), 0)); + movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); + movePlayerPacket.setOnGround(true); + entity.setMovePending(false); + + session.getUpstream().sendPacket(movePlayerPacket); + session.setSpawned(true); + + GeyserLogger.DEFAULT.info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ()); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java index c7f754dce..324909572 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java @@ -1,19 +1,51 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + package org.geysermc.connector.network.translators.java.entity.spawn; import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.ExpOrbEntity; +import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.EntityUtils; public class JavaSpawnExpOrbTranslator extends PacketTranslator { @Override public void translate(ServerSpawnExpOrbPacket packet, GeyserSession session) { - SpawnExperienceOrbPacket spawnExperienceOrbPacket = new SpawnExperienceOrbPacket(); - spawnExperienceOrbPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ())); - spawnExperienceOrbPacket.setAmount(packet.getExp()); + Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); + Entity entity = new ExpOrbEntity(packet.getExp(), packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + EntityType.EXPERIENCE_ORB, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0)); - session.getUpstream().sendPacket(spawnExperienceOrbPacket); + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java new file mode 100644 index 000000000..cb6b9f126 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnGlobalEntityTranslator.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaSpawnGlobalEntityTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnGlobalEntityPacket packet, GeyserSession session) { + Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); + + // Currently GlobalEntityType only has a lightning bolt + Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + EntityType.LIGHTNING_BOLT, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0)); + + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java new file mode 100644 index 000000000..93ff22a37 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnMobTranslator.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket; +import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.EntityUtils; + +public class JavaSpawnMobTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnMobPacket packet, GeyserSession session) { + Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); + Vector3f motion = new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()); + Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), packet.getHeadYaw()); + + EntityType type = EntityUtils.toBedrockEntity(packet.getType()); + if (type == null) { + GeyserLogger.DEFAULT.warning("Entity type " + packet.getType() + " was null."); + return; + } + + Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation); + + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java new file mode 100644 index 000000000..a484d4a39 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket; +import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.EntityUtils; + +public class JavaSpawnObjectTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnObjectPacket packet, GeyserSession session) { + if (packet.getType() == ObjectType.ITEM_FRAME) + return; + + Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); + Vector3f motion = new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()); + Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), 0); + + EntityType type = EntityUtils.toBedrockEntity(packet.getType()); + if (type == null) { + GeyserLogger.DEFAULT.warning("Entity type " + packet.getType() + " was null."); + return; + } + + Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation); + + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java new file mode 100644 index 000000000..d98e6c655 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPaintingTranslator.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaSpawnPaintingTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnPaintingPacket packet, GeyserSession session) { + Vector3f position = new Vector3f(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()); + + Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + EntityType.PAINTING, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0)); + + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java new file mode 100644 index 000000000..838dadce3 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnPlayerTranslator.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.entity.spawn; + +import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.PlayerEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaSpawnPlayerTranslator extends PacketTranslator { + + @Override + public void translate(ServerSpawnPlayerPacket packet, GeyserSession session) { + Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ()); + Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), 0); + Entity entity = new PlayerEntity(packet.getUUID(), packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + EntityType.PLAYER, position, new Vector3f(0, 0, 0), rotation); + + if (entity == null) + return; + + session.getEntityCache().spawnEntity(entity); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java new file mode 100644 index 000000000..429857aa3 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.scoreboard; + +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.session.cache.ScoreboardCache; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.scoreboard.Scoreboard; + +public class JavaDisplayScoreboardTranslator extends PacketTranslator { + + @Override + public void translate(ServerDisplayScoreboardPacket packet, GeyserSession session) { + try { + ScoreboardCache cache = session.getScoreboardCache(); + Scoreboard scoreboard = new Scoreboard(session); + cache.setScoreboard(scoreboard); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java deleted file mode 100644 index db4eef2f2..000000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.geysermc.connector.network.translators.java.scoreboard; - -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.session.cache.ScoreboardCache; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; - -public class JavaScoreboardDisplayTranslator extends PacketTranslator { - @Override - public void translate(ServerDisplayScoreboardPacket packet, GeyserSession session) { - try { - ScoreboardCache cache = session.getScoreboardCache(); - Scoreboard scoreboard = new Scoreboard(session); - } catch (Exception ex) { - ex.printStackTrace(); - } - } -} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java index 7076d1c66..fb60217cd 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java @@ -1,14 +1,40 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + package org.geysermc.connector.network.translators.java.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.ScoreboardCache; import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; +import org.geysermc.connector.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.ScoreboardObjective; import org.geysermc.connector.utils.MessageUtils; public class JavaScoreboardObjectiveTranslator extends PacketTranslator { + @Override public void translate(ServerScoreboardObjectivePacket packet, GeyserSession session) { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java deleted file mode 100644 index 85845a4ff..000000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.geysermc.connector.network.translators.java.scoreboard; - -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; -import com.nukkitx.protocol.bedrock.packet.SetScorePacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.session.cache.ScoreboardCache; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; -import org.geysermc.connector.utils.MessageUtils; - -public class JavaScoreboardTeamTranslator extends PacketTranslator { - @Override - public void translate(ServerTeamPacket packet, GeyserSession session) { - - } -} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java new file mode 100644 index 000000000..aa364fef7 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + +package org.geysermc.connector.network.translators.java.scoreboard; + +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaTeamTranslator extends PacketTranslator { + + @Override + public void translate(ServerTeamPacket packet, GeyserSession session) { + + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java index 3f67ed192..83b01ae02 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * 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 + */ + package org.geysermc.connector.network.translators.java.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; @@ -5,10 +30,11 @@ import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.ScoreboardCache; import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; +import org.geysermc.connector.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.ScoreboardObjective; public class JavaUpdateScoreTranslator extends PacketTranslator { + @Override public void translate(ServerUpdateScorePacket packet, GeyserSession session) { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java index 65c25a1d3..f94d726d5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaNotifyClientTranslator.java @@ -26,8 +26,10 @@ package org.geysermc.connector.network.translators.java.world; import com.flowpowered.math.vector.Vector3f; +import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; +import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -54,6 +56,11 @@ public class JavaNotifyClientTranslator extends PacketTranslator fakeMap = new HashMap(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java b/connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java similarity index 97% rename from connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java rename to connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java index a140ff677..f90c474e5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java @@ -23,12 +23,11 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.scoreboard; +package org.geysermc.connector.scoreboard; import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import lombok.Getter; import lombok.Setter; -import org.geysermc.connector.console.GeyserLogger; import java.util.HashMap; import java.util.Map; diff --git a/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java new file mode 100644 index 000000000..15c86d9b8 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/utils/EntityUtils.java @@ -0,0 +1,32 @@ +package org.geysermc.connector.utils; + +import com.github.steveice10.mc.protocol.data.game.entity.type.MobType; +import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; +import org.geysermc.connector.entity.type.EntityType; + +public class EntityUtils { + + public static MobType toJavaEntity(EntityType type) { + try { + return MobType.valueOf(type.name()); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static EntityType toBedrockEntity(MobType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static EntityType toBedrockEntity(ObjectType type) { + try { + return EntityType.valueOf(type.name()); + } catch (IllegalArgumentException ex) { + return null; + } + } +}