Skip to content

Commit

Permalink
fix: EntityBaseComponentImpl#teleportInDimension method shouldn't cal…
Browse files Browse the repository at this point in the history
…culate fall distance
  • Loading branch information
smartcmd committed Dec 23, 2024
1 parent 3ba4aa0 commit 5c909c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,12 @@ public boolean willBeSpawnedNextTick() {
}

public boolean setLocationAndCheckChunk(Location3fc newLoc) {
return setLocationAndCheckChunk(newLoc, true);
}

public boolean setLocationAndCheckChunk(Location3fc newLoc, boolean calculateFallDistance) {
if (checkChunk(this.location, newLoc)) {
setLocation(newLoc, true);
setLocation(newLoc, calculateFallDistance);
return true;
}
return false;
Expand Down Expand Up @@ -411,7 +415,9 @@ public void teleport(Location3fc target) {
}

var event = new EntityTeleportEvent(thisEntity, this.location, new Location3f(target));
if (!event.call()) return;
if (!event.call()) {
return;
}

target = event.getTo();
if (this.location.dimension == target.dimension()) {
Expand All @@ -427,7 +433,7 @@ protected void teleportInDimension(Location3fc target) {
// Ensure that the new chunk is loaded
target.dimension().getChunkService().getOrLoadChunkSync((int) target.x() >> 4, (int) target.z() >> 4);
// This method should always return true because we have loaded the chunk
setLocationAndCheckChunk(target);
setLocationAndCheckChunk(target, false);
broadcastMoveToViewers(target, true);
}

Expand Down Expand Up @@ -614,8 +620,12 @@ protected BedrockPacket createDeltaMovePacket(Location3fc newLoc, boolean telepo
pk.setHeadYaw((float) newLoc.headYaw());
locLastSent.headYaw = newLoc.headYaw();
}
if (onGround) pk.getFlags().add(ON_GROUND);
if (teleporting) pk.getFlags().add(TELEPORTING);
if (onGround) {
pk.getFlags().add(ON_GROUND);
}
if (teleporting) {
pk.getFlags().add(TELEPORTING);
}
return pk;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ protected void checkInteractDistance(EntityPlayer player) {

protected void updateBreakingTime(EntityPlayer player, long currentTime) {
var newBreakingTime = breakBlock.getBehavior().calculateBreakTime(breakBlock, player.getItemInHand(), player);
if (needBreakTime == newBreakingTime) return;
if (needBreakTime == newBreakingTime) {
return;
}

// Breaking time has changed, make adjustments
var timeLeft = stopBreakTime - currentTime;
stopBreakTime = currentTime + timeLeft * (needBreakTime / newBreakingTime);
Expand Down Expand Up @@ -255,7 +258,10 @@ public void handleSync(EntityPlayer player, PlayerAuthInputPacket packet, long r

@Override
public PacketSignal handleAsync(EntityPlayer player, PlayerAuthInputPacket packet, long receiveTime) {
if (notReadyForInput(player)) return PacketSignal.HANDLED;
if (notReadyForInput(player)) {
return PacketSignal.HANDLED;
}

// The pos which client sends to the server is higher than the actual coordinates (one base offset)
handleMovement(player, packet.getPosition().sub(0, player.getBaseOffset(), 0), packet.getRotation());
handleBlockAction(player, packet.getPlayerActions(), receiveTime);
Expand All @@ -270,7 +276,10 @@ protected void handleSingleItemStackRequest(EntityPlayer player, ItemStackReques
// We had no idea why the client still use PlayerAuthInputPacket to hold ItemStackRequest
// Instead of using ItemStackRequestPacket
// This seems only happen when player break a block (MineBlockAction)
if (request == null) return;
if (request == null) {
return;
}

var pk = new ItemStackRequestPacket();
pk.getRequests().add(request);
// Forward it to ItemStackRequestPacketProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ protected void handleClientMoveQueue() {

protected boolean updateEntityLocation(Entity entity, Location3fc newLoc) {
var event = new EntityMoveEvent(entity, entity.getLocation(), newLoc);
if (!event.call()) return false;
if (!event.call()) {
return false;
}

newLoc = event.getTo();

Expand Down

0 comments on commit 5c909c9

Please sign in to comment.