9
0
mirror of https://github.com/SparklyPower/SparklyPaper.git synced 2025-12-19 15:09:27 +00:00

Update to Paper 1.21.4 (post hard fork™️ edition)

This commit is contained in:
MrPowerGamerBR
2025-01-14 00:52:12 -03:00
parent 3e8eff82ea
commit 8e7b51f5d7
98 changed files with 3947 additions and 5536 deletions

View File

@@ -0,0 +1,86 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <git@mrpowergamerbr.com>
Date: Wed, 8 Jan 2025 22:48:04 -0300
Subject: [PATCH] Add PlayerPreMoveEvent
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index da190c2ab2080344dc11903aec51598af18d7556..f637d2be3d67a928ed7f78eaa7aa80cbea85a3e6 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1422,7 +1422,7 @@ public class ServerGamePacketListenerImpl
d3 = d - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
d4 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
d5 = d2 - this.lastGoodZ; // Paper - diff on change, used for checking large move vectors above
- boolean flag = d4 > 0.0;
+ boolean flag = d4 > 0.0; // SparklyPaper - diff on change, used to reset the fall distance, checks if d7 is > 0.0D (player is moving upwards)
if (this.player.onGround() && !packet.isOnGround() && flag) {
// Paper start - Add PlayerJumpEvent
org.bukkit.entity.Player player = this.getCraftPlayer();
@@ -1456,7 +1456,37 @@ public class ServerGamePacketListenerImpl
boolean flag1 = this.player.verticalCollisionBelow;
this.player.move(MoverType.PLAYER, new Vec3(d3, d4, d5));
- this.player.onGround = packet.isOnGround(); // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move
+ // SparklyPaper start - Add PlayerPreMoveEvent event
+ boolean isOnGround = packet.isOnGround();
+ boolean horizontalCollision = packet.horizontalCollision();
+ if (net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent.getHandlerList().getRegisteredListeners().length != 0) {
+ org.bukkit.entity.Player player = this.getCraftPlayer();
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
+ Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
+
+ // If the packet contains movement information then we update the To location with the correct XYZ.
+ if (packet.hasPos) {
+ to.setX(packet.x);
+ to.setY(packet.y);
+ to.setZ(packet.z);
+ }
+
+ // If the packet contains look information then we update the To location with the correct Yaw & Pitch.
+ if (packet.hasRot) {
+ to.setYaw(packet.yRot);
+ to.setPitch(packet.xRot);
+ }
+
+ net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent event = new net.sparklypower.sparklypaper.event.player.PlayerPreMoveEvent(player, from, to, packet.isOnGround(), packet.horizontalCollision(), flag);
+
+ if (event.callEvent()) {
+ isOnGround = event.isOnGround();
+ horizontalCollision = event.isHorizontalCollision();
+ flag = event.isResetFallDistance();
+ }
+ }
+ // SparklyPaper end
+ this.player.onGround = isOnGround; // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move // SparklyPaper - Add PlayerPreMoveEvent
boolean didCollide = toX != this.player.getX() || toY != this.player.getY() || toZ != this.player.getZ(); // Paper - needed here as the difference in Y can be reset - also note: this is only a guess at whether collisions took place, floating point errors can make this true when it shouldn't be...
// Paper start - prevent position desync
if (this.awaitingPositionFromClient != null) {
@@ -1590,15 +1620,15 @@ public class ServerGamePacketListenerImpl
&& this.noBlocksAround(this.player);
this.player.serverLevel().getChunkSource().move(this.player);
Vec3 vec3 = new Vec3(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z);
- this.player.setOnGroundWithMovement(packet.isOnGround(), packet.horizontalCollision(), vec3);
- this.player.doCheckFallDamage(vec3.x, vec3.y, vec3.z, packet.isOnGround());
+ this.player.setOnGroundWithMovement(isOnGround, horizontalCollision, vec3); // SparklyPaper - Add PlayerPreMoveEvent
+ this.player.doCheckFallDamage(vec3.x, vec3.y, vec3.z, isOnGround); // SparklyPaper - Add PlayerPreMoveEvent
this.player.recordMovementThroughBlocks(new Vec3(x, y, z), this.player.position());
this.handlePlayerKnownMovement(vec3);
if (flag) {
this.player.resetFallDistance();
}
- if (packet.isOnGround()
+ if (isOnGround // SparklyPaper - Add PlayerPreMoveEvent
|| this.player.hasLandedInLiquid()
|| this.player.onClimbable()
|| this.player.isSpectator()
@@ -1613,7 +1643,7 @@ public class ServerGamePacketListenerImpl
this.lastGoodZ = this.player.getZ();
} else {
this.internalTeleport(x, y, z, f, f1); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet.
- this.player.doCheckFallDamage(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z, packet.isOnGround());
+ this.player.doCheckFallDamage(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z, isOnGround); // SparklyPaper - Add PlayerPreMoveEvent
}
}
}