0x13 S13PacketDestroyEntities
Removes one or more entities from the client's render list.
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| entityIDs | VarInt[] | Array of entity IDs to destroy |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Count | VarInt | Number of entities |
| Entity IDs | VarInt array | One VarInt per entity |
MCP References
NetHandlerPlayClient.handleDestroyEntities()Handler Interface
INetHandlerPlayClientNotes
Vanilla Source
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
Deobfuscated MCP 1.8.9 source of S13PacketDestroyEntities, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/server/S13PacketDestroyEntities.java) at build time and verified present.
Deep Dive
Role in the protocol
The batch removal packet: a VarInt count followed by that many VarInt entity ids. The server flushes it from EntityPlayerMP.destroyEntitiesInWorld each tick with the accumulated destroy list, and sends the single-id form when a specific entity is removed (player disconnect, entity despawn). The client removes each id from the world's loaded entity list and clears the render manager's entry in handleDestroyEntities, which is how dead mobs, picked-up items and left players vanish.
Vanilla handling
EntityPlayerMP accumulates entity ids to destroy and sends one S13 per tick in destroyEntitiesInWorld; the single-id constructor is used by removeEntity and on player disconnects. NetHandlerPlayClient.handleDestroyEntities iterates the ids, removes each from world.loadedEntityList, clears the entity's render state and drops it from the client's entity lookup. Because removal is id-based and immediate, any client cache keyed by entity id must prune itself on S13 or it will hold stale entries.
Why clients touch it
Cleanup is the theme. Sigma 4.11 Ranking removes hit and prosecutor records for destroyed ids so a kill stat cannot fire after the target despawns. Rise's TranslationComponent maps S13 through the DESTROY_ENTITY entry of its PacketType enum, deleting the entity's position from the bypass map. Rise's PingSpoofComponent buffers S13 inside the players tuple so destruction stays ordered relative to held entity updates. KillAura and ESP target lists in these clients hold entity objects from the world list, so the vanilla removal handles them with no packet hook. November Recode 2.0's AntiBotModule watches S13 in WATCHDOG mode: when the destroyed ids include the bot it detected above the player, it prints a staff-removal notice and re-arms the spawn veto.
Exploit surface
S13 is a pure removal vector: the server despawns arbitrary ids, and the client has no say in it. The abuse angle is timing: entities destroyed on the server remain attackable client-side only if the client delays the packet, which is exactly what buffering S13 in PingSpoofComponent does, keeping ghost entities alive for the spoof window. Anti-cheats watch for players attacking ids that were destroyed server-side (attack-after-desync), the signature of ghost-entity kill aura; a client that buffers S13 must also stop targeting those ids when the flush lands.
Server-Side Handling
EntityPlayerMP.destroyEntitiesInWorld collects pending entity ids and sends a single S13 per tick; the single-id form is sent by removeEntity and on player disconnects. The client handler iterates the ids, removes each entity from world.loadedEntityList, clears its render state and drops it from the entity lookup. No validation is applied to the id list, so ids that do not exist are ignored.
Protocol Analysis
VarInt count, then count VarInt entity ids. The count field makes the packet self-describing; 1.8 clients accept any count including 0. Entity ids are server-assigned and unique per world session, which is why id-keyed caches (Sigma's hit maps, Rise's translation map) can prune by id without ambiguity. The packet is emitted every tick the destroy list is non-empty, so it arrives in bursts.
Anti-Cheat Landscape
The packet itself is never flagged; its timing is. Attack-after-desync detection compares the ids a client attacks with the ids the server destroyed, so any buffering or replay of S13 that outlives the destroy is the detectable pattern. Ping-spoof buffering of S13 is safe only while the flush stays inside the anticheat's entity-desync tolerance, which is why Rise pairs the component with per-anticheat velocity and teleport handling.
implementation Implementation Cases
The batch entity-removal packet. In the reference corpus its handlers are all cache pruning: Sigma's Ranking drops hit/prosecutor records, Rise's TranslationComponent removes map entries through DESTROY_ENTITY, and Rise's PingSpoofComponent buffers it with the entity stream so destruction stays ordered while ping spoofing. KillAura and ESP need no hook because their target lists are world-entity objects.
Track kills and deaths against named players and report stats, pruning records when targets despawn.
Hidden module that records attacked players in hitEntities and suspects in prosecutorEntities via EventAttack, correlates S0B animation with S06 health drops and S02 chat messages to attribute kills, and on S13 iterates the destroyed ids through onEntityRemoved so a removed player's record cannot later fire a kill stat. S18 teleport and S08 respawn share the cleanup paths.
// ===== FILE: Sigma 4.11, info/sigmaclient/module/impl/other/Ranking.java =====
package info.sigmaclient.module.impl.other;
import info.sigmaclient.Client;
import info.sigmaclient.event.Event;
import info.sigmaclient.event.RegisterEvent;
import info.sigmaclient.event.impl.EventAttack;
import info.sigmaclient.event.impl.EventPacket;
import info.sigmaclient.event.impl.EventUpdate;
import info.sigmaclient.management.users.TTSystem;
import info.sigmaclient.module.Module;
import info.sigmaclient.module.data.ModuleData;
import info.sigmaclient.util.Timer;
import info.sigmaclient.util.misc.ChatUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
public class Ranking extends Module {
private HashMap<Integer, HitEntity> hitEntities = new HashMap<>();
private HashMap<Integer, HitEntity> prosecutorEntities = new HashMap<>();
private HashMap<Integer, Long> lastAnimationTimestamp = new HashMap<>();
private info.sigmaclient.util.Timer delay = new Timer();
public Ranking(ModuleData data) {
super(data);
setHidden(true);
if (!isEnabled()) {
toggle();
}
}
@Override
@RegisterEvent(events = {EventAttack.class, EventPacket.class, EventUpdate.class})
public void onEvent(Event e) {
if (e instanceof EventAttack) {
EventAttack ea = (EventAttack) e;
if (ea.getEntity() instanceof EntityPlayer) {
EntityPlayer ep = (EntityPlayer) ea.getEntity();
if (!ep.getName().isEmpty()) {
if (!hitEntities.containsKey(ep.getEntityId())) {
hitEntities.put(ep.getEntityId(), new HitEntity(ep));
} else {
hitEntities.get(ep.getEntityId()).refresh();
}
}
}
} else if (e instanceof EventPacket) {
EventPacket ep = (EventPacket) e;
Packet packet = ep.getPacket();
if (packet instanceof S0BPacketAnimation) {
S0BPacketAnimation packetAnimation = (S0BPacketAnimation) packet;
lastAnimationTimestamp.put(packetAnimation.func_148978_c(), System.currentTimeMillis());
}
if (packet instanceof S06PacketUpdateHealth) {
S06PacketUpdateHealth packetUpdateHealth = (S06PacketUpdateHealth) packet;
if (packetUpdateHealth.getHealth() <= Minecraft.getMinecraft().thePlayer.getHealth()) {
try{
for (Object o : mc.theWorld.getLoadedEntityList()) {
if (o instanceof EntityPlayer) {
EntityPlayer entityPlayer = (EntityPlayer) o;
if (!(entityPlayer instanceof EntityPlayerSP) && lastAnimationTimestamp.containsKey(entityPlayer.getEntityId())) {
if (lastAnimationTimestamp.get(entityPlayer.getEntityId()) > System.currentTimeMillis() - 70 && entityPlayer.getPositionVector().squareDistanceTo(Minecraft.getMinecraft().thePlayer.getPositionVector()) < 9 * 9) {
if (!prosecutorEntities.containsKey(entityPlayer.getEntityId())) {
prosecutorEntities.put(entityPlayer.getEntityId(), new HitEntity(entityPlayer, true));
} else {
prosecutorEntities.get(entityPlayer.getEntityId()).refresh();
}
}
}
}
}
}catch(ConcurrentModificationException ee){};
}
if (packetUpdateHealth.getHealth() <= 0) {
onDeath();
}
}
if (packet instanceof S02PacketChat) {
S02PacketChat packetChat = (S02PacketChat) packet;
String message = packetChat.func_148915_c().getUnformattedText();
Iterator it = hitEntities.entrySet().iterator();
while (it.hasNext()) {
HitEntity hitEntity = ((Map.Entry<Integer, HitEntity>) it.next()).getValue();
if (hitEntity.getTime() > System.currentTimeMillis() - 3000 && message.contains(hitEntity.getName())) {
if (hitEntity.onChatMessage()) {
it.remove();
}
}
}
Iterator it2 = prosecutorEntities.entrySet().iterator();
while (it2.hasNext()) {
HitEntity hitEntity = ((Map.Entry<Integer, HitEntity>) it2.next()).getValue();
if (hitEntity.getTime() > System.currentTimeMillis() - 3000 && message.contains(hitEntity.getName()) && message.contains(Minecraft.getMinecraft().thePlayer.getName())) {
if (hitEntity.onChatMessage()) {
it2.remove();
}
}
}
} else if (packet instanceof S18PacketEntityTeleport) {
S18PacketEntityTeleport packetTeleport = (S18PacketEntityTeleport) packet;
int entityId = packetTeleport.func_149451_c();
onEntityRemoved(entityId);
} else if (packet instanceof S08PacketPlayerPosLook) {
onDeath();
} else if (packet instanceof S13PacketDestroyEntities) {
S13PacketDestroyEntities packetDestroyEntities = (S13PacketDestroyEntities) packet;
for (int entityId : packetDestroyEntities.func_149098_c()) {
onEntityRemoved(entityId);
}
} else if (packet instanceof S40PacketDisconnect) {
S40PacketDisconnect packetDisconnect = (S40PacketDisconnect) packet;
if (packetDisconnect.func_149165_c().getUnformattedText().toLowerCase().contains("ban") && Minecraft.getMinecraft().thePlayer != null && Minecraft.getMinecraft().thePlayer.ticksExisted > 15 * 20) {
sendStat("ban", "");
}
}
} else if (e instanceof EventUpdate) {
if (delay.delay(1000 * 60 * 10)) {
delay.reset();
sendStat("tick", "");
}
}
}
private void onDeath() {
Iterator it2 = prosecutorEntities.entrySet().iterator();
while (it2.hasNext()) {
HitEntity hitEntity = ((Map.Entry<Integer, HitEntity>) it2.next()).getValue();
if (hitEntity.getTime() > System.currentTimeMillis() - 3000) {
if (hitEntity.onRemoved()) {
it2.remove();
}
}
}
}
private void onEntityRemoved(int entityId) {
Iterator it = hitEntities.entrySet().iterator();
while (it.hasNext()) {
HitEntity hitEntity = ((Map.Entry<Integer, HitEntity>) it.next()).getValue();
if (hitEntity.getTime() > System.currentTimeMillis() - 3000 && entityId == hitEntity.getEntityId()) {
if (hitEntity.onRemoved()) {
it.remove();
}
}
}
}
public void sendStat(String type, String data) {
}
private class HitEntity {
private long time = System.currentTimeMillis();
private UUID uuid;
private String name;
private int entityId;
private boolean removed = false;
private boolean chatMessage = false;
private boolean prosecutor = false;
public HitEntity(EntityPlayer ep) {
uuid = ep.getUniqueID();
name = ep.getName();
entityId = ep.getEntityId();
}
public HitEntity(EntityPlayer ep, boolean prosecutor) {
uuid = ep.getUniqueID();
name = ep.getName();
entityId = ep.getEntityId();
this.prosecutor = prosecutor;
}
public boolean onRemoved() {
removed = true;
if (chatMessage) {
if (prosecutor) {
prosecuted();
} else {
killed();
}
return true;
}
return false;
}
public boolean onChatMessage() {
chatMessage = true;
if (removed) {
if (prosecutor) {
prosecuted();
} else {
killed();
}
return true;
}
return false;
}
private void killed() {
//ChatUtil.printChat("Kill (" + name + ") " + uuid.toString());
sendStat("kill", "&uuid=" + uuid.toString().replaceAll("-", ""));
}
public void refresh() {
time = System.currentTimeMillis();
}
public String getName() {
return name;
}
public long getTime() {
return time;
}
public int getEntityId() {
return entityId;
}
public void prosecuted() {
//ChatUtil.printChat("Prosecuted (" + name + ") " + uuid.toString());
sendStat("death", "&uuid=" + uuid.toString().replaceAll("-", ""));
}
}
}
// NOTE (AI): Hidden stat-tracking module: records attacked players and prosecutors, correlates S0B animation with S06 health drops to attribute kills, and watches S02 chat for kill messages. S13 is the cleanup path: destroyed entity ids are matched against the hit and prosecutor maps so stale records cannot fire a kill stat after the target despawns. S18 teleport and S08 respawn share the same onEntityRemoved and onDeath paths.Hold S13 in the entity-stream buffer while ping spoofing so destruction stays ordered relative to buffered entity updates.
S13 is listed in the players tuple of the component's packet classification. While a spoof is active, matching packets are cancelled from the event stream and parked in a timestamped queue; onPostMotion flushes entries whose delay elapsed. Holding S13 alongside S14/S16/S15/S17/S18/S19/S20 keeps replay order coherent so a flushed destroy cannot land before the entity updates that precede it.
// ===== FILE: Rise 6.1.30, com/alan/clients/component/impl/player/PingSpoofComponent.java =====
package com.alan.clients.component.impl.player;
import com.alan.clients.component.Component;
import com.alan.clients.event.CancellableEvent;
import com.alan.clients.event.Listener;
import com.alan.clients.event.annotations.EventLink;
import com.alan.clients.event.impl.motion.PostMotionEvent;
import com.alan.clients.event.impl.other.WorldChangeEvent;
import com.alan.clients.event.impl.packet.PacketReceiveEvent;
import com.alan.clients.event.impl.packet.PacketSendEvent;
import com.alan.clients.util.packet.PacketUtil;
import net.minecraft.client.gui.GuiDownloadTerrain;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.*;
import net.minecraft.network.play.server.*;
import net.minecraft.util.Tuple;
import rip.vantage.commons.util.time.StopWatch;
import java.util.Arrays;
import java.util.concurrent.ConcurrentLinkedQueue;
public final class PingSpoofComponent extends Component {
public static ConcurrentLinkedQueue<PacketUtil.TimedPacket> packets = new ConcurrentLinkedQueue<>();
static StopWatch enabledTimer = new StopWatch();
public static boolean enabled;
static long amount;
static Tuple<Class[], Boolean> regular = new Tuple<>(new Class[]{C0FPacketConfirmTransaction.class, C00PacketKeepAlive.class, S1CPacketEntityMetadata.class}, false);
static Tuple<Class[], Boolean> velocity = new Tuple<>(new Class[]{S12PacketEntityVelocity.class, S27PacketExplosion.class}, false);
static Tuple<Class[], Boolean> teleports = new Tuple<>(new Class[]{S08PacketPlayerPosLook.class, S39PacketPlayerAbilities.class, S09PacketHeldItemChange.class}, false);
static Tuple<Class[], Boolean> players = new Tuple<>(new Class[]{S13PacketDestroyEntities.class, S14PacketEntity.class, S14PacketEntity.S16PacketEntityLook.class, S14PacketEntity.S15PacketEntityRelMove.class, S14PacketEntity.S17PacketEntityLookMove.class, S18PacketEntityTeleport.class, S20PacketEntityProperties.class, S19PacketEntityHeadLook.class}, false);
static Tuple<Class[], Boolean> blink = new Tuple<>(new Class[]{C02PacketUseEntity.class, C0DPacketCloseWindow.class, C0EPacketClickWindow.class, C0CPacketInput.class, C0BPacketEntityAction.class, C08PacketPlayerBlockPlacement.class, C07PacketPlayerDigging.class, C09PacketHeldItemChange.class, C13PacketPlayerAbilities.class, C15PacketClientSettings.class, C16PacketClientStatus.class, C17PacketCustomPayload.class, C18PacketSpectate.class, C19PacketResourcePackStatus.class, C03PacketPlayer.class, C03PacketPlayer.C04PacketPlayerPosition.class, C03PacketPlayer.C05PacketPlayerLook.class, C03PacketPlayer.C06PacketPlayerPosLook.class, C0APacketAnimation.class}, false);
static Tuple<Class[], Boolean> movement = new Tuple<>(new Class[]{C03PacketPlayer.class, C03PacketPlayer.C04PacketPlayerPosition.class, C03PacketPlayer.C05PacketPlayerLook.class, C03PacketPlayer.C06PacketPlayerPosLook.class}, false);
public static Tuple<Class[], Boolean>[] types = new Tuple[]{regular, velocity, teleports, players, blink, movement};
@EventLink
public final Listener<PacketSendEvent> send = event -> event.setCancelled(onPacket(event.getPacket(), event).isCancelled());
@EventLink
public final Listener<PacketReceiveEvent> receive = event -> event.setCancelled(onPacket(event.getPacket(), event).isCancelled());
public CancellableEvent onPacket(Packet<?> packet, CancellableEvent event) {
if (!event.isCancelled() && enabled && Arrays.stream(types).anyMatch(tuple -> tuple.getSecond() && Arrays.stream(tuple.getFirst()).anyMatch(regularpacket -> regularpacket == packet.getClass()))) {
event.setCancelled();
packets.add(new PacketUtil.TimedPacket(packet));
}
return event;
}
public static void dispatch() {
if (!packets.isEmpty()) {
// Stops the packets from being called twice
boolean enabled = PingSpoofComponent.enabled;
PingSpoofComponent.enabled = false;
packets.forEach(timedPacket -> PacketUtil.queue(timedPacket.getPacket()));
PingSpoofComponent.enabled = enabled;
packets.clear();
}
}
public static void disable() {
enabled = false;
enabledTimer.setMillis(enabledTimer.millis - 999999999);
}
@EventLink
public final Listener<WorldChangeEvent> onWorldChange = event -> dispatch();
@EventLink
public final Listener<PostMotionEvent> onPostMotion = event -> {
if (!(enabled = !enabledTimer.finished(100) && !(mc.currentScreen instanceof GuiDownloadTerrain))) {
dispatch();
} else {
// Stops the packets from being called twice
enabled = false;
packets.forEach(packet -> {
if (packet.getTime() + amount < System.currentTimeMillis()) {
PacketUtil.queue(packet.getPacket());
packets.remove(packet);
}
});
enabled = true;
}
};
public static void spoof(int amount, boolean regular, boolean velocity, boolean teleports, boolean players) {
spoof(amount, regular, velocity, teleports, players, false);
}
public static void spoof(int amount, boolean regular, boolean velocity, boolean teleports, boolean players, boolean blink, boolean movement) {
enabledTimer.reset();
PingSpoofComponent.regular.setSecond(regular);
PingSpoofComponent.velocity.setSecond(velocity);
PingSpoofComponent.teleports.setSecond(teleports);
PingSpoofComponent.players.setSecond(players);
PingSpoofComponent.blink.setSecond(blink);
PingSpoofComponent.movement.setSecond(movement);
PingSpoofComponent.amount = amount;
}
public static void spoof(int amount, boolean regular, boolean velocity, boolean teleports, boolean players, boolean blink) {
spoof(amount, regular, velocity, teleports, players, blink, false);
}
public static void blink() {
spoof(9999999, true, false, false, false, true);
}
}
// NOTE (AI): S13 is one of the classes in the players tuple, the entity-stream buffer the component holds while ping spoofing. Buffering destruction keeps entity removal ordered relative to held S14/S18/S19/S20 updates, so replayed packets do not resurrect or desync ghost entities. In this corpus S13 is the only destroy-class packet the buffer covers.Remove destroyed entity ids from the entity-position map the Translation bypass maintains.
The DESTROY_ENTITY entry of the PacketType enum casts to S13PacketDestroyEntities, iterates getEntityIDs() and removes each from the entityPositions map. The map is the single source of truth for the Translation component's entity tracking, so a missed removal would let the bypass interpolate a despawned entity.
// ===== FILE: Rise 6.2.4, Client-release2/Client/src/main/java/com/alan/clients/component/impl/player/translation/PacketType.java =====
package com.alan.clients.component.impl.player.translation;
import lombok.Getter;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.*;
import java.util.Map;
import java.util.function.BiFunction;
public enum PacketType {
SPAWN_MOB(S0FPacketSpawnMob.class, (packet, entityPositions) -> {
S0FPacketSpawnMob spawnMobPacket = (S0FPacketSpawnMob) packet;
int entityId = spawnMobPacket.getEntityID();
double posX = spawnMobPacket.getX() / 32.0;
double posY = spawnMobPacket.getY() / 32.0;
double posZ = spawnMobPacket.getZ() / 32.0;
float yaw = (spawnMobPacket.getYaw() * 360) / 256.0F;
float pitch = (spawnMobPacket.getPitch() * 360) / 256.0F;
Position newPosition = new Position(posX, posY, posZ, yaw, pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}),
ENTITY_TELEPORT(S18PacketEntityTeleport.class, (packet, entityPositions) -> {
S18PacketEntityTeleport teleportPacket = (S18PacketEntityTeleport) packet;
int entityId = teleportPacket.getEntityId();
double posX = teleportPacket.getX() / 32.0;
double posY = teleportPacket.getY() / 32.0;
double posZ = teleportPacket.getZ() / 32.0;
float yaw = (teleportPacket.getYaw() * 360) / 256.0F;
float pitch = (teleportPacket.getPitch() * 360) / 256.0F;
Position newPosition = new Position(posX, posY, posZ, yaw, pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}),
ENTITY_REL_MOVE(S14PacketEntity.S15PacketEntityRelMove.class, (packet, entityPositions) -> {
S14PacketEntity.S15PacketEntityRelMove relMovePacket = (S14PacketEntity.S15PacketEntityRelMove) packet;
int entityId = relMovePacket.entityId;
Position currentPosition = entityPositions.get(entityId);
if (currentPosition != null) {
double newPosX = currentPosition.posX + relMovePacket.getPosX() / 32.0;
double newPosY = currentPosition.posY + relMovePacket.getPosY() / 32.0;
double newPosZ = currentPosition.posZ + relMovePacket.getPosZ() / 32.0;
float yaw = currentPosition.yaw;
float pitch = currentPosition.pitch;
Position newPosition = new Position(newPosX, newPosY, newPosZ, yaw, pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}
return null;
}),
ENTITY_LOOK_MOVE(S14PacketEntity.S17PacketEntityLookMove.class, (packet, entityPositions) -> {
S14PacketEntity.S17PacketEntityLookMove lookMovePacket = (S14PacketEntity.S17PacketEntityLookMove) packet;
int entityId = lookMovePacket.getEntityId();
double deltaX = lookMovePacket.getPosX() / 32.0;
double deltaY = lookMovePacket.getPosY() / 32.0;
double deltaZ = lookMovePacket.getPosZ() / 32.0;
float yaw = (lookMovePacket.getYaw() * 360) / 256.0F;
float pitch = (lookMovePacket.getPitch() * 360) / 256.0F;
Position currentPosition = entityPositions.get(entityId);
if (currentPosition != null) {
double newPosX = currentPosition.posX + deltaX;
double newPosY = currentPosition.posY + deltaY;
double newPosZ = currentPosition.posZ + deltaZ;
// Ensure yaw and pitch are updated
Position newPosition = new Position(newPosX, newPosY, newPosZ, yaw, pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}
return null;
}),
ENTITY_LOOK(S14PacketEntity.S16PacketEntityLook.class, (packet, entityPositions) -> {
S14PacketEntity.S16PacketEntityLook lookPacket = (S14PacketEntity.S16PacketEntityLook) packet;
int entityId = lookPacket.getEntityId();
float yaw = (lookPacket.getYaw() * 360) / 256.0F;
float pitch = (lookPacket.getPitch() * 360) / 256.0F;
Position currentPosition = entityPositions.get(entityId);
if (currentPosition != null) {
Position newPosition = new Position(currentPosition.posX, currentPosition.posY, currentPosition.posZ, yaw, pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}
return null;
}),
DESTROY_ENTITY(S13PacketDestroyEntities.class, (packet, entityPositions) -> {
S13PacketDestroyEntities destroyEntitiesPacket = (S13PacketDestroyEntities) packet;
int[] entityIds = destroyEntitiesPacket.getEntityIDs();
for (int entityId : entityIds) {
entityPositions.remove(entityId);
}
return entityPositions;
}),
ENTITY_HEAD_LOOK(S19PacketEntityHeadLook.class, (packet, entityPositions) -> {
S19PacketEntityHeadLook headLookPacket = (S19PacketEntityHeadLook) packet;
int entityId = headLookPacket.getEntityId();
float headYaw = (headLookPacket.getYaw() * 360) / 256.0F;
Position currentPosition = entityPositions.get(entityId);
if (currentPosition != null) {
Position newPosition = new Position(currentPosition.posX, currentPosition.posY, currentPosition.posZ, headYaw, currentPosition.pitch);
entityPositions.put(entityId, newPosition);
return entityPositions;
}
return null;
});
@Getter
private final Class<? extends Packet<?>> packetClass;
private final BiFunction<Packet<?>, Map<Integer, Position>, Map<Integer, Position>> handler;
PacketType(Class<? extends Packet<?>> packetClass, BiFunction<Packet<?>, Map<Integer, Position>, Map<Integer, Position>> handler) {
this.packetClass = packetClass;
this.handler = handler;
}
public Map<Integer, Position> handle(Packet<?> packet, Map<Integer, Position> positions) {
return handler.apply(packet, positions);
}
}
// NOTE (AI): The TranslationComponent packet registry. SPAWN_MOB decodes the fixed-point spawn coordinates (x32) and byte rotations (x256/360) into the entityPositions map that the Translation bypass feeds on, so the client keeps its own copy of every mob's server-side position. DESTROY_ENTITY removes entries when S13 arrives, and the same enum covers S18 teleport, S14 relative moves and looks, and S19 head look.Confirm that a detected bot was destroyed server-side, so the module can re-arm the S0C spawn veto and warn that staff removed the entity.
In WATCHDOG mode the packet listener iterates the destroyed entity ids of every S13. If one equals aboveEntityId (the bot the module detected above the player), it prints a removed-from-world notice and resets the tracker to -1, which re-arms the S0C branch of the same listener to flag the next spawn as a bot.
// ===== FILE: November Recode 2.0, feature/module/impl/combat/AntiBotModule.java =====
/* November.lol © 2023 */
package lol.november.feature.module.impl.combat;
import io.netty.util.internal.ConcurrentSet;
import java.util.Set;
import lol.november.feature.module.Category;
import lol.november.feature.module.Module;
import lol.november.feature.module.Register;
import lol.november.feature.setting.Setting;
import lol.november.listener.bus.Listener;
import lol.november.listener.bus.Subscribe;
import lol.november.listener.event.net.EventPacket;
import lol.november.listener.event.player.EventUpdate;
import lol.november.utility.chat.Printer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
import net.minecraft.network.play.server.S13PacketDestroyEntities;
/**
* @author Gavin
* @since 2.0.0
*/
@Register(
name = "AntiBot",
description = "Prevents you from attacking bots",
category = Category.COMBAT
)
public class AntiBotModule extends Module {
private final Setting<Mode> mode = new Setting<>("Mode", Mode.WATCHDOG);
private final Setting<Integer> tabTicks = new Setting<>(
() -> mode.getValue() == Mode.TAB_TICKS,
"Tab Ticks",
50,
1,
0,
500
);
private final Setting<Boolean> noTab = new Setting<>(
() -> mode.getValue() == Mode.NPC,
"No Tab List",
true
);
private final Set<Integer> bots = new ConcurrentSet<>();
private int aboveEntityId = -1;
private boolean aboveDespawn;
@Override
public void disable() {
super.disable();
bots.clear();
aboveEntityId = -1;
aboveDespawn = false;
}
@Subscribe
private final Listener<EventUpdate> update = event -> {
if (mc.thePlayer.ticksExisted < 5) {
bots.clear();
if (mode.getValue() == Mode.WATCHDOG) {
aboveEntityId = -1;
aboveDespawn = false;
}
return;
}
switch (mode.getValue()) {
case WATCHDOG -> {
// todo i have no clue
for (EntityPlayer player : mc.theWorld.playerEntities) {
if (player == null || player.equals(mc.thePlayer)) continue;
if (!tabList(player) && player.isInvisible()) {
bots.add(player.getEntityId());
}
}
if (aboveEntityId != -1) return;
for (int bot : bots) {
Entity entity = mc.theWorld.getEntityByID(bot);
if (!(entity instanceof EntityPlayer)) {
bots.remove(bot);
continue;
}
if (Math.abs(entity.posY - mc.thePlayer.posY) <= 10.0) {
aboveEntityId = entity.getEntityId();
Printer.print(
"Detected bot above you: " +
aboveEntityId +
" (" +
entity.getName() +
")"
);
break;
}
}
}
case TAB_TICKS -> {
for (EntityPlayer player : mc.theWorld.playerEntities) {
if (player == null || player.equals(mc.thePlayer)) continue;
if (
player.ticksExisted > tabTicks.getValue() && !tabList(player)
) bots.add(player.getEntityId());
}
}
case NPC -> {
for (EntityPlayer player : mc.theWorld.playerEntities) {
if (player == null || player.equals(mc.thePlayer)) continue;
String name = player.getGameProfile().getName();
if (
name.startsWith("CIT-") ||
name.contains("[NPC]") ||
name.contains("\u00A7") ||
(!tabList(player) && noTab.getValue())
) bots.add(player.getEntityId());
}
}
}
};
@Subscribe
private final Listener<EventPacket.In> packetIn = event -> {
if (mode.getValue() == Mode.WATCHDOG) {
if (event.get() instanceof S13PacketDestroyEntities packet) {
for (int entityId : packet.getEntityIDs()) {
if (entityId == aboveEntityId) {
Printer.print(entityId + " was removed from the world. Staff?");
aboveEntityId = -1;
}
}
} else if (event.get() instanceof S0CPacketSpawnPlayer packet) {
if (!aboveDespawn) return;
bots.add(packet.getEntityID());
Printer.print("Suspicious entity spawn: " + packet.getEntityID());
}
}
};
private boolean tabList(EntityPlayer player) {
for (NetworkPlayerInfo info : mc.thePlayer.sendQueue.getPlayerInfoMap()) {
if (
info
.getGameProfile()
.getName()
.equals(player.getGameProfile().getName())
) return true;
}
return false;
}
public boolean bot(int entityId) {
return bots.contains(entityId);
}
private enum Mode {
TAB_TICKS,
NPC,
WATCHDOG,
}
}
// NOTE (AI): The S13 listener in AntiBotModule runs only in WATCHDOG mode and is a despawn watcher: if the destroyed entity ids include aboveEntityId (the bot the module detected above the player), it prints a staff-removal notice and resets the tracker so the next spawn veto (the S0C branch of the same listener) can arm again. The reset is what chains the module's two packet hooks: S13 confirms the bot vanished server-side, and the next S0C spawn is then assumed to be a replacement bot.anticheat Anti-Cheat Checks
The destroy packet removes entity ids from the client's world, and server-side anticheats mirror that removal in their entity trackers. Because reach and hitbox checks must never measure against an entity the client no longer sees, destroy handling is data hygiene: Kauri removes fake-mob state on the confirming keepalive, intave decodes the destroy payload across three protocol layouts, and Hydro deletes the tracked entity on the send side. The packet is never flagged; keeping the tracker in sync with it is what keeps entity checks honest.
Remove fake-mob state for destroyed entities on the keepalive that confirms the destroy packet reached the client.
PacketHandler routes DESTROY_ENTITIES (both modern and legacy wrappers) to EntityTrackHandler.onEntityDestroy, which schedules a keepalive action: for each destroyed id it calls removeFakeMob, despawning any fake mobs the anticheat placed next to the tracked entity and clearing the client-has-entity flag. Fake mobs are the anti-hitbox probes Kauri spawns around combat entities, so their lifecycle must mirror real despawns exactly or reach checks would measure against ghosts.
// ===== FILE: funkemunky-KauriV3, Anticheat/src/main/java/dev/brighten/ac/handler/EntityTrackHandler.java =====
package dev.brighten.ac.handler;
import com.github.retrooper.packetevents.protocol.attribute.Attribute;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityPositionSync;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityTeleport;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes;
import dev.brighten.ac.data.APlayer;
import dev.brighten.ac.handler.entity.FakeMob;
import dev.brighten.ac.handler.entity.TrackedEntity;
import dev.brighten.ac.packet.WPacketPlayOutEntity;
import dev.brighten.ac.utils.EntityLocation;
import dev.brighten.ac.utils.KLocation;
import dev.brighten.ac.utils.timer.Timer;
import dev.brighten.ac.utils.timer.impl.MillisTimer;
import dev.brighten.ac.utils.world.types.RayCollision;
import lombok.RequiredArgsConstructor;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@RequiredArgsConstructor
public class EntityTrackHandler {
private final APlayer data;
private final Timer lastFlying = new MillisTimer();
public Set<Integer> canCreateMob = new HashSet<>();
public int streak;
public AtomicBoolean clientHasEntity = new AtomicBoolean(false);
private final Set<EntityType> allowedEntityTypes = Set.of(EntityTypes.ZOMBIE, EntityTypes.SHEEP,
EntityTypes.BLAZE, EntityTypes.SKELETON, EntityTypes.PLAYER, EntityTypes.VILLAGER, EntityTypes.IRON_GOLEM,
EntityTypes.WITCH, EntityTypes.COW, EntityTypes.CREEPER);
public Optional<Integer> getTargetOfFakeMob(int fakeMobId) {
for (TrackedEntity value : data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntities().values()) {
if(value.getFakeMobs().stream().anyMatch(mob -> mob.getEntityId() == fakeMobId)) {
return Optional.of(value.getEntityId());
}
}
return Optional.empty();
}
/**
*
* We are processing PacketPlayInFlying to iterate the tracked entity locations
*
*/
void onFlying() {
if(lastFlying.isNotPassed(1)) streak++;
else {
streak = 1;
}
processZombie();
data.getWorldTracker().getCurrentWorld().get().getTrackedEntities().values().forEach(entity -> {
var oldLoc = entity.getOldEntityLocation();
var newLoc = entity.getNewEntityLocation();
if(oldLoc != null) {
if(oldLoc.interpolatedLocations.size() > 1 && oldLoc.increment == 0) {
oldLoc.interpolatedLocations.removeFirst();
}
oldLoc.interpolateLocation();
}
if(newLoc != null) {
if(newLoc.interpolatedLocations.size() > 1 && newLoc.increment == 0) {
newLoc.interpolatedLocations.removeFirst();
}
newLoc.interpolateLocation();
}
});
lastFlying.reset();
}
/**
*
* Processing PacketPlayOutRelativePosition for updating entity locations in a relative manner.
*
* @param packet WrappedOutRelativePosition
*/
void onRelPosition(WPacketPlayOutEntity packet) {
Optional<TrackedEntity> entity = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(packet.getId());
if(entity.isEmpty() || !allowedEntityTypes.contains(entity.get().getEntityType())) return;
processFakeMobs(packet.getId(), true, packet.getX(), packet.getY(), packet.getZ());
EntityLocation eloc = entity.get().getNewEntityLocation();
entity.get().setOldEntityLocation(entity.get().getNewEntityLocation().clone());
runAction(entity.get(), () -> {
//We don't need to do version checking here. Atlas handles this for us.
eloc.newX += packet.getX();
eloc.newY += packet.getY();
eloc.newZ += packet.getZ();
eloc.newYaw += packet.getYaw();
eloc.newPitch += packet.getPitch();
eloc.increment = 3;
});
}
void onPositionSync(WrapperPlayServerEntityPositionSync packet) {
Optional<TrackedEntity> entity = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(packet.getId());
if(entity.isEmpty() || !allowedEntityTypes.contains(entity.get().getEntityType())) return;
processFakeMobs(packet.getId(), false, packet.getValues().getPosition().getX(),
packet.getValues().getPosition().getY(), packet.getValues().getPosition().getZ());
EntityLocation eloc = entity.get().getNewEntityLocation();
entity.get().setOldEntityLocation(entity.get().getNewEntityLocation().clone());
runAction(entity.get(), () -> {
//We don't need to do version checking here. Atlas handles this for us.
eloc.newX = packet.getValues().getPosition().getX();
eloc.newY = packet.getValues().getPosition().getY();
eloc.newZ = packet.getValues().getPosition().getZ();
eloc.newYaw = packet.getValues().getYaw();
eloc.newPitch = packet.getValues().getPitch();
eloc.increment = 3;
});
}
/**
*
* Processing PacketPlayOutEntityTeleport to update locations in a non-relative manner.
*
* @param packet WrappedOutEntityTeleportPacket
*/
void onTeleportSent(WrapperPlayServerEntityTeleport packet) {
Optional<TrackedEntity> entity = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(packet.getEntityId());
if(entity.isEmpty() || !allowedEntityTypes.contains(entity.get().getEntityType())) return;
processFakeMobs(packet.getEntityId(), false, packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
EntityLocation eloc = entity.get().getNewEntityLocation();
entity.get().setOldEntityLocation(entity.get().getNewEntityLocation().clone());
runAction(entity.get(), () -> {
if(data.getPlayerVersion().isNewerThanOrEquals(ClientVersion.V_1_9)) {
if (!(Math.abs(eloc.x - packet.getPosition().getX()) >= 0.03125D)
&& !(Math.abs(eloc.y - packet.getPosition().getY()) >= 0.015625D)
&& !(Math.abs(eloc.z - packet.getPosition().getZ()) >= 0.03125D)) {
eloc.increment = 0;
//We don't need to do version checking here. Atlas handles this for us.
eloc.newX = eloc.x = packet.getPosition().getX();
eloc.newY = eloc.y = packet.getPosition().getY();
eloc.newZ = eloc.z = packet.getPosition().getZ();
eloc.newYaw = eloc.yaw = packet.getYaw();
eloc.newPitch = eloc.pitch = packet.getPitch();
} else {
eloc.newX = packet.getPosition().getX();
eloc.newY = packet.getPosition().getY();
eloc.newZ = packet.getPosition().getZ();
eloc.newYaw = packet.getYaw();
eloc.newPitch = packet.getPitch();
eloc.increment = 3;
}
} else {
//We don't need to do version checking here. Atlas handles this for us.
eloc.newX = packet.getPosition().getX();
eloc.newY = packet.getPosition().getY();
eloc.newZ = packet.getPosition().getZ();
eloc.newYaw = packet.getYaw();
eloc.newPitch = packet.getPitch();
eloc.increment = 3;
}
});
}
void updateAttributes(WrapperPlayServerUpdateAttributes attributes) {
data.runKeepaliveAction(ka -> {
TrackedEntity tracked = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(attributes.getEntityId()).orElse(null);
if(tracked == null) return;
for (WrapperPlayServerUpdateAttributes.Property property : attributes.getProperties()) {
Attribute attribute = property.getAttribute();
if(attributes.getEntityId() == data.getBukkitPlayer().getEntityId() && attribute == Attributes.MOVEMENT_SPEED) {
ValuedAttribute value = tracked.getAttribute(attribute);
value.updateAttribute(property);
data.getInfo().setWalkSpeed(value.getValue());
}
tracked.updateAttribute(property);
}
});
}
/**
*
* We are running an action when a transaction is received. If the Entity provided is currently a target,
* we want to send a tranasction on this method being run and use that to more accurately get an estimate of when
* the client receives the transaction relative to what we want in the action. If not the target, then we use our
* transaction system which sends one transaction every tick, and then on return runs a list of Runnables which
* may be less accurate in some situations, but uses less processing and network resources.
*
* @param entity Entity
* @param action Runnable
*/
private void runAction(TrackedEntity entity, Runnable action) {
if(data.getInfo().getTarget() != null && data.getInfo().getTarget().getEntityId() == entity.getEntityId()) {
data.runInstantAction(ia -> {
if(!ia.isEnd()) {
action.run();
} else entity.setOldEntityLocation(null);
}, true);
} else {
data.runKeepaliveAction(keepalive -> action.run());
data.runKeepaliveAction(keepalive ->
entity.setOldEntityLocation(null), 1);
}
}
public void onEntityDestroy(WrapperPlayServerDestroyEntities packet) {
data.runKeepaliveAction(ka -> {
for(int id : packet.getEntityIds()) {
removeFakeMob(id);
}
});
}
public void removeFakeMob(int id) {
if(data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntities().containsKey(id)) {
List<FakeMob> mobs = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(id).map(TrackedEntity::getFakeMobs).orElse(new ArrayList<>());
for (FakeMob mob : mobs) {
mob.despawn();
}
mobs.clear();
}
clientHasEntity.set(false);
}
private static final double[] offsets = new double[]{-1.25, 0, 1.25};
private void createFakeMob(int entityId, KLocation location) {
if (!canCreateMob.contains(entityId)) return;
Optional<TrackedEntity> trackedEntity = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(entityId);
Optional<TrackedEntity> playerEntity = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(data.getBukkitPlayer().getEntityId());
if(trackedEntity.isEmpty() || playerEntity.isEmpty()) return;
for (double offset : offsets) {
FakeMob mob = new FakeMob(EntityTypes.MAGMA_CUBE);
List<EntityData<?>> types = new ArrayList<>();
EntityData<?> entityData = new EntityData<>(16, EntityDataTypes.BYTE, (byte)10);
types.add(entityData);
// Setting Magma cube size to size 10
mob.spawn(true, location.clone().add(offset, offset, offset),
types, data);
trackedEntity.get().getFakeMobs().add(mob);
}
KLocation eyeLoc = data.getMovement().getTo().getLoc().clone()
.add(0, data.getEyeHeight() / 2.5, 0);
RayCollision collision = new RayCollision(eyeLoc.toVector(), eyeLoc.getDirection());
Vector3d point = collision.collisionPoint(0.4);
FakeMob mob = new FakeMob(EntityTypes.SLIME);
List<EntityData<?>> types = new ArrayList<>();
EntityData<?> entityData = new EntityData<>(16, EntityDataTypes.BYTE, (byte)5);
types.add(entityData);
mob.spawn(true, new KLocation(point.getX(), point.getY(), point.getZ()), types, data);
playerEntity.get().getFakeMobs().add(mob);
canCreateMob.remove(entityId);
data.runKeepaliveAction(ka -> clientHasEntity.set(true));
}
public void processZombie() {
List<FakeMob> fakeMobs = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(data.getBukkitPlayer().getEntityId())
.map(TrackedEntity::getFakeMobs)
.orElse(new ArrayList<>());
if(fakeMobs.size() > 1) {
fakeMobs.forEach(fakeMob -> removeFakeMob(fakeMob.getEntityId()));
}
for (FakeMob fakeMob : fakeMobs) {
if(fakeMob.getType() == EntityTypes.SLIME) {
KLocation eyeLoc = data.getMovement().getTo().getLoc().clone().add(0, 0.6, 0);
RayCollision collision = new RayCollision(eyeLoc.toVector(), eyeLoc.getDirection());
Vector3d point = collision.collisionPoint(0.4);
fakeMob.teleport(point.getX(), point.getY(), point.getZ(), 0 ,0);
break;
}
}
}
public void processFakeMobs(int entityId, boolean rel, double x, double y, double z) {
List<FakeMob> fakeMobs = data.getWorldTracker().getCurrentWorld().get()
.getTrackedEntity(entityId).map(TrackedEntity::getFakeMobs).orElse(new ArrayList<>());
if(fakeMobs.isEmpty()) {
if(!rel) {
createFakeMob(entityId, new KLocation(x, y, z));
}
if(data.getInfo().getTarget() != null && data.getInfo().getTarget().getEntityId() == entityId) {
clientHasEntity.set(false);
}
return;
}
if(fakeMobs.size() != offsets.length + 1) {
fakeMobs.forEach(fakeMob -> removeFakeMob(fakeMob.getEntityId()));
}
int current = 0;
for (FakeMob fakeMob : fakeMobs) {
double offset = offsets[current++];
if(rel) {
fakeMob.move(x, y, z);
} else {
fakeMob.teleport(x + offset, y + offset, z + offset, 0, 0);
}
}
}
}
// NOTE (AI): onEntityDestroy is lines 240-246; removeFakeMob (248-261) does the actual cleanup. The keepalive deferral means removal lands only after the client acknowledges, matching the client's own despawn timing.
Decode the destroy payload across all protocol layouts and feed each entity id to the entity tracker.
EntityDestroyReader implements EntityIterable over the destroy packet. It branches on protocol era: an int list on 1.17.1+, a single int on 1.17.0, and an int array on 1.16 and below, exposing both forEach and a substitution iterator so the tracker can read or rewrite ids. PacketReaders registers it under ENTITY_DESTROY, and EntityTracker.receiveEntityDestroy processes each id, dismounting riders and marking destroyed entities so AttackRaytrace can ignore them.
// ===== FILE: intave-intave, src/main/java/de/jpx3/intave/packet/reader/EntityDestroyReader.java =====
package de.jpx3.intave.packet.reader;
import de.jpx3.intave.adapter.MinecraftVersions;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Consumer;
public final class EntityDestroyReader extends AbstractPacketReader implements EntityIterable {
private final boolean INT_LIST_ENTITY_DESTROY = MinecraftVersions.VER1_17_1.atOrAbove();
private final boolean SINGLE_INT_ENTITY_DESTROY = !INT_LIST_ENTITY_DESTROY && MinecraftVersions.VER1_17_0.atOrAbove();
private final boolean INT_ARRAY_ENTITY_DESTROY = !SINGLE_INT_ENTITY_DESTROY;
@Override
public void forEach(Consumer<? super Integer> action) {
if (INT_LIST_ENTITY_DESTROY) {
List<Integer> entityIds = packet().getIntLists().read(0);
entityIds.forEach(action);
} else if (INT_ARRAY_ENTITY_DESTROY) {
int[] entityIDs = packet().getIntegerArrays().read(0);
for (int entityID : entityIDs) {
action.accept(entityID);
}
} else {
action.accept(packet().getIntegers().read(0));
}
}
@NotNull
@Override
public SubstitutionIterator<Integer> iterator() {
if (INT_LIST_ENTITY_DESTROY) {
List<Integer> entityIDs = packet().getIntLists().read(0);
return new SubstitutionIterator<Integer>() {
int index = 0;
@Override
public void set(Integer integer) {
entityIDs.set(index - 1, integer);
}
@Override
public boolean hasNext() {
return index < entityIDs.size();
}
@Override
public Integer next() {
return entityIDs.get(index++);
}
};
} else if (INT_ARRAY_ENTITY_DESTROY) {
int[] entityIDs = packet().getIntegerArrays().read(0);
return new SubstitutionIterator<Integer>() {
int index = 0;
@Override
public void set(Integer integer) {
entityIDs[index - 1] = integer;
// packet().getIntegerArrays().write(0, entityIDs);
}
@Override
public boolean hasNext() {
return index < entityIDs.length;
}
@Override
public Integer next() {
return entityIDs[index++];
}
};
} else {
int id = packet().getIntegers().read(0);
return new SubstitutionIterator<Integer>() {
@Override
public void set(Integer integer) {
packet().getIntegers().write(0, integer);
}
boolean hasNext = true;
@Override
public boolean hasNext() {
return hasNext;
}
@Override
public Integer next() {
hasNext = false;
return id;
}
};
}
}
}
// NOTE (AI): The layout branch (lines 10-27) shows the 1.17 protocol split: int list, single int, then the legacy int array. The substitution iterator lets the anticheat rewrite ids in place, used by the EntityIdFilter module.
Remove destroyed entities from the tracked-entity map so reach and entity queries never see despawned ids.
EntityTracker.registerOutgoingPreHandler routes DESTROY_ENTITIES to handleDestroyEntities, which wraps WrapperPlayServerDestroyEntities and removes each id from the concurrent entityMap. Because insertion happens on spawn and removal on destroy, the map always mirrors the client's visible entity set; getDistanceToEntity and getClosestEntity simply cannot return a destroyed entity.
// ===== FILE: Incognitolol-Hydro, src/main/java/integral/studios/hydro/model/tracker/impl/EntityTracker.java =====
package integral.studios.hydro.model.tracker.impl;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import integral.studios.hydro.model.PlayerData;
import integral.studios.hydro.model.tracker.Tracker;
import integral.studios.hydro.util.player.tracker.entity.TrackedEntity;
import integral.studios.hydro.util.packet.PacketUtil;
import lombok.Getter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Getter
public class EntityTracker extends Tracker {
// Thread-safe entity storage
private final Map<Integer, TrackedEntity> entityMap = new ConcurrentHashMap<>();
public EntityTracker(PlayerData playerData) {
super(playerData);
}
@Override
public void registerOutgoingPreHandler(PacketSendEvent event) {
if (event.getPacketType() == PacketType.Play.Server.SPAWN_LIVING_ENTITY) {
handleSpawnLivingEntity(event);
} else if (event.getPacketType() == PacketType.Play.Server.SPAWN_PLAYER) {
handleSpawnPlayer(event);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_RELATIVE_MOVE) {
handleEntityRelativeMove(event);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_RELATIVE_MOVE_AND_ROTATION) {
handleEntityRelativeMoveAndRotation(event);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_TELEPORT) {
handleEntityTeleport(event);
} else if (event.getPacketType() == PacketType.Play.Server.DESTROY_ENTITIES) {
handleDestroyEntities(event);
}
}
@Override
public void registerIncomingPostHandler(PacketReceiveEvent event) {
if (PacketUtil.isFlying(event.getPacketType())) {
handleFlyingPacket();
}
}
private void handleSpawnLivingEntity(PacketSendEvent event) {
WrapperPlayServerSpawnLivingEntity wrapper = new WrapperPlayServerSpawnLivingEntity(event);
Vector3d position = wrapper.getPosition();
int entityId = wrapper.getEntityId();
TrackedEntity entity = new TrackedEntity(entityId, position.x, position.y, position.z);
entityMap.put(entityId, entity);
}
private void handleSpawnPlayer(PacketSendEvent event) {
WrapperPlayServerSpawnPlayer wrapper = new WrapperPlayServerSpawnPlayer(event);
Vector3d position = wrapper.getPosition();
int entityId = wrapper.getEntityId();
TrackedEntity entity = new TrackedEntity(entityId, position.x, position.y, position.z);
entityMap.put(entityId, entity);
}
private void handleEntityRelativeMove(PacketSendEvent event) {
WrapperPlayServerEntityRelativeMove wrapper = new WrapperPlayServerEntityRelativeMove(event);
TrackedEntity entity = entityMap.get(wrapper.getEntityId());
if (entity == null) {
return;
}
playerData.getTransactionTracker().confirmPre(() -> {
entity.handleMovement(wrapper.getDeltaX(), wrapper.getDeltaY(), wrapper.getDeltaZ());
});
playerData.getTransactionTracker().confirmPost(this::updateAllEntitiesPostTransaction);
}
private void handleEntityRelativeMoveAndRotation(PacketSendEvent event) {
WrapperPlayServerEntityRelativeMoveAndRotation wrapper = new WrapperPlayServerEntityRelativeMoveAndRotation(event);
TrackedEntity entity = entityMap.get(wrapper.getEntityId());
if (entity == null) {
return;
}
playerData.getTransactionTracker().confirmPre(() -> {
entity.handleMovement(wrapper.getDeltaX(), wrapper.getDeltaY(), wrapper.getDeltaZ());
});
playerData.getTransactionTracker().confirmPost(this::updateAllEntitiesPostTransaction);
}
private void handleEntityTeleport(PacketSendEvent event) {
WrapperPlayServerEntityTeleport wrapper = new WrapperPlayServerEntityTeleport(event);
TrackedEntity entity = entityMap.get(wrapper.getEntityId());
if (entity == null) {
return;
}
Vector3d position = wrapper.getPosition();
playerData.getTransactionTracker().confirmPre(() -> {
entity.handleTeleport(position.x, position.y, position.z);
});
playerData.getTransactionTracker().confirmPost(this::updateAllEntitiesPostTransaction);
}
private void handleDestroyEntities(PacketSendEvent event) {
WrapperPlayServerDestroyEntities wrapper = new WrapperPlayServerDestroyEntities(event);
for (int entityId : wrapper.getEntityIds()) {
entityMap.remove(entityId);
}
}
private void handleFlyingPacket() {
entityMap.values().forEach(TrackedEntity::handlePostFlying);
}
private void updateAllEntitiesPostTransaction() {
entityMap.values().forEach(TrackedEntity::handlePostTransaction);
}
public TrackedEntity get(int entityId) {
return entityMap.get(entityId);
}
public boolean isTracking(int entityId) {
return entityMap.containsKey(entityId);
}
public int getTrackedEntityCount() {
return entityMap.size();
}
public TrackedEntity removeEntity(int entityId) {
return entityMap.remove(entityId);
}
public void clearEntities() {
entityMap.clear();
}
public double getDistanceToEntity(int entityId) {
TrackedEntity entity = entityMap.get(entityId);
if (entity == null) {
return -1;
}
double dx = entity.getX() - playerData.getPositionTracker().getX();
double dy = entity.getY() - playerData.getPositionTracker().getY();
double dz = entity.getZ() - playerData.getPositionTracker().getZ();
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
public TrackedEntity getClosestEntity() {
TrackedEntity closest = null;
double minDistance = Double.MAX_VALUE;
for (Map.Entry<Integer, TrackedEntity> entry : entityMap.entrySet()) {
TrackedEntity entity = entry.getValue();
double distance = getDistanceToEntity(entry.getKey());
if (distance >= 0 && distance < minDistance) {
minDistance = distance;
closest = entity;
}
}
return closest;
}
public Map<Integer, TrackedEntity> getEntitiesWithinDistance(double maxDistance) {
Map<Integer, TrackedEntity> nearbyEntities = new ConcurrentHashMap<>();
for (Map.Entry<Integer, TrackedEntity> entry : entityMap.entrySet()) {
double distance = getDistanceToEntity(entry.getKey());
if (distance >= 0 && distance <= maxDistance) {
nearbyEntities.put(entry.getKey(), entry.getValue());
}
}
return nearbyEntities;
}
public int getEntityId(TrackedEntity entity) {
if (entity == null) return -1;
for (Map.Entry<Integer, TrackedEntity> entry : entityMap.entrySet()) {
if (entry.getValue() == entity) {
return entry.getKey();
}
}
return -1;
}
}
// NOTE (AI): handleDestroyEntities is lines 116-122, directly after the spawn handlers in the same dispatch, which is why the S0C, S0F and S13 corpora all reference this one file.
Related Packets
Wiki Cross-Reference
VarInt count followed by that many VarInt entity ids; server flushes the destroy list once per tick.
Id-keyed caches must prune on it; delaying it keeps ghost entities attackable, the attack-after-destroy flag pattern.
MCP 1.8.9 S13PacketDestroyEntities implements Packet
1.8.9 callers: EntityPlayerMP.onUpdate sends new S13PacketDestroyEntities (line 303): https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java
Cross-checked against minecraft.wiki (CC BY-SA 3.0) for 1.8.9 accuracy.
Vanilla Internals
Full 1.8.9 logic-class sources that send or handle this packet, stored verbatim.
Module Analyses Using S13PacketDestroyEntities
Full source walkthroughs of the modules and anti-cheats that use this packet.