Skip to content

Commit

Permalink
Added 1.19 snaphot fixes and entity type parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinRepo committed Apr 15, 2022
1 parent 11a4f5c commit f9b997c
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 12 deletions.
2 changes: 1 addition & 1 deletion java/src/me/dustin/chatbot/command/impl/CommandCoords.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
85 changes: 84 additions & 1 deletion java/src/me/dustin/chatbot/entity/LivingEntity.java
Original file line number Diff line number Diff line change
@@ -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<String> nonLivingEntities = new ArrayList<>();
private static final Map<Integer, String> 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;
Expand All @@ -21,6 +32,10 @@ public int getEntityId() {
return entityId;
}

public String getTypeName() {
return type;
}

public double getX() {
return x;
}
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion java/src/me/dustin/chatbot/entity/player/PlayerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion java/src/me/dustin/chatbot/network/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f9b997c

Please sign in to comment.