0x23 S23PacketBlockChange
Updates a single block in the world: position and new block state (combined ID+metadata).
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| position | BlockPos | Block position |
| blockState | IBlockState | New block state (blockId | (metadata << 12)) |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Position | BlockPos (long) | Encoded as long |
| Block ID + Meta | VarInt | Block ID | (metadata << 12) |
MCP References
NetHandlerPlayClient.handleBlockChange()Handler Interface
INetHandlerPlayClientVanilla 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 | |
| 60 | |
| 61 | |
| 62 | |
Deobfuscated MCP 1.8.9 source of S23PacketBlockChange, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/server/S23PacketBlockChange.java) at build time and verified present.
Deep Dive
Role in the protocol
S23 is the server's single-block state correction. The server sends it whenever one block in a loaded chunk changes and the change is cheap to express, with the alternative S21PacketChunkData / S22PacketMultiBlockChange reserved for bulk edits. The block state is encoded as a VarInt into the Block.BLOCK_STATE_IDS registry, not as the old blockId | (meta << 12) split; every block in 1.8.9 has a unique registry ID. NetHandlerPlayServer pushes it from the block-breaking path (line 481), the block-placement path (line 535), ItemInWorldManager.tryHarvestBlock (line 254) and PlayerManager's chunk watcher broadcast (line 436).
Vanilla handling
NetHandlerPlayClient.handleBlockChange calls PacketThreadUtil.func_180031_a for main-thread dispatch, then clientWorldController.func_180503_b(pos, state), which is WorldClient.setBlockState: it replaces the local block, updates the lightmap, and re-renders the region. That is the entire effect; there is no server round trip. Because the handler writes straight into the world, any module that reads world state after the event bus gets the correction for free, which is why so few clients intercept S23 directly.
Why clients touch it
Only one module in the 8-client corpus references S23PacketBlockChange: Rise 6.2.4's WatchdogJumpSprint, a Scaffold sprint mode. It treats every S23 as proof the server accepted a placed block: the PacketReceiveEvent handler sets start3 = true and increments a block counter, and the pre-motion handler then uses start3 to fire a spoofed C08PacketPlayerBlockPlacement with an ice ItemStack against the player's own position (line 116), which is the Watchdog anti-cheat block-placement trigger used to keep the player's on-ground state consistent while sprint-jumping. The counter also feeds previousBlockValue / previousTick logic that paces how often the exploit packet is sent.
Exploit surface
S23 is clientbound and carries no player identity, so there is nothing to spoof server-side; the abuse is entirely on the receiving end. Ghost-block clients that locally predict block state must reconcile against S23 when the server disagrees, and scaffold / nuker modules can use the arrival timing of S23 as a cheap ping-free ack. Anti-cheats watch the reverse direction: they validate that a C08PacketPlayerBlockPlacement is followed by a matching S23 echo and check the placed block against the client's claimed reach, which is exactly the surface WatchdogJumpSprint's ice-placement trick plays on.
Server-Side Handling
NetHandlerPlayServer sends S23 on block break (processPlayerDigging, ~line 481), on placement and its neighbor update (~line 535), plus a second packet for the offset block when the placed block has a block-on-use neighbor. ItemInWorldManager sends it after a successful harvest, and PlayerManager.sendToAllPlayersWatchingChunk broadcasts to every player with the chunk loaded. In 1.8.9 there is no server-side validation of the client's C08 beyond reach and interval checks in the digging/placement handlers.
Protocol Analysis
Wire format: BlockPos as a packed long (readBlockPos) followed by a VarInt block state registry ID. The state is resolved at construction time from the world, so the server always sends what it believes is current, and a stale S23 can overwrite a newer client-side prediction. In PLAY state only. Frequency is bounded by player block interactions, which is what makes it a usable ack channel.
Anti-Cheat Landscape
S23 itself is never flagged; it is server-originated truth. Anti-cheats use it to detect ghost blocks and reach abuse: a placed block whose S23 echo position lies outside the client's valid reach, or a C08 that gets no echo, feeds reach and scaffold checks. Clients that spoof block placement need the echo to keep their internal state honest, and the timing between C08 and S23 is a latency signal that modules like WatchdogJumpSprint fold into their pacing.
implementation Implementation Cases
The server's authoritative one-block correction. In this corpus it is used by exactly one module, Rise 6.2.4's WatchdogJumpSprint, which reads S23 arrivals as placement acknowledgements to pace a Watchdog-targeted ice-block C08 exploit. Everything else in the 8 clients lets the vanilla handler write the state into WorldClient and reads the world afterwards.
Use S23 block-change arrivals as placement acks to pace a Watchdog-targeted ice-block placement exploit inside Scaffold.
A PacketReceiveEvent listener checks for S23PacketBlockChange, sets start3 = true and increments the block counter. The PreMotionEvent handler then uses start3 to send a spoofed C08PacketPlayerBlockPlacement aimed at the player's own position with an ice ItemStack and randomized hit vectors, one-shotting start3 per ack so the exploit packet only fires after the server confirms a placement.
// ===== FILE: Rise 6.2.4, Client-release2/Client/src/main/java/com/alan/clients/module/impl/player/scaffold/sprint/WatchdogJumpSprint.java =====
package com.alan.clients.module.impl.player.scaffold.sprint;
import com.alan.clients.Client;
import com.alan.clients.component.impl.player.BadPacketsComponent;
import com.alan.clients.component.impl.player.PingSpoofComponent;
import com.alan.clients.component.impl.player.RotationComponent;
import com.alan.clients.component.impl.player.Slot;
import com.alan.clients.component.impl.player.rotationcomponent.MovementFix;
import com.alan.clients.event.Listener;
import com.alan.clients.event.Priorities;
import com.alan.clients.event.annotations.EventLink;
import com.alan.clients.event.impl.motion.PreMotionEvent;
import com.alan.clients.event.impl.motion.PreUpdateEvent;
import com.alan.clients.event.impl.motion.StrafeEvent;
import com.alan.clients.event.impl.packet.PacketReceiveEvent;
import com.alan.clients.event.impl.packet.PacketSendEvent;
import com.alan.clients.module.impl.movement.Flight;
import com.alan.clients.module.impl.movement.LongJump;
import com.alan.clients.module.impl.movement.Speed;
import com.alan.clients.module.impl.player.Scaffold;
import com.alan.clients.module.impl.player.scaffold.tower.WatchdogTower;
import com.alan.clients.util.chat.ChatUtil;
import com.alan.clients.util.packet.PacketUtil;
import com.alan.clients.util.player.MoveUtil;
import com.alan.clients.util.player.PlayerUtil;
import com.alan.clients.util.player.SlotUtil;
import com.alan.clients.util.vector.Vector2f;
import com.alan.clients.value.Mode;
import com.alan.clients.value.impl.BooleanValue;
import net.minecraft.block.BlockAir;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.network.play.client.C0BPacketEntityAction;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.potion.Potion;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Vec3i;
import java.util.Objects;
import java.util.Random;
public class WatchdogJumpSprint extends Mode<Scaffold> {
public WatchdogJumpSprint(String name, Scaffold parent) {
super(name, parent);
}
int previousBlockValue = -1;
private boolean jump = false;
private boolean jumpHandled = false;
int previousTick = -1;
int ongroundticks;
int time;
double speed;
public Vec3i offset = new Vec3i(0, 0, 0);
public static boolean hasC08Packet = false;
public static boolean start2 = false;
public static boolean start3 = false;
public static boolean start4 = false;
int startTriggerCount = 0;
private int block;
public final BooleanValue extraBlocks = new BooleanValue("Place Extra blocks", this, false);
@EventLink(value = Priorities.HIGH)
public final Listener<PreMotionEvent> onPreMotionEvent = event -> {
if(event.isOnGround()){
ongroundticks++;
} else{
ongroundticks = 0;
}
getParent().recursions = 1;
if (mc.thePlayer.onGroundTicks > 2 && !mc.gameSettings.keyBindJump.isKeyDown() && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled() && !mc.thePlayer.isPotionActive(Potion.moveSpeed)) {
MoveUtil.strafe();
mc.thePlayer.motionZ *= 1.129;
mc.thePlayer.motionX *= 1.129;
} else if (mc.thePlayer.onGroundTicks > 2 && !mc.gameSettings.keyBindJump.isKeyDown() && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled() && mc.thePlayer.isPotionActive(Potion.moveSpeed) && mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).amplifier + 1 >= 2) {
MoveUtil.strafe();
mc.thePlayer.motionZ *= 1.143;
mc.thePlayer.motionX *= 1.143;
} else if (mc.thePlayer.onGroundTicks > 2 && !mc.gameSettings.keyBindJump.isKeyDown() && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled() && mc.thePlayer.isPotionActive(Potion.moveSpeed) && mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).amplifier + 1 == 1) {
MoveUtil.strafe();
mc.thePlayer.motionZ *= 1.131;
mc.thePlayer.motionX *= 1.131;
}
if(Math.abs(mc.thePlayer.motionY) < 0.1 && mc.thePlayer.offGroundTicks<2){
// mc.thePlayer.onGround = true;
}
// ChatUtil.display(mc.thePlayer.motionY);
if (mc.gameSettings.keyBindSneak.isKeyDown()) {
return;
}
int currentTick = mc.thePlayer.ticksExisted;
int currentBlockValue = block;
if ( !getModule(Flight.class).isEnabled() && !getModule(LongJump.class).isEnabled()) {
if (!BadPacketsComponent.bad(true, true, false, true, false) && Math.random()>0.5 && start3 && MoveUtil.isMoving()) {
//ChatUtil.display("ice on my wrist");
Random random = new Random();
float hitX = random.nextFloat();
float hitZ = random.nextFloat();
PacketUtil.send(new C08PacketPlayerBlockPlacement(
new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ),
EnumFacing.UP.getIndex(),
new ItemStack(Blocks.ice),
hitX,
1.0F,
hitZ
));
start3 = false;
}
}
if (previousTick != -1 && currentTick - previousTick >= 4) {
previousBlockValue = currentBlockValue;
} else if (previousTick == -1) {
previousTick = currentTick;
previousBlockValue = currentBlockValue;
}
if (mc.thePlayer.onGround) {
MoveUtil.strafe();
}
if (mc.thePlayer.onGround) {
event.setPosY(event.getPosY() + 0.0001);
}
if (jump && !mc.gameSettings.keyBindJump.isKeyDown()) {
if (mc.thePlayer.motionY > .331 && mc.thePlayer.motionY < .34) {
} else if (mc.thePlayer.motionY > .15) {
}
WatchdogTower.angle = mc.thePlayer.rotationYaw;
WatchdogTower.tickCounter = 17;
WatchdogTower.ticks = 0;
MoveUtil.stop();
jump = false;
RotationComponent.setRotations(new Vector2f((float) (mc.thePlayer.rotationYaw + (Math.random() - 0.5) * 3), (float) (90)), 10, MovementFix.NORMAL);// Store the BlockPos in a variable
if (!(PlayerUtil.block(mc.thePlayer.posX, mc.thePlayer.lastGroundY - 2, mc.thePlayer.posY) instanceof BlockAir)) {
getParent().startY = mc.thePlayer.lastGroundY - 1;
}
}
if (mc.gameSettings.keyBindJump.isKeyDown()) {
jump = true;
}
};
@Override
public void onEnable() {
start3 = false;
start4 = false;
if (!(getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump"))) {
if (mc.thePlayer.onGroundTicks > 9) {
hasC08Packet = true;
jumpHandled = true;
}
} else {
mc.thePlayer.safeWalk = false;
}
start2 = true;
jump = false;
if (!mc.thePlayer.onGround && !mc.gameSettings.keyBindJump.isKeyDown()) {
mc.thePlayer.motionX *= 0;
mc.thePlayer.motionZ *= 0;
}
previousBlockValue = -1;
previousTick = -1;
block = 0;
start2 = true;
}
@Override
public void onDisable() {
start3 = false;
start3 = false;
mc.thePlayer.safeWalk = false;
hasC08Packet = false;
jumpHandled = false;
if (mc.thePlayer.ticksSinceTeleport < 20) {
MoveUtil.stop();
}
start2 = false;
if (jump) {
MoveUtil.stop();
}
PingSpoofComponent.dispatch();
}
@EventLink(value = Priorities.MEDIUM)
public final Listener<PreUpdateEvent> onPreUpdate = event -> {
boolean start = mc.thePlayer.lastGroundY == getParent().startY;
if (!extraBlocks.getValue()) {
start = true;
}
if (getComponent(Slot.class).getItemStack() != null &&
mc.thePlayer.posY > getParent().startY &&
mc.thePlayer.posY + MoveUtil.predictedMotion(mc.thePlayer.motionY, 2) <
getParent().startY + 1 && ((!jumpHandled || hasC08Packet) && Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled()) && !(getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump")) || getComponent(Slot.class).getItemStack() != null &&
mc.thePlayer.posY > getParent().startY &&
mc.thePlayer.posY + MoveUtil.predictedMotion(mc.thePlayer.motionY, 2) <
getParent().startY + 1 && getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump")) {
getComponent(Slot.class).setSlot(SlotUtil.findBlock());
}
if (Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled()) {
start = false;
}
if (jumpHandled) {
start = true;
}
if (mc.thePlayer.offGroundTicks > 8) {
jumpHandled = false;
}
if (!start && mc.thePlayer.onGround && !mc.gameSettings.keyBindJump.isKeyDown()) {
MoveUtil.strafe(MoveUtil.getAllowedHorizontalDistance() - .01);
mc.thePlayer.jump();
}
if (!(PlayerUtil.isBlockUnder(2) || PlayerUtil.isBlockUnder(1) || PlayerUtil.isBlockUnder(0) || PlayerUtil.isBlockUnder(3)) && !mc.gameSettings.keyBindJump.isPressed() && !mc.thePlayer.isPotionActive(Potion.moveSpeed) && !jump) {
} else if (mc.thePlayer.onGroundTicks < 1) {
mc.thePlayer.safeWalk = false;
}
if (mc.gameSettings.keyBindJump.isPressed() && mc.thePlayer.onGround && !jump && (start2 || getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump")) && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled()) {
start2 = false;
MoveUtil.strafe(MoveUtil.getbaseMoveSpeed() * .9);
if ((getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump"))) {
MoveUtil.strafe(MoveUtil.getAllowedHorizontalDistance() - .001);
}
}
if (mc.thePlayer.offGroundTicks == 4 && !mc.gameSettings.keyBindJump.isKeyDown() && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled() && !start && getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump")) {
mc.thePlayer.motionY = mc.thePlayer.motionY - .19;
}
if (mc.thePlayer.offGroundTicks == 1 && !mc.gameSettings.keyBindJump.isKeyDown()) {
MoveUtil.strafe();
}
if (PlayerUtil.blockRelativeToPlayer(0, mc.thePlayer.motionY, 0) != Blocks.air && mc.thePlayer.offGroundTicks > 2) {
MoveUtil.strafe();
}
if (start && !mc.gameSettings.keyBindJump.isKeyDown() && !mc.thePlayer.onGround && !getModule(Speed.class).isEnabled() && extraBlocks.getValue()) {
MoveUtil.stop();
} else if (start && !mc.gameSettings.keyBindJump.isKeyDown() && !mc.thePlayer.onGround && extraBlocks.getValue()) {
MoveUtil.stop();
}
if (start && mc.thePlayer.onGround && !mc.gameSettings.keyBindJump.isKeyDown()) {
startTriggerCount++;
}
if (!start) {
startTriggerCount = 0;
}
};
@EventLink
public final Listener<PacketReceiveEvent> onPacketReceive = event -> {
if (event.getPacket() instanceof S23PacketBlockChange) {
start3 = true;
block++;
}
};
@EventLink
public final Listener<StrafeEvent> onStrafe = event -> {
if (!(getModule(Scaffold.class).sameY.getValue().getName().equals("Auto Jump"))) {
if (mc.thePlayer.onGround && jumpHandled && hasC08Packet && !Client.INSTANCE.getModuleManager().get(Speed.class).isEnabled()) {
mc.thePlayer.motionY = .42;
hasC08Packet = false;
}
}
};
}
// NOTE (AI): The S23 hook is the small onPacketReceive listener at the bottom: every received block change sets start3 and bumps the block counter. start3 gates the ice-placement C08 in onPreMotionEvent (line ~109), and the block counter feeds the previousBlockValue/previousTick pacing. The ice C08 is the actual Watchdog exploit; S23 only supplies the acknowledgement signal. Note the same mode exists in Rise 6.1.30's tree without the S23 reference, which is why found_in lists only 6.2.4.anticheat Anti-Cheat Checks
S23 changes a single block and tells the client about it; it is the smallest world mutation in the protocol. For server-side anticheats it is still a compensated-world event: the cache must apply the change before checks judge the player, and scaffolding checks use the client-facing block state to validate placement supports. The corpus for S23 is the block-change pipeline again (Grim AirLiquidPlace and CompensatedWorld, NCP BlockChangeTracker and BlockChangeListener, Intave SingleBlockChangeReader, Kauri BlockUpdateHandler, FlopAC WrappedOutBlockChange), with the same world-cache pattern as S22 but per block.
Flag block placements against air or liquid supports, which scaffolding and tower cheats produce.
BlockPlaceListener reads the placement position and the compensated world's block state at the support location; it first checks blockHistory for recent START_DIGGING or netty-sync modifications at that position so instant-breaking plus placing in the same tick does not false. If the support is air or a no-place liquid, the check flags and resyncs the placed block. The file's comment documents years of false-positive archaeology around dig-then-place ordering.
// ===== FILE: GrimAnticheat-Grim, common/src/main/java/ac/grim/grimac/checks/impl/scaffolding/AirLiquidPlace.java =====
package ac.grim.grimac.checks.impl.scaffolding;
import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.BlockPlaceCheck;
import ac.grim.grimac.checks.type.BlockPlaceListener;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.BlockPlace;
import ac.grim.grimac.utils.change.BlockModification;
import ac.grim.grimac.utils.nmsutil.Materials;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.util.Vector3i;
@CheckData(name = "AirLiquidPlace", stableKey = "grim.scaffolding.air_liquid_place", description = "Placed a block against an invalid support")
public class AirLiquidPlace extends BlockPlaceCheck implements BlockPlaceListener {
public AirLiquidPlace(GrimPlayer player) {
super(player);
}
/*
* This check has been plagued by falses for ages, and I've finally figured it out.
* When breaking and placing on the same tick in the same tick, I believe the vanilla client always sends DIGGING ACTION packets first
* This check's falses all seem to stem from processing DiggingAction.START_DIGGING before PacketType.Play.Client.PLAYER_BLOCK_PLACEMENT in the same tick
* Since we process the break first, when we go to process the place it looks like the player placed against air in the async world
*
* We will often see:
* Async world updated: short_grass -> air at X: -32, Y: 69, Z: -240, tick 0, cause/source: DiggingAction.START_DIGGING
* AirLiquidPlace Check: Block state at X: -32, Y: 69, Z: -240 is air (valid: false), tick +0-1, cause/source: PacketType.Play.Client.PLAYER_BLOCK_PLACEMENT <---- previously falsed here
* Async world updated: air -> short_grass at X: -32, Y: 69, Z: -240, tick +3-4, cause: realtime task in applyBlockChanges(List<Vector3i> toApplyBlocks) source: PacketType.Play.Client.PONG
* Async world updated: short_grass -> air at X: -32, Y: 69, Z: -240, tick +0-1, cause: handleNettySyncTransaction(LatencyUtils.java:56) source: PacketType.Play.Client.PONG
*
* In addition, it is possible for:
* Async world updated: short_grass -> air at X: -49, Y: 69, Z: -190, tick 0, cause: realtime task in applyBlockChanges(List<Vector3i> toApplyBlocks) source: PacketType.Play.Client.PONG
* AirLiquidPlace Check: Block state at X: -49, Y: 69, Z: -190 is air (valid=false), tick 0 <--- false due to change from applyBlockChanges()
* Async world updated: grass_block[snowy=false] -> grass_block[snowy=false] at X: -49, Y: 69, Z: -189, tick 0, cause: handleNettySyncTransaction(LatencyUtils.java:56) source: PacketType.Play.Client.PONG
*
* And in even more rare cases:
* Async world updated: air -> air at X: -51, Y: 71, Z: -179, tick 0, cause: handleNettySyncTransaction(LatencyUtils.java:56) source: PacketType.Play.Client.PONG
* AirLiquidPlace Check: Block state at X: -49, Y: 70, Z: -180 is short_grass (valid=true), tick 0
* Async world updated: short_grass -> air at X: -49, Y: 70, Z: -180, tick 1, cause/source: DiggingAction.START_DIGGING <--- double dig here (see my AirLiquidBreak patch) this is legit behaviour. Can only be up to 2 in 1 tick though.
* Async world updated: air -> short_grass at X: -49, Y: 70, Z: -180, tick 1, cause/source: DiggingAction.START_DIGGING
* Async world updated: short_grass -> air at X: -51, Y: 70, Z: -179, tick 1, cause: realtime task in applyBlockChanges(List<Vector3i> toApplyBlocks) source: PacketType.Play.Client.PONG
* AirLiquidPlace Check: Block state at X: -49, Y: 70, Z: -179 is air (valid=false), tick 2 <--- falses here due to double dig if we only check the latest changed blockstate. We have to check all changes at the location in same tick.
* AirLiquidPlace Check: Block state at X: -49, Y: 70, Z: -179 is air (valid=true), tick 2
*
* All of which previously would've caused a false.
* To solve this we store recently changed blocks caused by DiggingAction.START_DIGGING (instant breaking) and check against the old block.
* Lots of other checks have similar issues, and with the new player.blockHistory we can patch those.
*
* So that's it right? It's unfalsable?
* Very close but not quite. Vanilla's client game desyncs, especially on a laggy connection where a player is breaking and placing grass 20 cps/sec in the same tick
* it is possible for short grass to be interacted with even if server-side the block is air much later, and it won't be accounted for because the modification isn't recent.
* This is incredibly rare, unreliable and is only triggerable if you intentionally want to false the check. I consider a violation lvl of 2-3 to be reliable
* and 5-6 to be autobannable (if you don't care about people who are deliberately trying to get themselves false banned)
*/
@Override
public void onBlockPlace(final BlockPlace place) {
if (player.gamemode == GameMode.CREATIVE) return;
Vector3i blockPos = place.position;
StateType placeAgainst = player.compensatedWorld.getBlockType(blockPos.getX(), blockPos.getY(), blockPos.getZ());
int currentTick = GrimAPI.INSTANCE.getTickManager().currentTick;
// this is actual more lenient than we need to be, We can check up to 1 ticks for all changes at location sand up to 0 ticks for first change
// But for such tiny differences in legitness it's not worth it.
Iterable<BlockModification> blockModifications = player.blockHistory.getRecentModifications((blockModification) -> currentTick - blockModification.tick() < 2
&& blockPos.equals(blockModification.location())
&& (blockModification.cause() == BlockModification.Cause.START_DIGGING || blockModification.cause() == BlockModification.Cause.HANDLE_NETTY_SYNC_TRANSACTION));
// Check if old block from instant breaking in same tick as the current placement was valid
// There should only be one block here for legit clients
for (BlockModification blockModification : blockModifications) {
StateType stateType = blockModification.oldBlockContents().getType();
if (!stateType.isAir() && !Materials.isNoPlaceLiquid(stateType)) {
return;
}
}
if (placeAgainst.isAir() || Materials.isNoPlaceLiquid(placeAgainst)) { // fail
if (flag() && shouldModifyPackets() && shouldCancel()) {
place.resync();
}
}
}
@Override
protected int getDefaultCancelVL() {
return 0;
}
}
// NOTE (AI): The S22 and S23 corpus hits are the compensated-world change paths this check depends on; the check itself is placement-triggered.Decode the S23 packet into a single block position and block data for the block update tracker.
AbstractPacketReader implementing BlockChanges: reads the BlockPosition field through a thread-local converter and returns the packet's block data as single-element lists, which the BlockUpdateTracker applies to the block cache and acknowledges.
// ===== FILE: intave-intave, src/main/java/de/jpx3/intave/packet/reader/SingleBlockChangeReader.java =====
package de.jpx3.intave.packet.reader;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import de.jpx3.intave.klass.Lookup;
import de.jpx3.intave.packet.converter.BlockPositionConverter;
import java.util.Collections;
import java.util.List;
public final class SingleBlockChangeReader extends AbstractPacketReader implements BlockChanges {
@Override
public List<BlockPosition> blockPositions() {
BlockPosition blockPosition = packet().getModifier()
.withType(Lookup.serverClass("BlockPosition"), BlockPositionConverter.threadConverter())
.read(0);
return Collections.singletonList(blockPosition);
// return Lists.newArrayList(packet.getBlockPositionModifier().readSafely(0));
}
@Override
public List<WrappedBlockData> blockDataList() {
return Collections.singletonList(packet().getBlockData().read(0));
}
}
// NOTE (AI): setup(BLOCK_CHANGE, SingleBlockChangeReader::new) is the S23 registration; the acknowledgeBlockChange sequence keeps 1.19+ sequenced changes in lockstep.Reflection wrapper for the S23 packet so FlopAC's processors can read block positions and data across 1.7-1.12 protocol versions.
Resolves the NMS PacketPlayOutBlockChange class and its fields: legacy 1.7.10 x/y/z ints plus block and data fields, or the 1.8+ BlockPosition and IBlockData fields. process() populates a BaseBlockPosition from whichever layout the server version uses, and the constructor can build the packet from a Bukkit Block for server-side resync.
// ===== FILE: JTXOfficial-FlopAC, src/main/java/me/jtx/flopac/tinyprotocol/packet/out/WrappedOutBlockChange.java =====
package me.jtx.flopac.tinyprotocol.packet.out;
import lombok.Getter;
import me.jtx.flopac.tinyprotocol.api.NMSObject;
import me.jtx.flopac.tinyprotocol.api.Packet;
import me.jtx.flopac.tinyprotocol.api.ProtocolVersion;
import me.jtx.flopac.tinyprotocol.api.packets.reflections.Reflections;
import me.jtx.flopac.tinyprotocol.api.packets.reflections.types.WrappedClass;
import me.jtx.flopac.tinyprotocol.api.packets.reflections.types.WrappedField;
import me.jtx.flopac.tinyprotocol.api.packets.reflections.types.WrappedMethod;
import me.jtx.flopac.tinyprotocol.packet.types.BaseBlockPosition;
import me.jtx.flopac.tinyprotocol.reflection.FieldAccessor;
import me.jtx.flopac.util.box.ReflectionUtil;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@Getter
public class WrappedOutBlockChange extends NMSObject {
private static final String packet = Packet.Server.BLOCK_CHANGE;
//1.7.10 and below
private static FieldAccessor<Integer> legacyX;
private static FieldAccessor<Integer> legacyY;
private static FieldAccessor<Integer> legacyZ;
private static WrappedField blockChangeBlockField;
private static WrappedField blockDataIntField;
private static WrappedMethod getDataMethod;
//1.8 and newer
private static FieldAccessor<Object> blockPosAccessor;
private static WrappedField iBlockDataField;
private static final WrappedClass blockChangeClass = Reflections.getNMSClass(packet);
private static final WrappedClass nmsBlockClass = Reflections.getNMSClass("Block");
private static final WrappedClass craftBlockClass = Reflections.getCBClass("CraftBlock");
private BaseBlockPosition position;
public WrappedOutBlockChange(Object packet) {
super(packet);
}
@Override
public void updateObject() {
}
public WrappedOutBlockChange(Block block) {
if(ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_7_10)) {
setPacket(packet, block.getX(), block.getY(), block.getZ(), ReflectionUtil.getWorldHandle(block.getWorld()));
} else {
setPacket(packet, ReflectionUtil.getWorldHandle(block.getWorld()), new BaseBlockPosition(block.getX(), block.getY(), block.getZ()).getAsBlockPosition());
}
}
@Override
public void process(Player player, ProtocolVersion version) {
if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
position = new BaseBlockPosition(fetch(legacyX), fetch(legacyY), fetch(legacyZ));
} else {
position = new BaseBlockPosition(fetch(blockPosAccessor));
}
}
static {
if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_8)) {
legacyX = fetchField(packet, int.class, 0);
legacyY = fetchField(packet, int.class, 1);
legacyZ = fetchField(packet, int.class, 2);
blockChangeBlockField = blockChangeClass.getFirstFieldByType(nmsBlockClass.getParent());
blockDataIntField = blockChangeClass.getFieldByName("data");
getDataMethod = Reflections.getNMSClass("World").getMethod("getData", int.class, int.class, int.class);
} else {
blockPosAccessor = fetchField(packet, Object.class, 0);
iBlockDataField = blockChangeClass.getFieldByType(ReflectionUtil.iBlockData, 0);
}
}
}
// NOTE (AI): The S23 corpus hit is the BLOCK_CHANGE registration; FlopAC's WrappedOutMultiBlockChange covers S22.Ingest server block changes, including S23 single-block updates, into NCP's compensated BlockChangeTracker.
Registers Bukkit listeners for piston, redstone, entity block change, block form and player interact events and converts each into tracker.addBlockChange entries with tick and direction; the tracker's validity-interval model lets SurvivalFly, Passable and Visible ask whether a block existed at move time rather than now.
// ===== FILE: Updated-NoCheatPlus-NoCheatPlus, NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/changetracker/BlockChangeListener.java =====
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.compat.blocks.changetracker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.material.Directional;
import org.bukkit.material.Door;
import org.bukkit.material.MaterialData;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeMaterial;
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
import fr.neatmonster.nocheatplus.event.mini.MiniListener;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
import fr.neatmonster.nocheatplus.utilities.map.BlockFlags;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties.ToolProps;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties.ToolType;
public class BlockChangeListener implements Listener {
// TODO: Fine grained configurability (also switch flag in MovingListener to a sub-config).
// TODO: Coarse player activity filter?
public final boolean is1_13 = ServerVersion.compareMinecraftVersion("1.13") >= 0;
public final boolean is1_9 = ServerVersion.compareMinecraftVersion("1.9") >= 0;
/** These blocks certainly can't be pushed nor pulled. */
public static long F_MOVABLE_IGNORE = BlockFlags.F_LIQUID;
/** These blocks might be pushed or pulled. */
public static long F_MOVABLE = BlockFlags.F_GROUND | BlockFlags.F_SOLID;
private final BlockChangeTracker tracker;
private final boolean retractHasBlocks;
private boolean enabled = true;
/** Default tag for listeners. */
private final String defaultTag = "system.nocheatplus.blockchangetracker";
/** Properties by dirt block type.*/
protected final Map<Material, ToolType> dirtblocks = init();
/**
* NOTE: Using MiniListenerWithOrder (and @Override before @EventHandler)
* would make the registry attempt to register with Bukkit for 'Object'.
*/
private final MiniListener<?>[] miniListeners = new MiniListener<?>[] {
new MiniListener<BlockRedstoneEvent>() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(BlockRedstoneEvent event) {
if (enabled) {
onBlockRedstone(event);
}
}
},
new MiniListener<EntityChangeBlockEvent>() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(EntityChangeBlockEvent event) {
if (enabled) {
onEntityChangeBlock(event);
}
}
},
new MiniListener<BlockPistonExtendEvent>() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(BlockPistonExtendEvent event) {
if (enabled) {
onPistonExtend(event);
}
}
},
new MiniListener<BlockPistonRetractEvent>() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(BlockPistonRetractEvent event) {
if (enabled) {
onPistonRetract(event);
}
}
},
new MiniListener<PlayerInteractEvent>() {
// Include cancelled events, due to the use-block part.
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(PlayerInteractEvent event) {
if (enabled) {
onPlayerInteract(event);
}
}
},
new MiniListener<BlockFormEvent>() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = defaultTag)
@Override
public void onEvent(BlockFormEvent event) {
if (enabled) {
onBlockForm(event);
}
}
}
// @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
// public void onBlockPhysics (final BlockPhysicsEvent event) {
// if (!enabled) {
// return;
// }
// // TODO: Fine grained enabling state (pistons, doors, other).
// final Block block = event.getBlock();
// if (block == null || !physicsMaterials.contains(block.getType())) {
// return;
// }
// // TODO: MaterialData -> Door, upper/lower half needed ?
// tracker.addBlocks(block); // TODO: Skip too fast changing states?
// DebugUtil.debug("BlockPhysics: " + block); // TODO: REMOVE
// }
};
public BlockChangeListener(final BlockChangeTracker tracker) {
this.tracker = tracker;
if (ReflectionUtil.getMethodNoArgs(BlockPistonRetractEvent.class, "getBlocks") == null) {
retractHasBlocks = false;
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().info(Streams.STATUS, "Assume legacy piston behavior.");
}
else {
retractHasBlocks = true;
}
}
private Map<Material, ToolType> init() {
Map<Material, ToolType> blocks = new HashMap<Material, ToolType>();
blocks.put(BridgeMaterial.GRASS_BLOCK, ToolType.HOE);
blocks.put(Material.DIRT, ToolType.HOE);
if (is1_13) {
blocks.put(Material.COARSE_DIRT, ToolType.SPADE);
blocks.put(Material.PODZOL, ToolType.SPADE);
}
if (ServerVersion.compareMinecraftVersion("1.17") >= 0) {
blocks.put(Material.ROOTED_DIRT, ToolType.SPADE);
}
return blocks;
}
/**
* Register actual listener(s).
*/
public void register() {
// TODO: Replace 'if (enabled)' by actually unregistering the listeners.
final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
for (final MiniListener<?> listener : miniListeners) {
api.addComponent(listener);
}
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
private BlockFace getDirection(final Block pistonBlock) {
// TODO: Register/store a fetcher thing (DirectionalFromBlock)
if (is1_13) {
final BlockData data = pistonBlock.getState().getBlockData();
if (data instanceof org.bukkit.block.data.Directional) {
org.bukkit.block.data.Directional directional = (org.bukkit.block.data.Directional) data;
return directional.getFacing();
}
return null;
}
final MaterialData data = pistonBlock.getState().getData();
if (data instanceof Directional) {
Directional directional = (Directional) data;
return directional.getFacing();
}
return null;
}
/**
* Get the direction, in which blocks are or would be moved (towards the piston).
*
* @param pistonBlock
* @param eventDirection
* @return
*/
private BlockFace getRetractDirection(final Block pistonBlock, final BlockFace eventDirection) {
// Tested for pistons directed upwards.
// TODO: Test for pistons directed downwards, N, W, S, E.
// TODO: distinguish sticky vs. not sticky.
final BlockFace pistonDirection = getDirection(pistonBlock);
if (pistonDirection == null) {
return eventDirection;
}
else {
return eventDirection.getOppositeFace();
}
}
private void onPistonExtend(final BlockPistonExtendEvent event) {
final BlockFace direction = event.getDirection();
tracker.addPistonBlocks(event.getBlock().getRelative(direction), direction, event.getBlocks());
}
private void onPistonRetract(final BlockPistonRetractEvent event) {
final List<Block> blocks;
if (retractHasBlocks) {
blocks = event.getBlocks();
}
else {
@SuppressWarnings("deprecation")
final Location retLoc = event.getRetractLocation();
if (retLoc == null) {
blocks = null;
}
else {
final Block retBlock = retLoc.getBlock();
final long flags = BlockFlags.getBlockFlags(retBlock.getType());
if ((flags & F_MOVABLE_IGNORE) == 0L && (flags & F_MOVABLE) != 0L) {
blocks = new ArrayList<Block>(1);
blocks.add(retBlock);
}
else {
blocks = null;
}
}
}
// TODO: Special cases (don't push upwards on retract, with the resulting location being a solid block).
final Block pistonBlock = event.getBlock();
final BlockFace direction = getRetractDirection(pistonBlock, event.getDirection());
tracker.addPistonBlocks(pistonBlock.getRelative(direction.getOppositeFace()), direction, blocks);
}
private void onBlockRedstone(final BlockRedstoneEvent event) {
final int oldCurrent = event.getOldCurrent();
final int newCurrent = event.getNewCurrent();
if (oldCurrent == newCurrent || oldCurrent > 0 && newCurrent > 0) {
return;
}
// TODO: Fine grained enabling state (pistons, doors, other).
final Block block = event.getBlock();
// TODO: Abstract method for a block and a set of materials (redstone, interact, ...).
if (block == null
|| (BlockFlags.getBlockFlags(block.getType()) & BlockFlags.F_VARIABLE_REDSTONE) == 0) {
return;
}
addRedstoneBlock(block);
}
private void addRedstoneBlock(final Block block) {
addBlockWithAttachedPotential(block, BlockFlags.F_VARIABLE_REDSTONE);
}
private void onEntityChangeBlock(final EntityChangeBlockEvent event) {
final Block block = event.getBlock();
if (block != null) {
tracker.addBlocks(block); // E.g. falling blocks like sand.
}
}
private void onPlayerInteract(final PlayerInteractEvent event) {
// Check preconditions.
final org.bukkit.event.block.Action action = event.getAction();
if (action == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) {
onRightClickBlock(event);
}
else if (!event.isCancelled()) {
if (action == org.bukkit.event.block.Action.PHYSICAL) {
onInteractPhysical(event);
}
}
}
private void onInteractPhysical(final PlayerInteractEvent event) {
final Block block = event.getClickedBlock();
if (block != null) {
final Material type = block.getType();
// TODO: Consider a flag.
if (type == BridgeMaterial.FARMLAND) {
tracker.addBlocks(block);
}
}
}
@SuppressWarnings("deprecation")
private void onRightClickBlock(final PlayerInteractEvent event) {
final Result result = event.useInteractedBlock();
if ((result == Result.ALLOW
|| result == Result.DEFAULT && !event.isCancelled())) {
final Block block = event.getClickedBlock();
if (block != null) {
final Material type = block.getType();
// Dirt
final ToolType blocktool = dirtblocks.get(type);
if (blocktool != null) {
final ToolProps tool = BlockProperties.getToolProps(event.getItem());
if (is1_13) {
if (tool.toolType == ToolType.SPADE
|| blocktool == tool.toolType) {
tracker.addBlocks(block);
}
}
else {
final boolean defdata = block.getData() == 0;
if (is1_9 && type == BridgeMaterial.GRASS_BLOCK && tool.toolType == ToolType.SPADE
|| defdata && tool.toolType == ToolType.HOE) {
tracker.addBlocks(block);
}
}
}
if ((BlockFlags.getBlockFlags(type) & BlockFlags.F_VARIABLE_USE) != 0L) {
addBlockWithAttachedPotential(block, BlockFlags.F_VARIABLE_USE);
}
}
}
}
private void onBlockForm(final BlockFormEvent event) {
final Block block = event.getBlock();
if (block != null) {
// TODO: Filter by player activity.
tracker.addBlocks(block);
}
}
/**
* Add a past state for this block, extending for the other block in case of
* doors. This is for the case of interaction or redstone level change.
*
* @param block
* @param relevantFlags
*/
private void addBlockWithAttachedPotential(final Block block, final long relevantFlags) {
if (is1_13) {
final BlockData data = block.getState().getBlockData();
if (data instanceof org.bukkit.block.data.type.Door) {
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) data;
final Block otherBlock = block.getRelative(door.getHalf() == Half.TOP ? BlockFace.DOWN : BlockFace.UP);
/*
* TODO: In case of redstone: Double doors... detect those too? Is it still more
* efficient than using BlockPhysics with lazy delayed updating
* (TickListener...). Hinge corner... possibilities?
*/
if (otherBlock != null // Top of the map / special case.
&& (BlockFlags.getBlockFlags(otherBlock.getType()) & relevantFlags) != 0) {
tracker.addBlocks(block, otherBlock);
return;
}
}
}
// Legacy
else {
final MaterialData materialData = block.getState().getData();
if (materialData instanceof Door) {
final Door door = (Door) materialData;
final Block otherBlock = block.getRelative(door.isTopHalf() ? BlockFace.DOWN : BlockFace.UP);
/*
* TODO: In case of redstone: Double doors... detect those too? Is it still more
* efficient than using BlockPhysics with lazy delayed updating
* (TickListener...). Hinge corner... possibilities?
*/
if (otherBlock != null // Top of the map / special case.
&& (BlockFlags.getBlockFlags(otherBlock.getType()) & relevantFlags) != 0) {
tracker.addBlocks(block, otherBlock);
return;
}
}
}
// Only add the block in question itself.
tracker.addBlocks(block);
}
}
// NOTE (AI): The S22 and S23 corpus hits are shared: the listener feeds both packet-driven and event-driven changes into one tracker.Related Packets
Wiki Cross-Reference
Clientbound 0x23: BlockPos packed long plus VarInt block state ID.
State ID follows global palette: type is id right-shift 4 and meta is id and 15.
Single-block correction; bulk edits use S21 chunk data or S22 multi change.
MCP 1.8.9 S23PacketBlockChange implements Packet
1.8.9 callers: NetHandlerPlayServer.processPlayerDigging sends new S23PacketBlockChange (line 547) +2 more: https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/network/NetHandlerPlayServer.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.