Skip to content

Commit

Permalink
Fix packets for 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Elikill58 committed Jul 26, 2024
1 parent 2c060b4 commit 57a770d
Show file tree
Hide file tree
Showing 8 changed files with 39,569 additions and 26 deletions.
39,410 changes: 39,410 additions & 0 deletions common/resources/versions/v1_20_6/blocks.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ enum Server implements PacketType {
CHUNK_BIOMES,
CUSTOM_PAYLOAD(NPacketPlayOutCustomPayload::new),
CUSTOM_SOUND_EFFECT,
CUSTOM_REPORT_DETAILS,
DAMAGE_EVENT,
DEBUG_SAMPLE,
ENTITY,
Expand Down Expand Up @@ -373,6 +374,7 @@ enum Server implements PacketType {
SCOREBOARD_TEAM,
SERVER_DATA,
SERVER_DIFFICULTY,
SERVER_LINKS,
SELECT_ADVANCEMENT_TAB,
SET_DISPLAY_CHAT_PREVIEW,
SET_COMPRESSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import com.elikill58.negativity.api.packets.PacketType.Server;
import com.elikill58.negativity.api.packets.nms.NamedVersion;

public class Version1_20_5 extends NamedVersion {
public class Version1_20_6 extends NamedVersion {

public Version1_20_5() {
public Version1_20_6() {
super("1.20.5");
// packets ID seems not same as 1.20
int i = 0;
Expand Down Expand Up @@ -93,7 +93,7 @@ public Version1_20_5() {
EntityType.ZOMBIE_VILLAGER, EntityType.PIG_ZOMBIE, EntityType.PLAYER, EntityType.FISHING_HOOK)) {
entityTypes.put(i++, types);
}
loadPostFlattening("/versions/v1_19_3/");
loadPostFlattening("/versions/v1_20_6/");

log();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.elikill58.negativity.api.packets.nms.versions;

import java.util.Arrays;

import com.elikill58.negativity.api.entity.EntityType;
import com.elikill58.negativity.api.packets.PacketType.Client;
import com.elikill58.negativity.api.packets.PacketType.Server;
import com.elikill58.negativity.api.packets.nms.NamedVersion;

public class Version1_21 extends NamedVersion {

public Version1_21() {
super("1.20.5");
// packets ID seems not same as 1.20
int i = 0;
for (Client type : Arrays.asList(Client.TELEPORT_ACCEPT, Client.TILE_NBT_QUERY, Client.DIFFICULTY_CHANGE,
Client.CHAT_ACK, Client.CHAT_COMMAND, Client.CHAT_COMMAND_SIGNED, Client.CHAT,
Client.CHAT_SESSION_UPDATE, Client.CHUNK_BATCH_RECEIVED, Client.CLIENT_COMMAND, Client.SETTINGS,
Client.TAB_COMPLETE, Client.CONFIGURATION_ACKNOWLEDGED, Client.ENCHANT_ITEM, Client.WINDOW_CLICK,
Client.CLOSE_WINDOW, Client.SLOT_STATE_CHANGE, Client.COOKIE_RESPONSE, Client.CUSTOM_PAYLOAD,
Client.DEBUG_SAMPLE_SUBSCRIPTION, Client.BEDIT, Client.ENTITY_NBT_QUERY, Client.USE_ENTITY,
Client.JIGSAW_GENERATE, Client.KEEP_ALIVE, Client.DIFFICULTY_LOCK, Client.POSITION,
Client.POSITION_LOOK, Client.LOOK, Client.GROUND, Client.VEHICLE_MOVE, Client.BOAT_MOVE,
Client.PICK_ITEM, Client.PING, Client.AUTO_RECIPE, Client.ABILITIES, Client.BLOCK_DIG,
Client.ENTITY_ACTION, Client.STEER_VEHICLE, Client.PONG, Client.RECIPE_SETTINGS,
Client.RECIPE_DISPLAYED, Client.ITEM_NAME, Client.RESOURCE_PACK_STATUS, Client.ADVANCEMENTS,
Client.TR_SEL, Client.BEACON, Client.HELD_ITEM_SLOT, Client.SET_COMMAND_BLOCK,
Client.SET_COMMAND_MINECART, Client.SET_CREATIVE_SLOT, Client.SET_JIGSAW, Client.STRUCT,
Client.UPDATE_SIGN, Client.ARM_ANIMATION, Client.SPECTATE, Client.USE_ITEM, Client.BLOCK_PLACE)) {
playIn.put(i++, type);
}
i = 0;
for (Server type : Arrays.asList(Server.BUNDLE, Server.SPAWN_ENTITY, Server.SPAWN_ENTITY_EXPERIENCE_ORB,
Server.ANIMATION, Server.STATISTIC, Server.BLOCK_CHANGED_ACK, Server.BLOCK_BREAK_ANIMATION,
Server.TILE_ENTITY_DATA, Server.BLOCK_ACTION, Server.BLOCK_CHANGE, Server.BOSS,
Server.SERVER_DIFFICULTY, Server.CHUNK_BATCH_FINISHED, Server.CHUNK_BATCH_STARTED, Server.CHUNK_BIOMES,
Server.CLEAR_TITLE, Server.TAB_COMPLETE, Server.COMMANDS, Server.CLOSE_WINDOW, Server.WINDOW_ITEMS,
Server.WINDOW_DATA, Server.SET_SLOT, Server.COOKIE_REQUEST, Server.SET_COOLDOWN,
Server.CHAT_CUSTOM_COMPLETION, Server.CUSTOM_PAYLOAD, Server.DAMAGE_EVENT, Server.DEBUG_SAMPLE,
Server.CHAT_DELETE, Server.KICK_DISCONNECT, Server.CHAT_DISGUISED, Server.ENTITY_STATUS,
Server.EXPLOSION, Server.UNLOAD_CHUNK, Server.GAME_STATE_CHANGE, Server.OPEN_WINDOW_HORSE,
Server.HURT_ANIMATION, Server.INITIALIZE_BORDER, Server.KEEP_ALIVE, Server.LEVEL_CHUNK_LIGHT,
Server.WORLD_EVENT, Server.WORLD_PARTICLES, Server.LIGHT_UPDATE, Server.LOGIN, Server.MAP,
Server.OPEN_WINDOW_MERCHANT, Server.REL_ENTITY_MOVE, Server.REL_ENTITY_MOVE_LOOK,
Server.REL_ENTITY_LOOK, Server.VEHICLE_MOVE, Server.OPEN_BOOK, Server.OPEN_WINDOW,
Server.OPEN_SIGN_EDITOR, Server.PING, Server.PONG, Server.AUTO_RECIPE, Server.ABILITIES, Server.CHAT,
Server.COMBAT_END_EVENT, Server.COMBAT_ENTER_EVENT, Server.COMBAT_KILL_EVENT, Server.PLAYER_INFO_REMOVE,
Server.PLAYER_INFO_UPDATE, Server.LOOK_AT, Server.POSITION, Server.RECIPES, Server.ENTITY_DESTROY,
Server.REMOVE_ENTITY_EFFECT, Server.SCOREBOARD_RESET, Server.RESOURCE_PACK_POP,
Server.RESOURCE_PACK_SEND, Server.RESPAWN, Server.ENTITY_HEAD_ROTATION, Server.MULTI_BLOCK_CHANGE,
Server.SELECT_ADVANCEMENT_TAB, Server.SERVER_DATA, Server.SET_ACTION_BAR_TEXT, Server.SET_BORDER_CENTER,
Server.SET_BORDER_LERP_SIZE, Server.SET_BORDER_SIZE, Server.SET_BORDER_WARNING_DELAY,
Server.SET_BORDER_WARNING_DISTANCE, Server.CAMERA, Server.HELD_ITEM_SLOT, Server.VIEW_CENTRE,
Server.VIEW_DISTANCE, Server.SPAWN_POSITION, Server.SCOREBOARD_DISPLAY_OBJECTIVE,
Server.ENTITY_METADATA, Server.ATTACH_ENTITY, Server.ENTITY_VELOCITY, Server.ENTITY_EQUIPMENT,
Server.EXPERIENCE, Server.UPDATE_HEALTH, Server.SCOREBOARD_OBJECTIVE, Server.MOUNT,
Server.SCOREBOARD_TEAM, Server.SCOREBOARD_SCORE, Server.SIMULATION_DISTANCE, Server.SET_SUBTITLE_TEXT,
Server.UPDATE_TIME, Server.SET_TITLE_TEXT, Server.SET_TITLE_ANIMATION, Server.ENTITY_SOUND,
Server.NAMED_SOUND_EFFECT, Server.START_CONFIGURATION, Server.STOP_SOUND, Server.COOKIE_STORE,
Server.SYSTEM_CHAT, Server.PLAYER_LIST_HEADER_FOOTER, Server.NBT_QUERY, Server.COLLECT,
Server.ENTITY_TELEPORT, Server.TICKING_STATE, Server.TICKING_STEP, Server.TRANSFERT,
Server.ADVANCEMENTS, Server.UPDATE_ATTRIBUTES, Server.ENTITY_EFFECT, Server.RECIPE_UPDATE, Server.TAGS,
Server.PROJECTILE_POWER, Server.CUSTOM_REPORT_DETAILS, Server.SERVER_LINKS)) {
playOut.put(i++, type);
}
i = 0;
for (EntityType types : Arrays.asList(EntityType.ALLAY, EntityType.AREA_EFFECT_CLOUD, EntityType.ARMOR_STAND,
EntityType.ARROW, EntityType.AXOLOTL, EntityType.BAT, EntityType.BEE, EntityType.BLAZE, EntityType.BOAT,
EntityType.CHEST_BOAT, EntityType.CAT, EntityType.CAVE_SPIDER, EntityType.CHICKEN, EntityType.COD,
EntityType.COW, EntityType.CREEPER, EntityType.DOLPHIN, EntityType.DONKEY, EntityType.DRAGON_FIREBALL,
EntityType.DROWNED, EntityType.ELDER_GUARDIAN, EntityType.ENDER_CRYSTAL, EntityType.ENDER_DRAGON,
EntityType.ENDERMAN, EntityType.ENDERMITE, EntityType.EVOKER, EntityType.EVOKER_FANGS,
EntityType.EXPERIENCE_ORB, EntityType.EYE_OF_ENDER, EntityType.FALLING_BLOCK, EntityType.FIREWORK,
EntityType.FOX, EntityType.FROG, EntityType.GHAST, EntityType.GIANT, EntityType.GLOW_ITEM_FRAME,
EntityType.GLOW_SQUID, EntityType.GOAT, EntityType.GUARDIAN, EntityType.HOGLIN, EntityType.HORSE,
EntityType.HUSK, EntityType.ILLUSIONER, EntityType.IRON_GOLEM, EntityType.DROPPED_ITEM,
EntityType.ITEM_FRAME, EntityType.FIREBALL, EntityType.LEASH_KNOT, EntityType.LIGHTNING,
EntityType.LLAMA, EntityType.LLAMA_SPIT, EntityType.MAGMA_CUBE, EntityType.MARKER, EntityType.MINECART,
EntityType.MINECART_CHEST, EntityType.MINECART_COMMAND_BLOCK, EntityType.MINECART_FURNACE,
EntityType.MINECART_HOPPER, EntityType.MINECART_MOB_SPAWNER, EntityType.MINECART_TNT, EntityType.MULE,
EntityType.MOOSHROOM, EntityType.OCELOT, EntityType.PAINTING, EntityType.PANDA, EntityType.PARROT,
EntityType.PHANTOM, EntityType.PIG, EntityType.PIGLIN, EntityType.PIGLIN_BRUTE, EntityType.PILLAGER,
EntityType.POLAR_BEAR, EntityType.PRIMED_TNT, EntityType.PUFFER_FISH, EntityType.RABBIT,
EntityType.RAVAGER, EntityType.SALMON, EntityType.SHEEP, EntityType.SHULKER, EntityType.SHULKER_BULLET,
EntityType.SILVERFISH, EntityType.SKELETON, EntityType.SKELETON_HORSE, EntityType.SLIME,
EntityType.SMALL_FIREBALL, EntityType.SNOW_GOLEM, EntityType.SNOW_BALL, EntityType.SPECTRAL_ARROW,
EntityType.SPIDER, EntityType.SQUID, EntityType.STRAY, EntityType.STRIDER, EntityType.TADPOLE,
EntityType.EGG, EntityType.ENDER_PEARL, EntityType.EXP_BOTTLE, EntityType.SPLASH_POTION,
EntityType.TRIDENT, EntityType.LLAMA_TRADER, EntityType.TROPICAL_FISH, EntityType.TURTLE,
EntityType.VEX, EntityType.VILLAGER, EntityType.VINDICATOR, EntityType.WANDERING_TRADER,
EntityType.WARDEN, EntityType.WITCH, EntityType.WITHER, EntityType.WITHER_SKELETON,
EntityType.WITHER_SKULL, EntityType.WOLF, EntityType.ZOGLIN, EntityType.ZOMBIE,
EntityType.ZOMBIE_VILLAGER, EntityType.PIG_ZOMBIE, EntityType.PLAYER, EntityType.FISHING_HOOK)) {
entityTypes.put(i++, types);
}
loadPostFlattening("/versions/v1_20_6/");

log();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,60 @@
public class NPacketPlayInBlockPlace implements NPacketPlayIn, LocatedPacket {

public Hand hand = Hand.MAIN;
/**
* This is no longer present since 1.21
*/
public BlockFace face;
/**
* This is no longer present since 1.21
*/
public BlockPosition pos;
/**
* This is no longer present since 1.21
*/
public boolean insideBlock;
/**
* This is no longer present since 1.21
*/
public float cursorX, cursorY, cursorZ;
public float yaw, pitch;

public NPacketPlayInBlockPlace() {

}

@Override
public void read(PacketSerializer serializer, Version version) {
if (version.isNewerOrEquals(Version.V1_14))
if (version.isNewerOrEquals(Version.V1_21)) {
this.hand = serializer.getEnum(Hand.class);
this.pos = serializer.readBlockPosition(version);
this.face = BlockFace.getById(serializer.readUnsignedByte());
if (version.isNewerOrEquals(Version.V1_9) && !version.isNewerOrEquals(Version.V1_14)) // between 1.9 to 1.13
this.hand = serializer.getEnum(Hand.class);
if (version.equals(Version.V1_8)) {
serializer.readItemStack(version); // skip item index
this.cursorX = serializer.readUnsignedByte() / 16.0F;
this.cursorY = serializer.readUnsignedByte() / 16.0F;
this.cursorZ = serializer.readUnsignedByte() / 16.0F;
serializer.readVarInt(); // sequence
this.yaw = serializer.readFloat();
this.pitch = serializer.readFloat();
} else {
this.cursorX = serializer.readFloat();
this.cursorY = serializer.readFloat();
this.cursorZ = serializer.readFloat();
if (version.isNewerOrEquals(Version.V1_14))
this.hand = serializer.getEnum(Hand.class);
this.pos = serializer.readBlockPosition(version);
this.face = BlockFace.getById(serializer.readUnsignedByte());
if (version.isNewerOrEquals(Version.V1_9) && !version.isNewerOrEquals(Version.V1_14)) // between 1.9 to 1.13
this.hand = serializer.getEnum(Hand.class);
if (version.equals(Version.V1_8)) {
serializer.readItemStack(version); // skip item index
this.cursorX = serializer.readUnsignedByte() / 16.0F;
this.cursorY = serializer.readUnsignedByte() / 16.0F;
this.cursorZ = serializer.readUnsignedByte() / 16.0F;
} else {
this.cursorX = serializer.readFloat();
this.cursorY = serializer.readFloat();
this.cursorZ = serializer.readFloat();
}
if (version.isNewerOrEquals(Version.V1_13))
this.insideBlock = serializer.readBoolean();
}
if (version.isNewerOrEquals(Version.V1_13))
this.insideBlock = serializer.readBoolean();
}

@Override
public boolean hasLocation() {
return pos != null && LocatedPacket.super.hasLocation();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public void onPacket(PacketPreReceiveEvent e) {
if (pa.getPacketType().equals(PacketType.Client.BLOCK_PLACE)) {
Player p = e.getPlayer();
NPacketPlayInBlockPlace packet = (NPacketPlayInBlockPlace) pa;
if(!packet.hasLocation())
return;
int amount = 0;
for(float f : Arrays.asList(packet.cursorX, packet.cursorY, packet.cursorZ)) {
if(f > 1.5) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ public void handlePacketReceived(PacketReceiveEvent e) {
lastFlying = flying;
} else if(pa.getPacketType().equals(PacketType.Client.BLOCK_PLACE)) {
NPacketPlayInBlockPlace place = (NPacketPlayInBlockPlace) pa;
Location loc = p.getLocation();
if(place.getBlockX() == loc.getBlockX() && place.getBlockY() == loc.getBlockY() - 1 && place.getBlockZ() == loc.getBlockZ()) {
if(amountInvalid > 40 && speed >= p.getWalkSpeed()) // if lot of invalid changes and go fast
Negativity.alertMod(ReportType.WARNING, p, c, UniversalUtils.parseInPorcent(amountInvalid), "rise-slot", proofs.toString(), new CheatHover.Literal("Pitch: " + lastFlying.pitch), amount);
else
Adapter.getAdapter().debug(Debug.CHECK, "Amount invalid: " + amountInvalid);
if(place.hasLocation()) {
Location loc = p.getLocation();
if(place.getBlockX() == loc.getBlockX() && place.getBlockY() == loc.getBlockY() - 1 && place.getBlockZ() == loc.getBlockZ()) {
if(amountInvalid > 40 && speed >= p.getWalkSpeed()) // if lot of invalid changes and go fast
Negativity.alertMod(ReportType.WARNING, p, c, UniversalUtils.parseInPorcent(amountInvalid), "rise-slot", proofs.toString(), new CheatHover.Literal("Pitch: " + lastFlying.pitch), amount);
else
Adapter.getAdapter().debug(Debug.CHECK, "Amount invalid: " + amountInvalid);
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions common/src/com/elikill58/negativity/universal/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.elikill58.negativity.api.packets.nms.versions.Version1_20;
import com.elikill58.negativity.api.packets.nms.versions.Version1_20_2;
import com.elikill58.negativity.api.packets.nms.versions.Version1_20_4;
import com.elikill58.negativity.api.packets.nms.versions.Version1_20_5;
import com.elikill58.negativity.api.packets.nms.versions.Version1_20_6;
import com.elikill58.negativity.api.packets.nms.versions.Version1_21;
import com.elikill58.negativity.api.packets.nms.versions.Version1_8;
import com.elikill58.negativity.api.packets.nms.versions.Version1_9;
import com.elikill58.negativity.api.packets.nms.versions.VersionUnknown;
Expand Down Expand Up @@ -50,7 +51,8 @@ public enum Version {
V1_20("1.20", 20, Version1_20::new, 763),
V1_20_2("1.20.2", 20.2, Version1_20_2::new, 764),
V1_20_4("1.20.4", 20.4, Version1_20_4::new, 765),
V1_20_5("1.20.5", 20.5, Version1_20_5::new, 766, 999),
V1_20_6("1.20.6", 20.5, Version1_20_6::new, 766),
V1_21("1.21", 21, Version1_21::new, 767, 999),
HIGHER("higher", 42, VersionUnknown::new, 1000);

private final double power;
Expand Down

0 comments on commit 57a770d

Please sign in to comment.