From 39bc9baf160011c6c83c59dd7609ee103486a3e5 Mon Sep 17 00:00:00 2001 From: Ryan Hecht Date: Wed, 24 Jul 2019 22:03:59 -0700 Subject: [PATCH] Added JavaEntityDestoryTranslator and JavaSpawnExpOrbTranslator --- .../network/translators/TranslatorsInit.java | 18 ++++---- .../entity/JavaEntityDestroyTranslator.java | 45 +++++++++++++++++++ .../spawn/JavaSpawnExpOrbTranslator.java | 19 ++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java 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 d1b629d21..2e79a5ed9 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 @@ -28,10 +28,8 @@ package org.geysermc.connector.network.translators; 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.ServerEntityPositionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; -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.*; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; import com.nukkitx.nbt.CompoundTagBuilder; @@ -45,14 +43,12 @@ import org.geysermc.connector.network.translators.bedrock.BedrockAnimateTranslat import org.geysermc.connector.network.translators.bedrock.BedrockCommandRequestTranslator; import org.geysermc.connector.network.translators.bedrock.BedrockTextTranslator; import org.geysermc.connector.network.translators.java.JavaChatTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityPositionRotationTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityPositionTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityTeleportTranslator; -import org.geysermc.connector.network.translators.java.JavaEntityVelocityTranslator; +import org.geysermc.connector.network.translators.java.entity.*; import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator; -import org.geysermc.connector.network.translators.java.JavaNotifyClientTranslator; +import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator; +import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator; import org.geysermc.connector.network.translators.java.JavaTitleTranslator; -import org.geysermc.connector.network.translators.java.JavaUpdateTimeTranslator; +import org.geysermc.connector.network.translators.java.world.JavaUpdateTimeTranslator; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -86,6 +82,8 @@ public class TranslatorsInit { Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator()); Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator()); Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator()); + Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator()); + Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator()); Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator()); 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 new file mode 100644 index 000000000..a9885d330 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityDestroyTranslator.java @@ -0,0 +1,45 @@ +/* + * 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.ServerEntityDestroyPacket; +import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaEntityDestroyTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityDestroyPacket packet, GeyserSession session) { + for (int entityId : packet.getEntityIds()) { + RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket(); + removeEntityPacket.setUniqueEntityId(entityId); + + session.getUpstream().sendPacket(removeEntityPacket); + } + } +} + 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 new file mode 100644 index 000000000..c7f754dce --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnExpOrbTranslator.java @@ -0,0 +1,19 @@ +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.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +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()); + + session.getUpstream().sendPacket(spawnExperienceOrbPacket); + } +}