From f9b997c6e346c2c9b00e912d55ecca61e2fdd59c Mon Sep 17 00:00:00 2001 From: DustinRepo Date: Fri, 15 Apr 2022 19:42:43 -0400 Subject: [PATCH] Added 1.19 snaphot fixes and entity type parsing --- .../chatbot/command/impl/CommandCoords.java | 2 +- .../dustin/chatbot/entity/LivingEntity.java | 85 ++++++++++++++++++- .../player/ClientPlayer.java | 2 +- .../chatbot/entity/player/PlayerEntity.java | 2 +- .../chatbot/network/ClientConnection.java | 2 +- .../handler/PlayClientBoundPacketHandler.java | 11 ++- .../play/s2c/ClientBoundSpawnMobPacket.java | 5 +- .../packet/pipeline/PacketDecoderHandler.java | 2 +- .../chatbot/process/impl/KillAuraProcess.java | 2 +- 9 files changed, 101 insertions(+), 12 deletions(-) rename java/src/me/dustin/chatbot/{network => entity}/player/ClientPlayer.java (99%) diff --git a/java/src/me/dustin/chatbot/command/impl/CommandCoords.java b/java/src/me/dustin/chatbot/command/impl/CommandCoords.java index 8deb865..d29228c 100644 --- a/java/src/me/dustin/chatbot/command/impl/CommandCoords.java +++ b/java/src/me/dustin/chatbot/command/impl/CommandCoords.java @@ -2,7 +2,7 @@ import me.dustin.chatbot.command.Command; import me.dustin.chatbot.entity.player.PlayerInfo; -import me.dustin.chatbot.network.player.ClientPlayer; +import me.dustin.chatbot.entity.player.ClientPlayer; import java.util.Random; import java.util.UUID; diff --git a/java/src/me/dustin/chatbot/entity/LivingEntity.java b/java/src/me/dustin/chatbot/entity/LivingEntity.java index 7fa9e81..b0248d8 100644 --- a/java/src/me/dustin/chatbot/entity/LivingEntity.java +++ b/java/src/me/dustin/chatbot/entity/LivingEntity.java @@ -1,15 +1,26 @@ package me.dustin.chatbot.entity; import me.dustin.chatbot.ChatBot; +import me.dustin.chatbot.helper.GeneralHelper; +import me.dustin.chatbot.network.packet.ProtocolHandler; import me.dustin.chatbot.process.ChatBotProcess; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + public class LivingEntity { protected final int entityId; + protected final String type; protected double x, y, z; protected float yaw, pitch; - public LivingEntity(int entityId, double x, double y, double z, float yaw, float pitch) { + private static final ArrayList nonLivingEntities = new ArrayList<>(); + private static final Map entityIds = new HashMap<>(); + + public LivingEntity(int entityId, String type, double x, double y, double z, float yaw, float pitch) { this.entityId = entityId; + this.type = type; this.x = x; this.y = y; this.z = z; @@ -21,6 +32,10 @@ public int getEntityId() { return entityId; } + public String getTypeName() { + return type; + } + public double getX() { return x; } @@ -82,4 +97,72 @@ public String toString() { ", pitch=" + pitch + '}'; } + + public static String getTypeName(int id) { + if (!entityIds.containsKey(id)) + return "unknown"; + return entityIds.get(id); + } + + public static boolean isLiving(String name) { + return !nonLivingEntities.contains(name); + } + + static { + String v = ProtocolHandler.getCurrent().getName().replace(".", "_"); + if (v.contains("pre") || v.contains("w")) + v = "1_19"; + //fat fuckin mess to create the version id needed for the link, i.e. 1_12 from 1.12.2 + if (v.split("_").length > 2) + v = v.split("_")[0] + "_" + v.split("_")[1]; + String url = "https://raw.githubusercontent.com/DustinRepo/ChatBot/master/entityIds/" + v + "_entity_ids.txt"; + GeneralHelper.HttpResponse httpResponse = GeneralHelper.httpRequest(url, null, null, "GET"); + if (httpResponse.responseCode() != 404) { + String[] ids = httpResponse.data().split("\n"); + for (String s : ids) { + int id = Integer.parseInt(s.split("=")[0]); + String name = s.split("=")[1]; + entityIds.put(id, name); + } + } + nonLivingEntities.add("entity.minecraft.area_effect_cloud"); + nonLivingEntities.add("entity.minecraft.armor_stand"); + nonLivingEntities.add("entity.minecraft.arrow"); + nonLivingEntities.add("entity.minecraft.boat"); + nonLivingEntities.add("entity.minecraft.chest_boat"); + nonLivingEntities.add("entity.minecraft.dragon_fireball"); + nonLivingEntities.add("entity.minecraft.end_crystal"); + nonLivingEntities.add("entity.minecraft.evoker_fangs"); + nonLivingEntities.add("entity.minecraft.experience_orb"); + nonLivingEntities.add("entity.minecraft.eye_of_ender"); + nonLivingEntities.add("entity.minecraft.falling_block"); + nonLivingEntities.add("entity.minecraft.firework_rocket"); + nonLivingEntities.add("entity.minecraft.glow_item_frame"); + nonLivingEntities.add("entity.minecraft.item"); + nonLivingEntities.add("entity.minecraft.item_frame"); + nonLivingEntities.add("entity.minecraft.fireball"); + nonLivingEntities.add("entity.minecraft.leash_knot"); + nonLivingEntities.add("entity.minecraft.lightning_bolt"); + nonLivingEntities.add("entity.minecraft.llama_spit"); + nonLivingEntities.add("entity.minecraft.marker"); + nonLivingEntities.add("entity.minecraft.minecart"); + nonLivingEntities.add("entity.minecraft.chest_minecart"); + nonLivingEntities.add("entity.minecraft.command_block_minecart"); + nonLivingEntities.add("entity.minecraft.furnace_minecart"); + nonLivingEntities.add("entity.minecraft.hopper_minecart"); + nonLivingEntities.add("entity.minecraft.spawner_minecart"); + nonLivingEntities.add("entity.minecraft.tnt_minecart"); + nonLivingEntities.add("entity.minecraft.painting"); + nonLivingEntities.add("entity.minecraft.tnt"); + nonLivingEntities.add("entity.minecraft.shulker_bullet"); + nonLivingEntities.add("entity.minecraft.small_fireball"); + nonLivingEntities.add("entity.minecraft.spectral_arrow"); + nonLivingEntities.add("entity.minecraft.egg"); + nonLivingEntities.add("entity.minecraft.ender_pearl"); + nonLivingEntities.add("entity.minecraft.experience_bottle"); + nonLivingEntities.add("entity.minecraft.potion"); + nonLivingEntities.add("entity.minecraft.trident"); + nonLivingEntities.add("entity.minecraft.wither_skull"); + nonLivingEntities.add("entity.minecraft.fishing_bobber"); + } } diff --git a/java/src/me/dustin/chatbot/network/player/ClientPlayer.java b/java/src/me/dustin/chatbot/entity/player/ClientPlayer.java similarity index 99% rename from java/src/me/dustin/chatbot/network/player/ClientPlayer.java rename to java/src/me/dustin/chatbot/entity/player/ClientPlayer.java index cc14fec..f7f623f 100644 --- a/java/src/me/dustin/chatbot/network/player/ClientPlayer.java +++ b/java/src/me/dustin/chatbot/entity/player/ClientPlayer.java @@ -1,4 +1,4 @@ -package me.dustin.chatbot.network.player; +package me.dustin.chatbot.entity.player; import me.dustin.chatbot.ChatBot; import me.dustin.chatbot.entity.player.PlayerInfo; diff --git a/java/src/me/dustin/chatbot/entity/player/PlayerEntity.java b/java/src/me/dustin/chatbot/entity/player/PlayerEntity.java index 32d4d19..71469dd 100644 --- a/java/src/me/dustin/chatbot/entity/player/PlayerEntity.java +++ b/java/src/me/dustin/chatbot/entity/player/PlayerEntity.java @@ -7,7 +7,7 @@ public class PlayerEntity extends LivingEntity { private final PlayerInfo playerInfo; public PlayerEntity(int entityId, double x, double y, double z, float yaw, float pitch, PlayerInfo playerInfo) { - super(entityId, x, y, z, yaw, pitch); + super(entityId, "entity.minecraft.player", x, y, z, yaw, pitch); this.playerInfo = playerInfo; } diff --git a/java/src/me/dustin/chatbot/network/ClientConnection.java b/java/src/me/dustin/chatbot/network/ClientConnection.java index c57a2e3..c43123d 100644 --- a/java/src/me/dustin/chatbot/network/ClientConnection.java +++ b/java/src/me/dustin/chatbot/network/ClientConnection.java @@ -28,7 +28,7 @@ import me.dustin.chatbot.network.packet.pipeline.PacketEncryptor; import me.dustin.chatbot.network.packet.pipeline.PacketInflater; import me.dustin.chatbot.network.packet.impl.play.s2c.ClientBoundJoinGamePacket; -import me.dustin.chatbot.network.player.ClientPlayer; +import me.dustin.chatbot.entity.player.ClientPlayer; import me.dustin.chatbot.entity.player.PlayerInfoManager; import me.dustin.chatbot.world.World; import me.dustin.chatbot.process.ProcessManager; diff --git a/java/src/me/dustin/chatbot/network/packet/handler/PlayClientBoundPacketHandler.java b/java/src/me/dustin/chatbot/network/packet/handler/PlayClientBoundPacketHandler.java index 0bea268..5acc6cc 100644 --- a/java/src/me/dustin/chatbot/network/packet/handler/PlayClientBoundPacketHandler.java +++ b/java/src/me/dustin/chatbot/network/packet/handler/PlayClientBoundPacketHandler.java @@ -8,12 +8,11 @@ import me.dustin.chatbot.event.EventReceiveChatMessage; import me.dustin.chatbot.event.EventRemovePlayer; import me.dustin.chatbot.helper.GeneralHelper; -import me.dustin.chatbot.network.packet.Packet; import me.dustin.chatbot.network.packet.ProtocolHandler; import me.dustin.chatbot.network.packet.impl.play.c2s.*; import me.dustin.chatbot.network.packet.impl.play.s2c.*; import me.dustin.chatbot.network.packet.pipeline.PacketByteBuf; -import me.dustin.chatbot.network.player.ClientPlayer; +import me.dustin.chatbot.entity.player.ClientPlayer; import me.dustin.chatbot.entity.player.PlayerInfo; import me.dustin.chatbot.world.World; @@ -137,11 +136,15 @@ public void handleSpawnPlayerPacket(ClientBoundSpawnPlayerPacket clientBoundSpaw getClientConnection().getWorld().getLivingEntities().add(player); } + //in 1.19 they deleted the SpawnMob packet and just use the standard spawn entity packet, so now we have to filter non-living entities just to make sure we don't get kicked for attacking an item with KillAura public void handleSpawnMobPacket(ClientBoundSpawnMobPacket clientBoundSpawnMobPacket) { float yaw = (float)(clientBoundSpawnMobPacket.getYaw() * 360) / 256.0f; float pitch = (float)(clientBoundSpawnMobPacket.getPitch() * 360) / 256.0f; - LivingEntity livingEntity = new LivingEntity(clientBoundSpawnMobPacket.getEntityId(), clientBoundSpawnMobPacket.getX(), clientBoundSpawnMobPacket.getY(), clientBoundSpawnMobPacket.getZ(), yaw, pitch); - getClientConnection().getWorld().getLivingEntities().add(livingEntity); + String typeName = LivingEntity.getTypeName(clientBoundSpawnMobPacket.getType()); + if (LivingEntity.isLiving(typeName)) { + LivingEntity livingEntity = new LivingEntity(clientBoundSpawnMobPacket.getEntityId(), typeName, clientBoundSpawnMobPacket.getX(), clientBoundSpawnMobPacket.getY(), clientBoundSpawnMobPacket.getZ(), yaw, pitch); + getClientConnection().getWorld().getLivingEntities().add(livingEntity); + } } public void handleEntityPositionPacket(ClientBoundEntityPositionPacket clientBoundEntityPositionPacket) { diff --git a/java/src/me/dustin/chatbot/network/packet/impl/play/s2c/ClientBoundSpawnMobPacket.java b/java/src/me/dustin/chatbot/network/packet/impl/play/s2c/ClientBoundSpawnMobPacket.java index 1fdd7bb..34c9703 100644 --- a/java/src/me/dustin/chatbot/network/packet/impl/play/s2c/ClientBoundSpawnMobPacket.java +++ b/java/src/me/dustin/chatbot/network/packet/impl/play/s2c/ClientBoundSpawnMobPacket.java @@ -20,7 +20,10 @@ public class ClientBoundSpawnMobPacket extends Packet.ClientBoundPacket { public ClientBoundSpawnMobPacket(PacketByteBuf packetByteBuf) { super(packetByteBuf); this.entityId = packetByteBuf.readVarInt(); - this.uuid = packetByteBuf.readUuid(); + if (ProtocolHandler.getCurrent().getProtocolVer() >= ProtocolHandler.getVersionFromName("1.9").getProtocolVer()) + this.uuid = packetByteBuf.readUuid(); + else + this.uuid = UUID.randomUUID(); this.type = ProtocolHandler.getCurrent().getProtocolVer() <= ProtocolHandler.getVersionFromName("1.10.2").getProtocolVer() ? packetByteBuf.readByte() : packetByteBuf.readVarInt(); if (ProtocolHandler.getCurrent().getProtocolVer() <= ProtocolHandler.getVersionFromName("1.8.9").getProtocolVer()) { this.x = (packetByteBuf.readInt() / 32.D); diff --git a/java/src/me/dustin/chatbot/network/packet/pipeline/PacketDecoderHandler.java b/java/src/me/dustin/chatbot/network/packet/pipeline/PacketDecoderHandler.java index 2ca5b35..d31808c 100644 --- a/java/src/me/dustin/chatbot/network/packet/pipeline/PacketDecoderHandler.java +++ b/java/src/me/dustin/chatbot/network/packet/pipeline/PacketDecoderHandler.java @@ -40,7 +40,7 @@ public PacketDecoderHandler() { playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "plugin"), ClientBoundCustomDataPacket.class); playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_destroy"), ClientBoundRemoveEntities.class); playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_player"), ClientBoundSpawnPlayerPacket.class); - playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_mob_spawn"), ClientBoundSpawnMobPacket.class); + playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_mob_spawn", "entity_object_spawn"), ClientBoundSpawnMobPacket.class); playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "teleport"), ClientBoundEntityTeleportPacket.class); playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "relative_move"), ClientBoundEntityPositionPacket.class); playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "movement_rotation"), ClientBoundEntityPositionPacket.class); diff --git a/java/src/me/dustin/chatbot/process/impl/KillAuraProcess.java b/java/src/me/dustin/chatbot/process/impl/KillAuraProcess.java index 8edcb7d..d80e36a 100644 --- a/java/src/me/dustin/chatbot/process/impl/KillAuraProcess.java +++ b/java/src/me/dustin/chatbot/process/impl/KillAuraProcess.java @@ -8,7 +8,7 @@ import me.dustin.chatbot.network.ClientConnection; import me.dustin.chatbot.network.packet.impl.play.c2s.ServerBoundInteractEntityPacket; import me.dustin.chatbot.network.packet.impl.play.c2s.ServerBoundPlayerSwingPacket; -import me.dustin.chatbot.network.player.ClientPlayer; +import me.dustin.chatbot.entity.player.ClientPlayer; import me.dustin.chatbot.process.ChatBotProcess; public class KillAuraProcess extends ChatBotProcess {