0x44 S44PacketWorldBorder
Updates the world border (center, size, warning distance/buffer, damping).
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| action | VarInt Enum | 0=setSize, 1=lerpSize, 2=setCenter, 3=initialize, 4=setWarningTime, 5=setWarningBlocks |
| fields | varies | Action-dependent border parameters |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Action | VarInt | 0=size, 1=lerp, 2=center, 3=init, 4=warnTime, 5=warnBlocks |
| Per-Action Data | varies |
MCP References
NetHandlerPlayClient.handleWorldBorder()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 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
Deobfuscated MCP 1.8.9 source of S44PacketWorldBorder, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/server/S44PacketWorldBorder.java) at build time and verified present.
Deep Dive
Role in the protocol
World border state machine with six actions: SET_SIZE, LERP_SIZE, SET_CENTER, INITIALIZE, SET_WARNING_TIME and SET_WARNING_BLOCKS. ServerConfigurationManager broadcasts the five change actions to all players on border mutation (lines 245-261 in the MCP builds) and sends INITIALIZE to each player on join (line 786). INITIALIZE is the only action carrying the full state: center, current and target diameter, transition time, and both warning values.
Vanilla handling
The client handler func_175093_a delegates to packet.func_179788_a(worldBorder), which mutates the single WorldBorder object owned by the client world: setCenter, setTransition, setWarningDistance and setWarningTime. The border then feeds the renderer's red vignette and the camera clamp in EntityRenderer. It is one of the few packets whose handler mutates shared world state instead of copying values into local fields.
Why clients touch it
No module in the 8 clients references S44. Border tracking would matter for movement modules pathing around a shrinking border or for border-bypass claims, but none exists in the corpus. The border is server-enforced: EntityPlayerMP movement validation and WorldBorder.intersects run server-side and teleport or damage players who cross it, so the client's copy is purely cosmetic and modules gain nothing by intercepting it.
Exploit surface
All six actions deserialize doubles and a VarLong transition time with no sanity bounds; a hostile server can inject NaN or extreme diameters into the client WorldBorder, which the renderer then lerps against, producing visual glitches (the classic NaN border). Because enforcement is server-side, corrupting the client border changes nothing gameplay-relevant. The notable quirk is LERP_SIZE's VarLong time field, which is milliseconds server-side, not ticks.
Server-Side Handling
ServerConfigurationManager registers a WorldBorder listener that broadcasts SET_SIZE, LERP_SIZE, SET_CENTER, SET_WARNING_TIME and SET_WARNING_BLOCKS to all players on mutation (lines 245-261, MCP numbering), and sends INITIALIZE in initializeConnectionToPlayer (line 786). INITIALIZE serializes the whole border: center X/Z doubles, diameter and target doubles, VarLong transition time, warning distance and warning time ints.
Protocol Analysis
Action is a VarInt enum; payload depends on action. SET_SIZE: one double (target diameter). LERP_SIZE: old diameter double, target double, VarLong transition time in milliseconds. SET_CENTER: two doubles. SET_WARNING_TIME and SET_WARNING_BLOCKS: one int each. INITIALIZE: center doubles, both diameters, VarLong, and both warning ints. readEnumValue can return null on an out-of-range action, which NPEs in the read switch.
Anti-Cheat Landscape
No anti-cheat measures border packets. The server enforces the border in its own movement pipeline (EntityPlayerMP position validation against WorldBorder.intersects), so client-side border state has no bearing on any server-side check. The only client-visible effect of tampering is rendering artifacts.
implementation Implementation Cases
Six-action world border state machine, broadcast on change and fully initialized on join. Server-enforced, so the client copy is cosmetic; none of the 8 clients has a module that references it. The interesting wire details are the mixed field widths and the VarLong transition time.
anticheat Anti-Cheat Checks
The world border packet is the one clientbound world-state packet anticheats genuinely consume. Grim decodes all five actions into a border state and feeds it into the collision pipeline so phase checks treat the border as a solid wall, and intave decodes the same actions into the border model its movement simulation runs against. NCP and Artemis implement the border-as-wall idea too, but they read Bukkit's server-side WorldBorder instead of the packet. Negativity and Artemis also register the packet type.
Mirror the server's world border state on the compensation side so collision and movement checks know where the border is.
A PacketSendListener that wraps the five border packet forms (WORLD_BORDER action packet, INITIALIZE_WORLD_BORDER, WORLD_BORDER_CENTER, WORLD_BORDER_SIZE, WORLD_BORDER_LERP_SIZE) and mutates a BorderExtent: SET_SIZE and WORLD_BORDER_SIZE set the diameter, LERP_SIZE and WORLD_BORDER_LERP_SIZE build a moving extent with the transition duration, SET_CENTER and WORLD_BORDER_CENTER move the center, and INITIALIZE fills the whole state plus the portal teleport boundary. Each update is transaction-bracketed and applied on the next real-time task, and tickBorder() advances the lerp on movement ticks.
// ===== FILE: GrimAnticheat-Grim, common/src/main/java/ac/grim/grimac/events/packets/PacketWorldBorder.java =====
package ac.grim.grimac.events.packets;
import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.type.PacketSendListener;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.worldborder.BorderExtent;
import ac.grim.grimac.utils.worldborder.RealTimeMovingBorderExtent;
import ac.grim.grimac.utils.worldborder.StaticBorderExtent;
import ac.grim.grimac.utils.worldborder.TickBasedMovingBorderExtent;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerInitializeWorldBorder;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWorldBorder;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWorldBorderCenter;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWorldBorderSize;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayWorldBorderLerpSize;
import lombok.Getter;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
public class PacketWorldBorder extends Check implements PacketSendListener {
private static final boolean SERVER_TICK_BASED = PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_21_11);
@Getter
private double centerX;
@Getter
private double centerZ;
@Getter
private double absoluteMaxSize;
@Getter
private BorderExtent extent;
public PacketWorldBorder(GrimPlayer playerData) {
super(playerData);
this.extent = new StaticBorderExtent(5.999997E7);
}
public double getCurrentDiameter() {
return extent.size();
}
public double getMinX() {
return extent.getMinX(centerX, absoluteMaxSize);
}
public double getMaxX() {
return extent.getMaxX(centerX, absoluteMaxSize);
}
public double getMinZ() {
return extent.getMinZ(centerZ, absoluteMaxSize);
}
public double getMaxZ() {
return extent.getMaxZ(centerZ, absoluteMaxSize);
}
public void tickBorder() {
extent = extent.tick();
}
@Override
public void onPacketSend(PacketSendEvent event) {
if (event.getPacketType() == PacketType.Play.Server.WORLD_BORDER) {
WrapperPlayServerWorldBorder packet = new WrapperPlayServerWorldBorder(event);
player.sendTransaction();
// Names are misleading, it's diameter not radius.
if (packet.getAction() == WrapperPlayServerWorldBorder.WorldBorderAction.SET_SIZE) {
double size = packet.getRadius();
player.addRealTimeTaskNow(() -> setSize(size));
} else if (packet.getAction() == WrapperPlayServerWorldBorder.WorldBorderAction.LERP_SIZE) {
double oldDiameter = packet.getOldRadius();
double newDiameter = packet.getNewRadius();
long speed = packet.getSpeed();
player.addRealTimeTaskNow(() -> setLerp(oldDiameter, newDiameter, speed));
} else if (packet.getAction() == WrapperPlayServerWorldBorder.WorldBorderAction.SET_CENTER) {
double centerX = packet.getCenterX();
double centerZ = packet.getCenterZ();
player.addRealTimeTaskNow(() -> setCenter(centerX, centerZ));
} else if (packet.getAction() == WrapperPlayServerWorldBorder.WorldBorderAction.INITIALIZE) {
double centerX = packet.getCenterX();
double centerZ = packet.getCenterZ();
double oldDiameter = packet.getOldRadius();
double newDiameter = packet.getNewRadius();
long speed = packet.getSpeed();
int portalTeleportBoundary = packet.getPortalTeleportBoundary();
player.addRealTimeTaskNow(() -> {
setCenter(centerX, centerZ);
setLerp(oldDiameter, newDiameter, speed);
absoluteMaxSize = portalTeleportBoundary;
});
}
}
if (event.getPacketType() == PacketType.Play.Server.INITIALIZE_WORLD_BORDER) {
player.sendTransaction();
WrapperPlayServerInitializeWorldBorder packet = new WrapperPlayServerInitializeWorldBorder(event);
double centerX = packet.getX();
double centerZ = packet.getZ();
double oldDiameter = packet.getOldDiameter();
double newDiameter = packet.getNewDiameter();
long speed = packet.getSpeed();
int portalTeleportBoundary = packet.getPortalTeleportBoundary();
player.addRealTimeTaskNow(() -> {
setCenter(centerX, centerZ);
setLerp(oldDiameter, newDiameter, speed);
absoluteMaxSize = portalTeleportBoundary;
});
}
if (event.getPacketType() == PacketType.Play.Server.WORLD_BORDER_CENTER) {
player.sendTransaction();
WrapperPlayServerWorldBorderCenter packet = new WrapperPlayServerWorldBorderCenter(event);
double centerX = packet.getX();
double centerZ = packet.getZ();
player.addRealTimeTaskNow(() -> setCenter(centerX, centerZ));
}
if (event.getPacketType() == PacketType.Play.Server.WORLD_BORDER_SIZE) {
player.sendTransaction();
double size = new WrapperPlayServerWorldBorderSize(event).getDiameter();
player.addRealTimeTaskNow(() -> setSize(size));
}
if (event.getPacketType() == PacketType.Play.Server.WORLD_BORDER_LERP_SIZE) {
player.sendTransaction();
WrapperPlayWorldBorderLerpSize packet = new WrapperPlayWorldBorderLerpSize(event);
double oldDiameter = packet.getOldDiameter();
double newDiameter = packet.getNewDiameter();
long speed = packet.getSpeed();
player.addRealTimeTaskNow(() -> setLerp(oldDiameter, newDiameter, speed));
}
}
@Contract(mutates = "this")
private void setCenter(double x, double z) {
centerX = x;
centerZ = z;
}
@Contract(mutates = "this")
private void setSize(double size) {
this.extent = new StaticBorderExtent(size);
}
@Contract(mutates = "this")
private void setLerp(double oldDiameter, double newDiameter, long speed) {
if (speed <= 0 || oldDiameter == newDiameter) {
this.extent = new StaticBorderExtent(newDiameter);
} else {
this.extent = createMovingExtent(oldDiameter, newDiameter, speed);
}
}
@Contract("_, _, _ -> new")
private @NotNull BorderExtent createMovingExtent(double from, double to, long speed) {
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_11)) { // tick-based
long durationTicks = SERVER_TICK_BASED ? speed : (speed / 50);
return new TickBasedMovingBorderExtent(from, to, durationTicks);
} else { // real-time based
long durationMs = SERVER_TICK_BASED ? (speed * 50) : speed;
return new RealTimeMovingBorderExtent(from, to, durationMs);
}
}
}
// NOTE (AI): The S44 handling is the whole onPacketSend method (lines 65-137), covering all five border packet forms. PacketPlayerTick.java lines 30 and 37 fetch this check to read border state during movement ticks; Collisions.java line 216 pulls it inside addWorldBorder.Treat the world border as an axis-aligned collision wall so phase and clipping checks cannot move a player through it.
Collisions.addWorldBorder computes the border's min and max X/Z from the PacketWorldBorder check state and, when the player is within 16 blocks of the border, appends four thin collision boxes (one per side, infinite in Y) to the box list the collision resolver tests against. getCollisionBoxes calls it first, so any movement that would place the player across the border collides like a wall.
// ===== FILE: GrimAnticheat-Grim, common/src/main/java/ac/grim/grimac/utils/nmsutil/Collisions.java =====
package ac.grim.grimac.utils.nmsutil;
import ac.grim.grimac.events.packets.PacketWorldBorder;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.predictionengine.blockeffects.BlockEffectsResolver;
import ac.grim.grimac.predictionengine.blockeffects.impl.BlockEffectsResolverV1_21_10;
import ac.grim.grimac.predictionengine.blockeffects.impl.BlockEffectsResolverV1_21_2;
import ac.grim.grimac.predictionengine.blockeffects.impl.BlockEffectsResolverV1_21_4;
import ac.grim.grimac.predictionengine.blockeffects.impl.BlockEffectsResolverV1_21_5;
import ac.grim.grimac.predictionengine.blockeffects.impl.BlockEffectsResolverV1_21_6;
import ac.grim.grimac.utils.chunks.Column;
import ac.grim.grimac.utils.collisions.CollisionData;
import ac.grim.grimac.utils.collisions.datatypes.CollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
import ac.grim.grimac.utils.data.VectorData;
import ac.grim.grimac.utils.data.packetentity.PacketEntity;
import ac.grim.grimac.utils.data.tags.SyncedTags;
import ac.grim.grimac.utils.functions.BlockAndPositionConsumer;
import ac.grim.grimac.utils.functions.BlockAndPositionPredicate;
import ac.grim.grimac.utils.latency.CompensatedWorld;
import ac.grim.grimac.utils.math.GrimMath;
import ac.grim.grimac.utils.math.Vector3dm;
import ac.grim.grimac.utils.math.VectorUtils;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.potion.PotionTypes;
import com.github.retrooper.packetevents.protocol.world.Direction;
import com.github.retrooper.packetevents.protocol.world.chunk.BaseChunk;
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
import com.github.retrooper.packetevents.protocol.world.states.defaulttags.BlockTags;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3i;
import it.unimi.dsi.fastutil.floats.FloatArraySet;
import it.unimi.dsi.fastutil.floats.FloatArrays;
import it.unimi.dsi.fastutil.floats.FloatSet;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@UtilityClass
public final class Collisions {
public static final double COLLISION_EPSILON = 1.0E-7;
private static final boolean IS_FOURTEEN = PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14); // Optimization for chunks with empty block count
private static final List<List<Axis>> allAxisCombinations = Arrays.asList(
Arrays.asList(Axis.Y, Axis.X, Axis.Z),
Arrays.asList(Axis.Y, Axis.Z, Axis.X),
Arrays.asList(Axis.X, Axis.Y, Axis.Z),
Arrays.asList(Axis.X, Axis.Z, Axis.Y),
Arrays.asList(Axis.Z, Axis.X, Axis.Y),
Arrays.asList(Axis.Z, Axis.Y, Axis.X));
private static final List<List<Axis>> nonStupidityCombinations = Arrays.asList(
Arrays.asList(Axis.Y, Axis.X, Axis.Z),
Arrays.asList(Axis.Y, Axis.Z, Axis.X));
public static boolean slowCouldPointThreeHitGround(GrimPlayer player, double x, double y, double z) {
SimpleCollisionBox oldBB = player.boundingBox;
player.boundingBox = GetBoundingBox.getBoundingBoxFromPosAndSize(player, x, y, z, 0.6f, 0.06f);
double movementThreshold = player.getMovementThreshold();
double posXZ = collide(player, movementThreshold, -movementThreshold, movementThreshold).getY();
double negXNegZ = collide(player, -movementThreshold, -movementThreshold, -movementThreshold).getY();
double posXNegZ = collide(player, movementThreshold, -movementThreshold, -movementThreshold).getY();
double posZNegX = collide(player, -movementThreshold, -movementThreshold, movementThreshold).getY();
player.boundingBox = oldBB;
return negXNegZ != -movementThreshold || posXNegZ != -movementThreshold || posXZ != -movementThreshold || posZNegX != -movementThreshold;
}
// Call this when there isn't uncertainty on the Y axis
public static Vector3dm collide(GrimPlayer player, double desiredX, double desiredY, double desiredZ) {
return collide(player, desiredX, desiredY, desiredZ, desiredY, null);
}
public static Vector3dm collide(GrimPlayer player, double desiredX, double desiredY, double desiredZ, double clientVelY, VectorData data) {
if (desiredX == 0 && desiredY == 0 && desiredZ == 0) return new Vector3dm();
final SimpleCollisionBox grabBoxesBB = player.boundingBox.copy();
final double stepUpHeight = player.getMaxUpStep();
if (desiredX == 0.0 && desiredZ == 0.0) {
if (desiredY > 0.0) {
grabBoxesBB.maxY += desiredY;
} else {
grabBoxesBB.minY += desiredY;
}
} else {
if (stepUpHeight > 0.0 && (player.lastOnGround || desiredY < 0 || clientVelY < 0)) {
// don't bother getting the collisions if we don't need them.
if (desiredY <= 0.0) {
grabBoxesBB.expandToCoordinate(desiredX, desiredY, desiredZ);
grabBoxesBB.maxY += stepUpHeight;
} else {
grabBoxesBB.expandToCoordinate(desiredX, Math.max(stepUpHeight, desiredY), desiredZ);
}
} else {
grabBoxesBB.expandToCoordinate(desiredX, desiredY, desiredZ);
}
}
List<SimpleCollisionBox> desiredMovementCollisionBoxes = new ArrayList<>();
getCollisionBoxes(player, grabBoxesBB, desiredMovementCollisionBoxes, false);
double bestInput = Double.MAX_VALUE;
Vector3dm bestOrderResult = null;
Vector3dm bestTheoreticalCollisionResult = VectorUtils.cutBoxToVector(player.actualMovement, new SimpleCollisionBox(0, Math.min(0, desiredY), 0, desiredX, Math.max(stepUpHeight, desiredY), desiredZ).sort());
int zeroCount = (desiredX == 0 ? 1 : 0) + (desiredY == 0 ? 1 : 0) + (desiredZ == 0 ? 1 : 0);
for (List<Axis> order : (data != null && data.isZeroPointZeroThree() ? allAxisCombinations : nonStupidityCombinations)) {
Vector3dm collisionResult = collideBoundingBoxLegacy(new Vector3dm(desiredX, desiredY, desiredZ), player.boundingBox, desiredMovementCollisionBoxes, order);
// While running up stairs and holding space, the player activates the "lastOnGround" part without otherwise being able to step
// 0.03 movement must compensate for stepping elsewhere. Too much of a hack to include in this method.
boolean movingIntoGroundReal = player.pointThreeEstimator.closeEnoughToGroundToStepWithPointThree(data, clientVelY) || collisionResult.getY() != desiredY && (desiredY < 0 || clientVelY < 0);
boolean movingIntoGround = player.lastOnGround || movingIntoGroundReal;
// If the player has x or z collision, is going in the downwards direction in the last or this tick, and can step up
// If not, just return the collisions without stepping up that we calculated earlier
// At high ping, if you get setback, then you can reach the ground in time. When you are teleported back up by the setback, the game allows you to step up legitimately. By disallowing stepping we prevent a step exploit.
final boolean disallowStepping = player.getSetbackTeleportUtil().getRequiredSetBack() != null && player.getSetbackTeleportUtil().getRequiredSetBack().getTicksComplete() == 1;
if (!disallowStepping && stepUpHeight > 0.0F && movingIntoGround && (collisionResult.getX() != desiredX || collisionResult.getZ() != desiredZ)) {
player.uncertaintyHandler.isStepMovement = true;
// 1.21 significantly refactored this
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21)) {
SimpleCollisionBox startingOffsetBox = movingIntoGroundReal ? player.boundingBox.copy().offset(0.0, collisionResult.getY(), 0.0) : player.boundingBox.copy();
SimpleCollisionBox offsetByHorizAndStepBox = startingOffsetBox.copy().expandToCoordinate(desiredX, stepUpHeight, desiredZ);
if (!movingIntoGroundReal) {
offsetByHorizAndStepBox = offsetByHorizAndStepBox.copy().expandToCoordinate(0.0, -1.0E-5F, 0.0);
}
final List<SimpleCollisionBox> stepCollisions = new ArrayList<>();
getCollisionBoxes(player, offsetByHorizAndStepBox, stepCollisions, false);
final float[] stepHeights = collectStepHeights(startingOffsetBox, stepCollisions, (float) stepUpHeight, (float) collisionResult.getY());
for (float stepHeight : stepHeights) {
Vector3dm vec3d2 = collideBoundingBoxLegacy(new Vector3dm(desiredX, stepHeight, desiredZ), startingOffsetBox, stepCollisions, order);
if (getHorizontalDistanceSqr(vec3d2) > getHorizontalDistanceSqr(collisionResult)) {
final double d = player.boundingBox.minY - startingOffsetBox.minY;
collisionResult = vec3d2.add(new Vector3dm(0.0, -d, 0.0));
break;
}
}
} else {
Vector3dm regularStepUp = collideBoundingBoxLegacy(new Vector3dm(desiredX, stepUpHeight, desiredZ), player.boundingBox, desiredMovementCollisionBoxes, order);
// 1.7 clients do not have this stepping bug fix
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8)) {
Vector3dm stepUpBugFix = collideBoundingBoxLegacy(new Vector3dm(0, stepUpHeight, 0), player.boundingBox.copy().expandToCoordinate(desiredX, 0, desiredZ), desiredMovementCollisionBoxes, order);
if (stepUpBugFix.getY() < stepUpHeight) {
Vector3dm stepUpBugFixResult = collideBoundingBoxLegacy(new Vector3dm(desiredX, 0, desiredZ), player.boundingBox.copy().offset(0, stepUpBugFix.getY(), 0), desiredMovementCollisionBoxes, order).add(stepUpBugFix);
if (getHorizontalDistanceSqr(stepUpBugFixResult) > getHorizontalDistanceSqr(regularStepUp)) {
regularStepUp = stepUpBugFixResult;
}
}
}
if (getHorizontalDistanceSqr(regularStepUp) > getHorizontalDistanceSqr(collisionResult)) {
collisionResult = regularStepUp.add(collideBoundingBoxLegacy(new Vector3dm(0, -regularStepUp.getY() + (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14) ? desiredY : 0), 0), player.boundingBox.copy().offset(regularStepUp.getX(), regularStepUp.getY(), regularStepUp.getZ()), desiredMovementCollisionBoxes, order));
}
}
}
double resultAccuracy = collisionResult.distanceSquared(bestTheoreticalCollisionResult);
// Step movement doesn't care about ground (due to 0.03)
if (player.wouldCollisionResultFlagGroundSpoof(desiredY, collisionResult.getY())) {
resultAccuracy += 1;
}
if (resultAccuracy < bestInput) {
bestOrderResult = collisionResult;
bestInput = resultAccuracy;
if (resultAccuracy < 0.00001 * 0.00001) break;
if (zeroCount >= 2) break;
}
}
return bestOrderResult;
}
private static float[] collectStepHeights(SimpleCollisionBox collisionBox, List<SimpleCollisionBox> collisions, float stepHeight, float collideY) {
final FloatSet floatSet = new FloatArraySet(4);
for (SimpleCollisionBox blockBox : collisions) {
for (double possibleStepY : blockBox.getYPointPositions()) {
float yDiff = (float) (possibleStepY - collisionBox.minY);
if (!(yDiff < 0.0F) && yDiff != collideY) {
if (yDiff > stepHeight) {
break;
}
floatSet.add(yDiff);
}
}
}
float[] fs = floatSet.toFloatArray();
FloatArrays.unstableSort(fs);
return fs;
}
public static boolean addWorldBorder(GrimPlayer player, SimpleCollisionBox wantedBB, List<SimpleCollisionBox> listOfBlocks, boolean onlyCheckCollide) {
// Worldborders were added in 1.8
// Don't add to border unless the player is colliding with it and is near it
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_8)) {
PacketWorldBorder border = player.checkManager.getCheck(PacketWorldBorder.class);
double minX = Math.floor(border.getMinX());
double minZ = Math.floor(border.getMinZ());
double maxX = Math.ceil(border.getMaxX());
double maxZ = Math.ceil(border.getMaxZ());
// If the player is fully within the worldborder
double toMinX = player.lastX - minX;
double toMaxX = maxX - player.lastX;
double minimumInXDirection = Math.min(toMinX, toMaxX);
double toMinZ = player.lastZ - minZ;
double toMaxZ = maxZ - player.lastZ;
double minimumInZDirection = Math.min(toMinZ, toMaxZ);
double distanceToBorder = Math.min(minimumInXDirection, minimumInZDirection);
// If the player's is within 16 blocks of the worldborder, add the worldborder to the collisions (optimization)
if (distanceToBorder < 16 && player.lastX > minX && player.lastX < maxX && player.lastZ > minZ && player.lastZ < maxZ) {
if (listOfBlocks == null) listOfBlocks = new ArrayList<>();
// South border
listOfBlocks.add(new SimpleCollisionBox(minX - 10, Double.NEGATIVE_INFINITY, maxZ, maxX + 10, Double.POSITIVE_INFINITY, maxZ, false));
// North border
listOfBlocks.add(new SimpleCollisionBox(minX - 10, Double.NEGATIVE_INFINITY, minZ, maxX + 10, Double.POSITIVE_INFINITY, minZ, false));
// East border
listOfBlocks.add(new SimpleCollisionBox(maxX, Double.NEGATIVE_INFINITY, minZ - 10, maxX, Double.POSITIVE_INFINITY, maxZ + 10, false));
// West border
listOfBlocks.add(new SimpleCollisionBox(minX, Double.NEGATIVE_INFINITY, minZ - 10, minX, Double.POSITIVE_INFINITY, maxZ + 10, false));
if (onlyCheckCollide) {
for (SimpleCollisionBox box : listOfBlocks) {
if (box.isIntersected(wantedBB)) return true;
}
}
}
}
return false;
}
// This is mostly taken from Tuinity collisions
public static boolean getCollisionBoxes(GrimPlayer player, SimpleCollisionBox wantedBB, List<SimpleCollisionBox> listOfBlocks, boolean onlyCheckCollide) {
SimpleCollisionBox expandedBB = wantedBB.copy();
boolean collided = addWorldBorder(player, wantedBB, listOfBlocks, onlyCheckCollide);
if (onlyCheckCollide && collided) return true;
int minBlockX = (int) Math.floor(expandedBB.minX - COLLISION_EPSILON) - 1;
int maxBlockX = (int) Math.floor(expandedBB.maxX + COLLISION_EPSILON) + 1;
int minBlockY = (int) Math.floor(expandedBB.minY - COLLISION_EPSILON) - 1;
int maxBlockY = (int) Math.floor(expandedBB.maxY + COLLISION_EPSILON) + 1;
int minBlockZ = (int) Math.floor(expandedBB.minZ - COLLISION_EPSILON) - 1;
int maxBlockZ = (int) Math.floor(expandedBB.maxZ + COLLISION_EPSILON) + 1;
final int minSection = player.compensatedWorld.getMinHeight() >> 4;
final int minBlock = minSection << 4;
final int maxBlock = player.compensatedWorld.getMaxHeight() - 1;
int minChunkX = minBlockX >> 4;
int maxChunkX = maxBlockX >> 4;
int minChunkZ = minBlockZ >> 4;
int maxChunkZ = maxBlockZ >> 4;
int minYIterate = Math.max(minBlock, minBlockY);
int maxYIterate = Math.min(maxBlock, maxBlockY);
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
int minZ = currChunkZ == minChunkZ ? minBlockZ & 15 : 0; // coordinate in chunk
int maxZ = currChunkZ == maxChunkZ ? maxBlockZ & 15 : 15; // coordinate in chunk
for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
int minX = currChunkX == minChunkX ? minBlockX & 15 : 0; // coordinate in chunk
int maxX = currChunkX == maxChunkX ? maxBlockX & 15 : 15; // coordinate in chunk
int chunkXGlobalPos = currChunkX << 4;
int chunkZGlobalPos = currChunkZ << 4;
Column chunk = player.compensatedWorld.getChunk(currChunkX, currChunkZ);
if (chunk == null) continue;
BaseChunk[] sections = chunk.chunks();
for (int y = minYIterate; y <= maxYIterate; ++y) {
int sectionIndex = (y >> 4) - minSection;
BaseChunk section = sections[sectionIndex];
if (section == null || (IS_FOURTEEN && section.isEmpty())) { // Check for empty on 1.13+ servers
// empty
// skip to next section
y = (y & ~15) + 15; // increment by 15: iterator loop increments by the extra one
continue;
}
for (int currZ = minZ; currZ <= maxZ; ++currZ) {
for (int currX = minX; currX <= maxX; ++currX) {
int x = currX | chunkXGlobalPos;
int z = currZ | chunkZGlobalPos;
WrappedBlockState data = section.get(CompensatedWorld.blockVersion, x & 0xF, y & 0xF, z & 0xF, false);
// Works on both legacy and modern! Faster than checking for material types, most common case
if (data.getGlobalId() == 0) continue;
// Thanks SpottedLeaf for this optimization, I took edgeCount from Tuinity
int edgeCount = ((x == minBlockX || x == maxBlockX) ? 1 : 0) +
((y == minBlockY || y == maxBlockY) ? 1 : 0) +
((z == minBlockZ || z == maxBlockZ) ? 1 : 0);
final StateType type = data.getType();
if (edgeCount != 3 && (edgeCount != 1 || Materials.isShapeExceedsCube(type))
&& (edgeCount != 2 || type == StateTypes.PISTON_HEAD)) {
final CollisionBox collisionBox = CollisionData.getData(type).getMovementCollisionBox(player, player.getClientVersion(), data, x, y, z);
// Don't add to a list if we only care if the player intersects with the block
if (!onlyCheckCollide) {
collisionBox.downCast(listOfBlocks);
} else if (collisionBox.isCollided(wantedBB)) {
return true;
}
}
}
}
}
}
}
return false;
}
public static Vector3dm collideBoundingBoxLegacy(Vector3dm toCollide, SimpleCollisionBox
box, List<SimpleCollisionBox> desiredMovementCollisionBoxes, List<Axis> order) {
double x = toCollide.getX();
double y = toCollide.getY();
double z = toCollide.getZ();
SimpleCollisionBox setBB = box.copy();
for (Axis axis : order) {
if (axis == Axis.X) {
for (SimpleCollisionBox bb : desiredMovementCollisionBoxes) {
x = bb.collideX(setBB, x);
}
setBB.offset(x, 0.0D, 0.0D);
} else if (axis == Axis.Y) {
for (SimpleCollisionBox bb : desiredMovementCollisionBoxes) {
y = bb.collideY(setBB, y);
}
setBB.offset(0.0D, y, 0.0D);
} else if (axis == Axis.Z) {
for (SimpleCollisionBox bb : desiredMovementCollisionBoxes) {
z = bb.collideZ(setBB, z);
}
setBB.offset(0.0D, 0.0D, z);
}
}
return new Vector3dm(x, y, z);
}
public static boolean isEmpty(GrimPlayer player, SimpleCollisionBox playerBB) {
return !getCollisionBoxes(player, playerBB, null, true);
}
public static double getHorizontalDistanceSqr(Vector3dm vector) {
return vector.getX() * vector.getX() + vector.getZ() * vector.getZ();
}
public static Vector3dm maybeBackOffFromEdge(Vector3dm vec3, GrimPlayer player, boolean overrideVersion) {
if (!player.isFlying && player.isSneaking && isAboveGround(player)) {
double x = vec3.getX();
double z = vec3.getZ();
double maxStepDown = overrideVersion || player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_11) ? -player.getMaxUpStep() : -1 + COLLISION_EPSILON;
while (x != 0.0 && isEmpty(player, player.boundingBox.copy().offset(x, maxStepDown, 0.0))) {
if (x < 0.05D && x >= -0.05D) {
x = 0.0D;
} else if (x > 0.0D) {
x -= 0.05D;
} else {
x += 0.05D;
}
}
while (z != 0.0 && isEmpty(player, player.boundingBox.copy().offset(0.0, maxStepDown, z))) {
if (z < 0.05D && z >= -0.05D) {
z = 0.0D;
} else if (z > 0.0D) {
z -= 0.05D;
} else {
z += 0.05D;
}
}
while (x != 0.0 && z != 0.0 && isEmpty(player, player.boundingBox.copy().offset(x, maxStepDown, z))) {
if (x < 0.05D && x >= -0.05D) {
x = 0.0D;
} else if (x > 0.0D) {
x -= 0.05D;
} else {
x += 0.05D;
}
if (z < 0.05D && z >= -0.05D) {
z = 0.0D;
} else if (z > 0.0D) {
z -= 0.05D;
} else {
z += 0.05D;
}
}
vec3 = new Vector3dm(x, vec3.getY(), z);
}
return vec3;
}
public static boolean isAboveGround(GrimPlayer player) {
// https://bugs.mojang.com/browse/MC-2404
return player.lastOnGround || (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16_2) && (player.fallDistance < player.getMaxUpStep() &&
!isEmpty(player, player.boundingBox.copy().offset(0.0, player.fallDistance - player.getMaxUpStep(), 0.0))));
}
public static void handleInsideBlocks(GrimPlayer player) {
// Mojang rewrote this whole logic in 1.21.2 (see Collisions#applyEffectsFromBlocks)
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_2)) return;
// Use the bounding box for after the player's movement is applied
double expandAmount = player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_19_4) ? 1e-5 : 0.001;
SimpleCollisionBox box = (player.inVehicle()
? GetBoundingBox.getCollisionBoxForPlayer(player, player.x, player.y, player.z)
: player.boundingBox.copy()).expand(-expandAmount);
int minX = GrimMath.mojangFloor(box.minX);
int minY = GrimMath.mojangFloor(box.minY);
int minZ = GrimMath.mojangFloor(box.minZ);
int maxX = GrimMath.mojangFloor(box.maxX);
int maxY = GrimMath.mojangFloor(box.maxY);
int maxZ = GrimMath.mojangFloor(box.maxZ);
if (player.compensatedWorld.areChunksUnloadedAt(minX, minY, minZ, maxX, maxY, maxZ))
return;
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
WrappedBlockState block = player.compensatedWorld.getBlock(x, y, z);
StateType blockType = block.getType();
if (blockType.isAir()) {
continue;
}
onInsideBlock(player, player.clientVelocity, false, blockType, block, x, y, z, true);
}
}
}
}
public static void onInsideBlock(GrimPlayer player, Vector3dm clientVelocity, boolean onlyApplyVelocity, StateType blockType, WrappedBlockState block, int blockX, int blockY, int blockZ, boolean magic) {
PacketEntity riding = player.compensatedEntities.self.getRiding();
boolean stuckEntityIsLiving = riding == null || riding.isLivingEntity;
if (blockType == StateTypes.NETHER_PORTAL) {
player.intersectedWithNetherPortal = true;
}
if (!onlyApplyVelocity && blockType == StateTypes.COBWEB) {
if (stuckEntityIsLiving && player.compensatedEntities.hasPotionEffect(PotionTypes.WEAVING)) {
player.stuckSpeedMultiplier = StuckSpeed.COBWEB_WEAVING;
} else {
player.stuckSpeedMultiplier = StuckSpeed.COBWEB;
}
}
if (!onlyApplyVelocity && stuckEntityIsLiving && blockType == StateTypes.SWEET_BERRY_BUSH
&& player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) {
player.stuckSpeedMultiplier = StuckSpeed.SWEET_BERRY_BUSH;
}
if (!onlyApplyVelocity && blockType == StateTypes.POWDER_SNOW && blockX == Math.floor(player.x) && blockY == Math.floor(player.y) && blockZ == Math.floor(player.z)
&& player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_17)) {
player.stuckSpeedMultiplier = StuckSpeed.POWDER_SNOW;
}
if (blockType == StateTypes.SOUL_SAND && player.getClientVersion().isOlderThan(ClientVersion.V_1_15)) {
clientVelocity.setX(clientVelocity.getX() * 0.4D);
clientVelocity.setZ(clientVelocity.getZ() * 0.4D);
}
if (!onlyApplyVelocity && blockType == StateTypes.LAVA && player.getClientVersion().isOlderThan(ClientVersion.V_1_16) && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14)) {
player.wasTouchingLava = true;
}
if (blockType == StateTypes.BUBBLE_COLUMN && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_13) && magic) {
WrappedBlockState blockAbove = player.compensatedWorld.getBlock(blockX, blockY + 1, blockZ);
if (player.inVehicle() && player.compensatedEntities.self.getRiding().isBoat) {
if (!blockAbove.getType().isAir()) {
if (block.isDrag()) {
clientVelocity.setY(Math.max(-0.3D, clientVelocity.getY() - 0.03D));
} else {
clientVelocity.setY(Math.min(0.7D, clientVelocity.getY() + 0.06D));
}
}
} else {
if (blockAbove.getType().isAir()) {
if (block.isDrag()) {
clientVelocity.setY(Math.max(-0.9D, clientVelocity.getY() - 0.03D));
} else {
clientVelocity.setY(Math.min(1.8D, clientVelocity.getY() + 0.1D));
}
} else {
if (block.isDrag()) {
clientVelocity.setY(Math.max(-0.3D, clientVelocity.getY() - 0.03D));
} else {
clientVelocity.setY(Math.min(0.7D, clientVelocity.getY() + 0.06D));
}
}
}
// Reset fall distance inside bubble column
if (!onlyApplyVelocity) player.fallDistance = 0;
}
if (blockType == StateTypes.HONEY_BLOCK && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_15)) {
if (isSlidingDown(clientVelocity, player, blockX, blockY, blockZ)) {
if (getOldDeltaY(player, clientVelocity.getY()) < -0.13D) {
double d0 = -0.05 / getOldDeltaY(player, clientVelocity.getY());
clientVelocity.setX(clientVelocity.getX() * d0);
clientVelocity.setY(getNewDeltaY(player, -0.05D));
clientVelocity.setZ(clientVelocity.getZ() * d0);
} else {
clientVelocity.setY(getNewDeltaY(player, -0.05D));
}
}
// If honey sliding, fall distance is 0
if (!onlyApplyVelocity) player.fallDistance = 0;
}
}
// Implementation of Collisions#handleInsideBlocks for >= 1.21.2
public static void applyEffectsFromBlocks(GrimPlayer player) {
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_21_2)) {
return;
}
// Reset stuck speed so it can update
if (player.stuckSpeedMultiplier.getX() < 0.99) {
player.uncertaintyHandler.lastStuckSpeedMultiplier.reset();
}
player.resetStuckSpeedMultiplier();
player.finalMovementsThisTick.clear();
Vector3d from = new Vector3d(player.lastX, player.lastY, player.lastZ);
Vector3d to = new Vector3d(player.x, player.y, player.z);
ClientVersion clientVersion = player.getClientVersion();
if (clientVersion.isOlderThan(ClientVersion.V_1_21_5)) {
player.finalMovementsThisTick.add(new GrimPlayer.Movement(from, to));
} else if (clientVersion.isNewerThanOrEquals(ClientVersion.V_1_21_5)) {
player.finalMovementsThisTick.addAll(player.movementThisTick);
player.movementThisTick.clear();
if (player.finalMovementsThisTick.isEmpty()) {
player.finalMovementsThisTick.add(new GrimPlayer.Movement(from, to));
} else if (player.finalMovementsThisTick.get(player.finalMovementsThisTick.size() - 1).to().distanceSquared(to) > 9.9999994E-11F) {
player.finalMovementsThisTick.add(new GrimPlayer.Movement(player.finalMovementsThisTick.get(player.finalMovementsThisTick.size() - 1).to(), to));
}
}
Collisions.resolveBlockEffects(player, player.finalMovementsThisTick);
if (player.stuckSpeedMultiplier.getX() < 0.9) {
// Reset fall distance if stuck in block
player.fallDistance = 0;
}
// Flying players are not affected by cobwebs/sweet berry bushes
if (player.isFlying) {
player.stuckSpeedMultiplier = StuckSpeed.NONE;
}
}
public static void resolveBlockEffects(GrimPlayer player, Vector3d from, Vector3d to) {
Collisions.resolveBlockEffects(player, List.of(new GrimPlayer.Movement(from, to)));
}
public static void resolveBlockEffects(GrimPlayer player, List<GrimPlayer.Movement> movements) {
resolveBlockEffects(player, player.clientVelocity, false, movements);
}
public static void resolveBlockEffects(GrimPlayer player, Vector3dm clientVelocity, boolean onlyApplyVelocity, List<GrimPlayer.Movement> movements) {
ClientVersion version = player.getClientVersion();
BlockEffectsResolver resolver;
if (version == ClientVersion.V_1_21_2) {
resolver = BlockEffectsResolverV1_21_2.INSTANCE; // 1.21.2-1.21.3
} else if (version == ClientVersion.V_1_21_4) {
resolver = BlockEffectsResolverV1_21_4.INSTANCE; // 1.21.4
} else if (version == ClientVersion.V_1_21_5) {
resolver = BlockEffectsResolverV1_21_5.INSTANCE; // 1.21.5
} else if (version.isNewerThanOrEquals(ClientVersion.V_1_21_6) && version.isOlderThanOrEquals(ClientVersion.V_1_21_7)) {
resolver = BlockEffectsResolverV1_21_6.INSTANCE; // 1.21.6-1.21.8
} else {
resolver = BlockEffectsResolverV1_21_10.INSTANCE; // 1.21.10
}
resolver.applyEffectsFromBlocks(player, clientVelocity, onlyApplyVelocity, movements);
}
private static double getOldDeltaY(GrimPlayer player, double value) {
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_2) ? value / 0.98F + 0.08 : value;
}
private static double getNewDeltaY(GrimPlayer player, double value) {
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_2) ? (value - 0.08) * 0.98F : value;
}
private static boolean isSlidingDown(Vector3dm vector, GrimPlayer player, int locationX, int locationY,
int locationZ) {
if (player.onGround) {
return false;
} else if (player.y > (double) locationY + 0.9375D - COLLISION_EPSILON) {
return false;
} else if (getOldDeltaY(player, vector.getY()) >= -0.08D) {
return false;
} else {
double d0 = Math.abs(locationX + 0.5D - player.lastX);
double d1 = Math.abs(locationZ + 0.5D - player.lastZ);
// Calculate player width using bounding box, which will change while swimming or gliding
double d2 = 0.4375D + ((player.pose.width) / 2.0F);
return d0 + COLLISION_EPSILON > d2 || d1 + COLLISION_EPSILON > d2;
}
}
public static boolean suffocatesAt(GrimPlayer player, SimpleCollisionBox playerBB) {
// Blocks are stored in YZX order
for (int y = (int) Math.floor(playerBB.minY); y < Math.ceil(playerBB.maxY); y++) {
for (int z = (int) Math.floor(playerBB.minZ); z < Math.ceil(playerBB.maxZ); z++) {
for (int x = (int) Math.floor(playerBB.minX); x < Math.ceil(playerBB.maxX); x++) {
if (doesBlockSuffocate(player, x, y, z)) {
// Mojang re-added soul sand pushing by checking if the player is actually in the block
// (This is why from 1.14-1.15 soul sand didn't push)
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16)) {
WrappedBlockState data = player.compensatedWorld.getBlock(x, y, z);
CollisionBox box = CollisionData.getData(data.getType()).getMovementCollisionBox(player, player.getClientVersion(), data, x, y, z);
if (!box.isIntersected(playerBB)) continue;
}
return true;
}
}
}
}
return false;
}
public static boolean doesBlockSuffocate(GrimPlayer player, int x, int y, int z) {
WrappedBlockState data = player.compensatedWorld.getBlock(x, y, z);
StateType mat = data.getType();
// Optimization - all blocks that can suffocate must have a hitbox
if (!mat.isSolid()) return false;
// 1.13- players can not be pushed by blocks that can emit power, for some reason, while 1.14+ players can
if (mat == StateTypes.OBSERVER || mat == StateTypes.REDSTONE_BLOCK)
return player.getClientVersion().isNewerThan(ClientVersion.V_1_13_2);
// Tnt only pushes on 1.14+ clients
if (mat == StateTypes.TNT)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14);
// Farmland only pushes on 1.16+ clients
if (mat == StateTypes.FARMLAND)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16);
// 1.14-1.15 doesn't push with soul sand, the rest of the versions do
if (mat == StateTypes.SOUL_SAND)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16) || player.getClientVersion().isOlderThan(ClientVersion.V_1_14);
// 1.13 and below exempt piston bases, while 1.14+ look to see if they are a full block or not
if ((mat == StateTypes.PISTON || mat == StateTypes.STICKY_PISTON) && player.getClientVersion().isOlderThan(ClientVersion.V_1_14))
return false;
// 1.13 and below exempt ICE and FROSTED_ICE, 1.14 have them push
if (mat == StateTypes.ICE || mat == StateTypes.FROSTED_ICE)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14);
// I believe leaves and glass are consistently exempted across all versions
if (BlockTags.LEAVES.contains(mat) || BlockTags.GLASS_BLOCKS.contains(mat)) return false;
// 1.16 players are pushed by dirt paths, 1.8 players don't have this block, so it gets converted to a full block
if (mat == StateTypes.DIRT_PATH)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_16) || player.getClientVersion().isOlderThan(ClientVersion.V_1_9);
// Only 1.14+ players are pushed by beacons
if (mat == StateTypes.BEACON)
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_14);
// Thank god I already have the solid blocking blacklist written, but all these are exempt
if (Materials.isSolidBlockingBlacklist(mat, player.getClientVersion())) return false;
CollisionBox box = CollisionData.getData(mat).getMovementCollisionBox(player, player.getClientVersion(), data, x, y, z);
return box.isFullBlock();
}
// Thanks Tuinity
public static boolean hasMaterial(GrimPlayer player, SimpleCollisionBox checkBox, @NotNull BlockAndPositionPredicate searchingFor) {
int minBlockX = (int) Math.floor(checkBox.minX);
int maxBlockX = (int) Math.floor(checkBox.maxX);
int minBlockY = (int) Math.floor(checkBox.minY);
int maxBlockY = (int) Math.floor(checkBox.maxY);
int minBlockZ = (int) Math.floor(checkBox.minZ);
int maxBlockZ = (int) Math.floor(checkBox.maxZ);
final int minSection = player.compensatedWorld.getMinHeight() >> 4;
final int minBlock = minSection << 4;
final int maxBlock = player.compensatedWorld.getMaxHeight() - 1;
int minChunkX = minBlockX >> 4;
int maxChunkX = maxBlockX >> 4;
int minChunkZ = minBlockZ >> 4;
int maxChunkZ = maxBlockZ >> 4;
int minYIterate = Math.max(minBlock, minBlockY);
int maxYIterate = Math.min(maxBlock, maxBlockY);
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
int minZ = currChunkZ == minChunkZ ? minBlockZ & 15 : 0; // coordinate in chunk
int maxZ = currChunkZ == maxChunkZ ? maxBlockZ & 15 : 15; // coordinate in chunk
for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
int minX = currChunkX == minChunkX ? minBlockX & 15 : 0; // coordinate in chunk
int maxX = currChunkX == maxChunkX ? maxBlockX & 15 : 15; // coordinate in chunk
int chunkXGlobalPos = currChunkX << 4;
int chunkZGlobalPos = currChunkZ << 4;
Column chunk = player.compensatedWorld.getChunk(currChunkX, currChunkZ);
if (chunk == null) continue;
BaseChunk[] sections = chunk.chunks();
for (int y = minYIterate; y <= maxYIterate; ++y) {
BaseChunk section = sections[(y >> 4) - minSection];
if (section == null || (IS_FOURTEEN && section.isEmpty())) { // Check for empty on 1.13+ servers
// empty
// skip to next section
y = (y & ~(15)) + 15; // increment by 15: iterator loop increments by the extra one
continue;
}
for (int currZ = minZ; currZ <= maxZ; ++currZ) {
for (int currX = minX; currX <= maxX; ++currX) {
int x = currX | chunkXGlobalPos;
int z = currZ | chunkZGlobalPos;
WrappedBlockState data = section.get(CompensatedWorld.blockVersion, x & 0xF, y & 0xF, z & 0xF, false);
if (searchingFor.test(data, x, y, z))
return true;
}
}
}
}
}
return false;
}
// Thanks Tuinity
public static void forEachCollisionBox(@NotNull GrimPlayer player, @NotNull SimpleCollisionBox checkBox, @NotNull BlockAndPositionConsumer searchingFor) {
int minBlockX = (int) Math.floor(checkBox.minX - COLLISION_EPSILON) - 1;
int maxBlockX = (int) Math.floor(checkBox.maxX + COLLISION_EPSILON) + 1;
int minBlockY = (int) Math.floor(checkBox.minY - COLLISION_EPSILON) - 1;
int maxBlockY = (int) Math.floor(checkBox.maxY + COLLISION_EPSILON) + 1;
int minBlockZ = (int) Math.floor(checkBox.minZ - COLLISION_EPSILON) - 1;
int maxBlockZ = (int) Math.floor(checkBox.maxZ + COLLISION_EPSILON) + 1;
final int minSection = player.compensatedWorld.getMinHeight() >> 4;
final int minBlock = minSection << 4;
final int maxBlock = player.compensatedWorld.getMaxHeight() - 1;
int minChunkX = minBlockX >> 4;
int maxChunkX = maxBlockX >> 4;
int minChunkZ = minBlockZ >> 4;
int maxChunkZ = maxBlockZ >> 4;
int minYIterate = Math.max(minBlock, minBlockY);
int maxYIterate = Math.min(maxBlock, maxBlockY);
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
int minZ = currChunkZ == minChunkZ ? minBlockZ & 15 : 0; // coordinate in chunk
int maxZ = currChunkZ == maxChunkZ ? maxBlockZ & 15 : 15; // coordinate in chunk
for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
int minX = currChunkX == minChunkX ? minBlockX & 15 : 0; // coordinate in chunk
int maxX = currChunkX == maxChunkX ? maxBlockX & 15 : 15; // coordinate in chunk
int chunkXGlobalPos = currChunkX << 4;
int chunkZGlobalPos = currChunkZ << 4;
Column chunk = player.compensatedWorld.getChunk(currChunkX, currChunkZ);
if (chunk == null) continue;
BaseChunk[] sections = chunk.chunks();
for (int y = minYIterate; y <= maxYIterate; ++y) {
BaseChunk section = sections[(y >> 4) - minSection];
if (section == null || (IS_FOURTEEN && section.isEmpty())) { // Check for empty on 1.13+ servers
// empty
// skip to next section
y = (y & ~(15)) + 15; // increment by 15: iterator loop increments by the extra one
continue;
}
for (int currZ = minZ; currZ <= maxZ; ++currZ) {
for (int currX = minX; currX <= maxX; ++currX) {
int x = currX | chunkXGlobalPos;
int z = currZ | chunkZGlobalPos;
WrappedBlockState data = section.get(CompensatedWorld.blockVersion, x & 0xF, y & 0xF, z & 0xF, false);
// Works on both legacy and modern! Faster than checking for material types, most common case
if (data.getGlobalId() == 0) continue;
// Thanks SpottedLeaf for this optimization, I took edgeCount from Tuinity
int edgeCount = ((x == minBlockX || x == maxBlockX) ? 1 : 0) +
((y == minBlockY || y == maxBlockY) ? 1 : 0) +
((z == minBlockZ || z == maxBlockZ) ? 1 : 0);
final StateType type = data.getType();
if (edgeCount != 3 && (edgeCount != 1 || Materials.isShapeExceedsCube(type))
&& (edgeCount != 2 || type == StateTypes.PISTON_HEAD)) {
final CollisionBox collisionBox = CollisionData.getData(type).getMovementCollisionBox(player, player.getClientVersion(), data, x, y, z);
if (collisionBox.isIntersected(checkBox)) {
searchingFor.accept(data, x, y, z);
}
}
}
}
}
}
}
}
public static boolean onClimbable(GrimPlayer player, double x, double y, double z) {
WrappedBlockState blockState = player.compensatedWorld.getBlock(x, y, z);
StateType blockMaterial = blockState.getType();
if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_11) &&
player.isGliding && BlockTags.CAN_GLIDE_THROUGH.contains(blockMaterial)) {
return false;
}
// ViaVersion replacement block -> glow berry vines (cave vines) -> fern
if (blockMaterial == StateTypes.CAVE_VINES || blockMaterial == StateTypes.CAVE_VINES_PLANT) {
return player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_17);
}
if (player.tagManager.block(SyncedTags.CLIMBABLE).contains(blockMaterial)) {
return true;
}
// ViaVersion replacement block -> sweet berry bush to vines
if (blockMaterial == StateTypes.SWEET_BERRY_BUSH && player.getClientVersion().isOlderThan(ClientVersion.V_1_14)) {
return true;
}
return trapdoorUsableAsLadder(player, x, y, z, blockState);
}
public static boolean trapdoorUsableAsLadder(GrimPlayer player, double x, double y, double z, WrappedBlockState blockData) {
if (!BlockTags.TRAPDOORS.contains(blockData.getType())) return false;
// Feature implemented in 1.9
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) return false;
if (blockData.isOpen()) {
WrappedBlockState blockBelow = player.compensatedWorld.getBlock(x, y - 1, z);
if (blockBelow.getType() == StateTypes.LADDER) {
return blockData.getFacing() == blockBelow.getFacing();
}
}
return false;
}
public enum Axis {
X {
@Override
public double get(Vector3d vector) {
return vector.getX();
}
@Override
public int get(Vector3i vector) {
return vector.getX();
}
@Override
public double choose(double x, double y, double z) {
return x;
}
@Override
public int choose(int x, int y, int z) {
return x;
}
@Override
public Direction getPositive() {
return Direction.EAST;
}
@Override
public Direction getNegative() {
return Direction.WEST;
}
},
Y {
@Override
public double get(Vector3d vector) {
return vector.getY();
}
@Override
public int get(Vector3i vector) {
return vector.getY();
}
@Override
public double choose(double x, double y, double z) {
return y;
}
@Override
public int choose(int x, int y, int z) {
return y;
}
@Override
public Direction getPositive() {
return Direction.UP;
}
@Override
public Direction getNegative() {
return Direction.DOWN;
}
},
Z {
@Override
public double get(Vector3d vector) {
return vector.getZ();
}
@Override
public int get(Vector3i vector) {
return vector.getZ();
}
@Override
public double choose(double x, double y, double z) {
return z;
}
@Override
public int choose(int x, int y, int z) {
return z;
}
@Override
public Direction getPositive() {
return Direction.SOUTH;
}
@Override
public Direction getNegative() {
return Direction.NORTH;
}
};
public abstract double get(Vector3d vector);
public abstract int get(Vector3i vector);
public abstract double choose(double x, double y, double z);
public abstract int choose(int x, int y, int z);
public abstract Direction getPositive();
public abstract Direction getNegative();
}
}
// NOTE (AI): The border logic is addWorldBorder (lines 212-255), consumed by getCollisionBoxes at line 261. The block is the full 1012-line collision file because addWorldBorder is part of the shared collision pipeline.Decode the border packet family into the immutable border model that intave's movement simulation runs against.
A packet reader registered for all seven border packet ids (WORLD_BORDER, SET_BORDER_CENTER, SET_BORDER_SIZE, SET_BORDER_LERP_SIZE, SET_BORDER_WARNING_DELAY, SET_BORDER_WARNING_DISTANCE, INITIALIZE_BORDER). updated() maps the packet type to an UpdateType, reads the doubles and longs out of the ProtocolLib container (with legacy 1.8 offset handling for the action packet), and returns a new WorldBorder: center updates rebuild with a new center, size updates set the diameter, lerp updates build a MovingWorldBorder with the transition time, and INITIALIZE applies all four. MovementDispatcher.sentWorldBorderUpdate (lines 803-812) feeds the result into the movement metadata, and the simulation environment exposes it through border().
// ===== FILE: intave-intave, src/main/java/de/jpx3/intave/packet/reader/WorldBorderReader.java =====
/*
* Copyright 2026 Intave
*
* This software is licensed under the PolyForm Perimeter License 1.0.0.
* You may use this software for any purpose, except for providing to
* others any product that competes with the software.
*
* A copy of the license is available at:
* https://polyformproject.org/licenses/perimeter/1.0.0/
*/
package de.jpx3.intave.packet.reader;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import de.jpx3.intave.share.Position;
import de.jpx3.intave.world.border.WorldBorder;
import org.jetbrains.annotations.NotNull;
import static de.jpx3.intave.packet.reader.WorldBorderReader.UpdateType.INITIALIZE;
public final class WorldBorderReader extends AbstractPacketReader {
public @NotNull WorldBorder updated(@NotNull WorldBorder worldBorder) {
if (type().updatesCenter()) {
worldBorder = worldBorder.withCenterAt(center());
}
if (type().updatesRawSize()) {
worldBorder = worldBorder.withSize(size());
}
if (type().updatesLerpSize()) {
worldBorder = worldBorder.withLerpingSize(
oldSize(), newSize(), lerpTime()
);
}
if (type().updatesAbsoluteMaxSize()) {
worldBorder = worldBorder.withAbsoluteMaxSize(absoluteMaxSize());
}
return worldBorder;
}
private Position center() {
UpdateType type = type();
if (type.updatesCenter()) {
StructureModifier<Double> doubles = packet().getDoubles();
double centerX = doubles.read(0);
double centerZ = doubles.read(1);
return new Position(centerX, 0, centerZ);
}
throw new IllegalStateException("Cannot get center for update type: " + type);
}
private double size() {
UpdateType type = type();
if (type.updatesRawSize()) {
boolean legacyPacket = packet().getType() == PacketType.Play.Server.WORLD_BORDER;
return (float) (double) packet().getDoubles().read(legacyPacket ? 2 : 0);
}
throw new IllegalStateException("Cannot get size for update type: " + type);
}
private double oldSize() {
UpdateType type = type();
if (type.updatesLerpSize()) {
boolean legacyPacket = packet().getType() == PacketType.Play.Server.WORLD_BORDER;
int initializeOffset = type() == INITIALIZE ? 2 : 0;
return (float) (double) packet().getDoubles().read(legacyPacket ? 3 : initializeOffset);
}
throw new IllegalStateException("Cannot get old size for update type: " + type);
}
private double newSize() {
UpdateType type = type();
if (type.updatesLerpSize()) {
boolean legacyPacket = packet().getType() == PacketType.Play.Server.WORLD_BORDER;
int initializeOffset = type() == INITIALIZE ? 2 : 0;
return (float) (double) packet().getDoubles().read(legacyPacket ? 2 : initializeOffset + 1);
}
throw new IllegalStateException("Cannot get new size for update type: " + type);
}
private int absoluteMaxSize() {
UpdateType type = type();
if (type.updatesAbsoluteMaxSize()) {
return packet().getIntegers().read(0);
}
throw new IllegalStateException("Cannot get absolute max size for update type: " + type);
}
private long lerpTime() {
UpdateType type = type();
if (type.updatesLerpSize()) {
return packet().getLongs().read(0);
}
throw new IllegalStateException("Cannot get lerp time for update type: " + type);
}
private UpdateType type() {
PacketContainer packet = packet();
PacketType type = packet.getType();
if (type == PacketType.Play.Server.WORLD_BORDER) {
return packet.getEnumModifier(UpdateType.class, 0).read(0);
} else if (type == PacketType.Play.Server.SET_BORDER_LERP_SIZE) {
return UpdateType.LERP_SIZE;
} else if (type == PacketType.Play.Server.INITIALIZE_BORDER) {
return INITIALIZE;
} else if (type == PacketType.Play.Server.SET_BORDER_CENTER) {
return UpdateType.SET_CENTER;
} else if (type == PacketType.Play.Server.SET_BORDER_SIZE) {
return UpdateType.SET_SIZE;
} else if (type == PacketType.Play.Server.SET_BORDER_WARNING_DISTANCE) {
return UpdateType.SET_WARNING_BLOCKS;
} else if (type == PacketType.Play.Server.SET_BORDER_WARNING_DELAY) {
return UpdateType.SET_WARNING_TIME;
} else {
throw new IllegalStateException("Unknown world border packet type: " + type);
}
}
public enum UpdateType {
SET_SIZE,
LERP_SIZE,
SET_CENTER,
INITIALIZE,
SET_WARNING_TIME,
SET_WARNING_BLOCKS;
public boolean updatesCenter() {
return this == SET_CENTER || this == INITIALIZE;
}
public boolean updatesRawSize() {
return this == SET_SIZE || this == INITIALIZE;
}
public boolean updatesLerpSize() {
return this == LERP_SIZE || this == INITIALIZE;
}
public boolean updatesAbsoluteMaxSize() {
return this == INITIALIZE;
}
}
}
// NOTE (AI): The S44 handling is the whole file. PacketReaders.java lines 82-88 register all seven border packet ids to this reader; MovementDispatcher.java lines 803-812 route the decoded border into the movement metadata; the border model lives in de.jpx3.intave.world.border (StaticWorldBorder and MovingWorldBorder).Related Packets
Wiki Cross-Reference
Warning time is measured in seconds and warning distance in blocks, matching the units of the worldborder warning time and warning distance commands.
MCP 1.8.9 S44PacketWorldBorder implements Packet
1.8.9 callers: ServerConfigurationManager.onSizeChanged sends new S44PacketWorldBorder (line 231): https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/server/management/ServerConfigurationManager.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.