Skip to content

Commit f9b997c

Browse files
committed
Added 1.19 snaphot fixes and entity type parsing
1 parent 11a4f5c commit f9b997c

9 files changed

Lines changed: 101 additions & 12 deletions

File tree

java/src/me/dustin/chatbot/command/impl/CommandCoords.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import me.dustin.chatbot.command.Command;
44
import me.dustin.chatbot.entity.player.PlayerInfo;
5-
import me.dustin.chatbot.network.player.ClientPlayer;
5+
import me.dustin.chatbot.entity.player.ClientPlayer;
66

77
import java.util.Random;
88
import java.util.UUID;

java/src/me/dustin/chatbot/entity/LivingEntity.java

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package me.dustin.chatbot.entity;
22

33
import me.dustin.chatbot.ChatBot;
4+
import me.dustin.chatbot.helper.GeneralHelper;
5+
import me.dustin.chatbot.network.packet.ProtocolHandler;
46
import me.dustin.chatbot.process.ChatBotProcess;
57

8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
612
public class LivingEntity {
713
protected final int entityId;
14+
protected final String type;
815
protected double x, y, z;
916
protected float yaw, pitch;
1017

11-
public LivingEntity(int entityId, double x, double y, double z, float yaw, float pitch) {
18+
private static final ArrayList<String> nonLivingEntities = new ArrayList<>();
19+
private static final Map<Integer, String> entityIds = new HashMap<>();
20+
21+
public LivingEntity(int entityId, String type, double x, double y, double z, float yaw, float pitch) {
1222
this.entityId = entityId;
23+
this.type = type;
1324
this.x = x;
1425
this.y = y;
1526
this.z = z;
@@ -21,6 +32,10 @@ public int getEntityId() {
2132
return entityId;
2233
}
2334

35+
public String getTypeName() {
36+
return type;
37+
}
38+
2439
public double getX() {
2540
return x;
2641
}
@@ -82,4 +97,72 @@ public String toString() {
8297
", pitch=" + pitch +
8398
'}';
8499
}
100+
101+
public static String getTypeName(int id) {
102+
if (!entityIds.containsKey(id))
103+
return "unknown";
104+
return entityIds.get(id);
105+
}
106+
107+
public static boolean isLiving(String name) {
108+
return !nonLivingEntities.contains(name);
109+
}
110+
111+
static {
112+
String v = ProtocolHandler.getCurrent().getName().replace(".", "_");
113+
if (v.contains("pre") || v.contains("w"))
114+
v = "1_19";
115+
//fat fuckin mess to create the version id needed for the link, i.e. 1_12 from 1.12.2
116+
if (v.split("_").length > 2)
117+
v = v.split("_")[0] + "_" + v.split("_")[1];
118+
String url = "https://raw.githubusercontent.com/DustinRepo/ChatBot/master/entityIds/" + v + "_entity_ids.txt";
119+
GeneralHelper.HttpResponse httpResponse = GeneralHelper.httpRequest(url, null, null, "GET");
120+
if (httpResponse.responseCode() != 404) {
121+
String[] ids = httpResponse.data().split("\n");
122+
for (String s : ids) {
123+
int id = Integer.parseInt(s.split("=")[0]);
124+
String name = s.split("=")[1];
125+
entityIds.put(id, name);
126+
}
127+
}
128+
nonLivingEntities.add("entity.minecraft.area_effect_cloud");
129+
nonLivingEntities.add("entity.minecraft.armor_stand");
130+
nonLivingEntities.add("entity.minecraft.arrow");
131+
nonLivingEntities.add("entity.minecraft.boat");
132+
nonLivingEntities.add("entity.minecraft.chest_boat");
133+
nonLivingEntities.add("entity.minecraft.dragon_fireball");
134+
nonLivingEntities.add("entity.minecraft.end_crystal");
135+
nonLivingEntities.add("entity.minecraft.evoker_fangs");
136+
nonLivingEntities.add("entity.minecraft.experience_orb");
137+
nonLivingEntities.add("entity.minecraft.eye_of_ender");
138+
nonLivingEntities.add("entity.minecraft.falling_block");
139+
nonLivingEntities.add("entity.minecraft.firework_rocket");
140+
nonLivingEntities.add("entity.minecraft.glow_item_frame");
141+
nonLivingEntities.add("entity.minecraft.item");
142+
nonLivingEntities.add("entity.minecraft.item_frame");
143+
nonLivingEntities.add("entity.minecraft.fireball");
144+
nonLivingEntities.add("entity.minecraft.leash_knot");
145+
nonLivingEntities.add("entity.minecraft.lightning_bolt");
146+
nonLivingEntities.add("entity.minecraft.llama_spit");
147+
nonLivingEntities.add("entity.minecraft.marker");
148+
nonLivingEntities.add("entity.minecraft.minecart");
149+
nonLivingEntities.add("entity.minecraft.chest_minecart");
150+
nonLivingEntities.add("entity.minecraft.command_block_minecart");
151+
nonLivingEntities.add("entity.minecraft.furnace_minecart");
152+
nonLivingEntities.add("entity.minecraft.hopper_minecart");
153+
nonLivingEntities.add("entity.minecraft.spawner_minecart");
154+
nonLivingEntities.add("entity.minecraft.tnt_minecart");
155+
nonLivingEntities.add("entity.minecraft.painting");
156+
nonLivingEntities.add("entity.minecraft.tnt");
157+
nonLivingEntities.add("entity.minecraft.shulker_bullet");
158+
nonLivingEntities.add("entity.minecraft.small_fireball");
159+
nonLivingEntities.add("entity.minecraft.spectral_arrow");
160+
nonLivingEntities.add("entity.minecraft.egg");
161+
nonLivingEntities.add("entity.minecraft.ender_pearl");
162+
nonLivingEntities.add("entity.minecraft.experience_bottle");
163+
nonLivingEntities.add("entity.minecraft.potion");
164+
nonLivingEntities.add("entity.minecraft.trident");
165+
nonLivingEntities.add("entity.minecraft.wither_skull");
166+
nonLivingEntities.add("entity.minecraft.fishing_bobber");
167+
}
85168
}

java/src/me/dustin/chatbot/network/player/ClientPlayer.java renamed to java/src/me/dustin/chatbot/entity/player/ClientPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.dustin.chatbot.network.player;
1+
package me.dustin.chatbot.entity.player;
22

33
import me.dustin.chatbot.ChatBot;
44
import me.dustin.chatbot.entity.player.PlayerInfo;

java/src/me/dustin/chatbot/entity/player/PlayerEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class PlayerEntity extends LivingEntity {
88
private final PlayerInfo playerInfo;
99
public PlayerEntity(int entityId, double x, double y, double z, float yaw, float pitch, PlayerInfo playerInfo) {
10-
super(entityId, x, y, z, yaw, pitch);
10+
super(entityId, "entity.minecraft.player", x, y, z, yaw, pitch);
1111
this.playerInfo = playerInfo;
1212
}
1313

java/src/me/dustin/chatbot/network/ClientConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import me.dustin.chatbot.network.packet.pipeline.PacketEncryptor;
2929
import me.dustin.chatbot.network.packet.pipeline.PacketInflater;
3030
import me.dustin.chatbot.network.packet.impl.play.s2c.ClientBoundJoinGamePacket;
31-
import me.dustin.chatbot.network.player.ClientPlayer;
31+
import me.dustin.chatbot.entity.player.ClientPlayer;
3232
import me.dustin.chatbot.entity.player.PlayerInfoManager;
3333
import me.dustin.chatbot.world.World;
3434
import me.dustin.chatbot.process.ProcessManager;

java/src/me/dustin/chatbot/network/packet/handler/PlayClientBoundPacketHandler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import me.dustin.chatbot.event.EventReceiveChatMessage;
99
import me.dustin.chatbot.event.EventRemovePlayer;
1010
import me.dustin.chatbot.helper.GeneralHelper;
11-
import me.dustin.chatbot.network.packet.Packet;
1211
import me.dustin.chatbot.network.packet.ProtocolHandler;
1312
import me.dustin.chatbot.network.packet.impl.play.c2s.*;
1413
import me.dustin.chatbot.network.packet.impl.play.s2c.*;
1514
import me.dustin.chatbot.network.packet.pipeline.PacketByteBuf;
16-
import me.dustin.chatbot.network.player.ClientPlayer;
15+
import me.dustin.chatbot.entity.player.ClientPlayer;
1716
import me.dustin.chatbot.entity.player.PlayerInfo;
1817
import me.dustin.chatbot.world.World;
1918

@@ -137,11 +136,15 @@ public void handleSpawnPlayerPacket(ClientBoundSpawnPlayerPacket clientBoundSpaw
137136
getClientConnection().getWorld().getLivingEntities().add(player);
138137
}
139138

139+
//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
140140
public void handleSpawnMobPacket(ClientBoundSpawnMobPacket clientBoundSpawnMobPacket) {
141141
float yaw = (float)(clientBoundSpawnMobPacket.getYaw() * 360) / 256.0f;
142142
float pitch = (float)(clientBoundSpawnMobPacket.getPitch() * 360) / 256.0f;
143-
LivingEntity livingEntity = new LivingEntity(clientBoundSpawnMobPacket.getEntityId(), clientBoundSpawnMobPacket.getX(), clientBoundSpawnMobPacket.getY(), clientBoundSpawnMobPacket.getZ(), yaw, pitch);
144-
getClientConnection().getWorld().getLivingEntities().add(livingEntity);
143+
String typeName = LivingEntity.getTypeName(clientBoundSpawnMobPacket.getType());
144+
if (LivingEntity.isLiving(typeName)) {
145+
LivingEntity livingEntity = new LivingEntity(clientBoundSpawnMobPacket.getEntityId(), typeName, clientBoundSpawnMobPacket.getX(), clientBoundSpawnMobPacket.getY(), clientBoundSpawnMobPacket.getZ(), yaw, pitch);
146+
getClientConnection().getWorld().getLivingEntities().add(livingEntity);
147+
}
145148
}
146149

147150
public void handleEntityPositionPacket(ClientBoundEntityPositionPacket clientBoundEntityPositionPacket) {

java/src/me/dustin/chatbot/network/packet/impl/play/s2c/ClientBoundSpawnMobPacket.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public class ClientBoundSpawnMobPacket extends Packet.ClientBoundPacket {
2020
public ClientBoundSpawnMobPacket(PacketByteBuf packetByteBuf) {
2121
super(packetByteBuf);
2222
this.entityId = packetByteBuf.readVarInt();
23-
this.uuid = packetByteBuf.readUuid();
23+
if (ProtocolHandler.getCurrent().getProtocolVer() >= ProtocolHandler.getVersionFromName("1.9").getProtocolVer())
24+
this.uuid = packetByteBuf.readUuid();
25+
else
26+
this.uuid = UUID.randomUUID();
2427
this.type = ProtocolHandler.getCurrent().getProtocolVer() <= ProtocolHandler.getVersionFromName("1.10.2").getProtocolVer() ? packetByteBuf.readByte() : packetByteBuf.readVarInt();
2528
if (ProtocolHandler.getCurrent().getProtocolVer() <= ProtocolHandler.getVersionFromName("1.8.9").getProtocolVer()) {
2629
this.x = (packetByteBuf.readInt() / 32.D);

java/src/me/dustin/chatbot/network/packet/pipeline/PacketDecoderHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public PacketDecoderHandler() {
4040
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "plugin"), ClientBoundCustomDataPacket.class);
4141
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_destroy"), ClientBoundRemoveEntities.class);
4242
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_player"), ClientBoundSpawnPlayerPacket.class);
43-
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_mob_spawn"), ClientBoundSpawnMobPacket.class);
43+
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "entity_mob_spawn", "entity_object_spawn"), ClientBoundSpawnMobPacket.class);
4444
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "teleport"), ClientBoundEntityTeleportPacket.class);
4545
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "relative_move"), ClientBoundEntityPositionPacket.class);
4646
playMap.put(ProtocolHandler.getCurrent().getPacketId(ProtocolHandler.NetworkSide.CLIENTBOUND, "movement_rotation"), ClientBoundEntityPositionPacket.class);

java/src/me/dustin/chatbot/process/impl/KillAuraProcess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import me.dustin.chatbot.network.ClientConnection;
99
import me.dustin.chatbot.network.packet.impl.play.c2s.ServerBoundInteractEntityPacket;
1010
import me.dustin.chatbot.network.packet.impl.play.c2s.ServerBoundPlayerSwingPacket;
11-
import me.dustin.chatbot.network.player.ClientPlayer;
11+
import me.dustin.chatbot.entity.player.ClientPlayer;
1212
import me.dustin.chatbot.process.ChatBotProcess;
1313

1414
public class KillAuraProcess extends ChatBotProcess {

0 commit comments

Comments
 (0)