Skip to content

Commit

Permalink
Optimized speed check
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 2, 2023
1 parent 896fb64 commit 4462df5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions patches/server/0004-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ index a53514f2c510b29f596c361de7bc0b405c27e964..269c7ba0707db4fdc45a70000e0be892
.withRequiredArg()
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..6e1124d38cd910216cf9c9d9a289078eea043aa5
index 0000000000000000000000000000000000000000..11b51a22e3441d7118e29178db6ed3529be52d60
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,787 @@
Expand Down Expand Up @@ -731,7 +731,7 @@ index 0000000000000000000000000000000000000000..6e1124d38cd910216cf9c9d9a289078e
+
+ public static boolean elytraAeronauticsNoChunk = false;
+ public static double elytraAeronauticsNoChunkHeight = 500.0D;
+ public static double elytraAeronauticsNoChunkSpeed = 50.0D;
+ public static double elytraAeronauticsNoChunkSpeed = -1.0D;
+ public static boolean elytraAeronauticsNoChunkMes = true;
+ public static String elytraAeronauticsNoChunkStartMes = "Flight enter cruise mode";
+ public static String elytraAeronauticsNoChunkEndMes = "Flight exit cruise mode";
Expand Down
19 changes: 16 additions & 3 deletions patches/server/0076-Elytra-aeronautics-no-chunk-load.patch
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ index e122a633bc3e26f7a98149f66da8a9e8359c6faf..3b03de0fe88c76b21d58472139b648a9
int i = SectionPos.blockToSectionCoord(player.getBlockX());
int j = SectionPos.blockToSectionCoord(player.getBlockZ());
SectionPos sectionposition = player.getLastSectionPos();
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 6d40c0b3fbccaa86207603f38b073f36df3880e6..d5659ed1f59967060b4e511a571a7f3765b25c00 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -653,7 +653,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player

// Paper start - Prevent moving into unloaded chunks
- if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (
+ if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && !player.elytraAeronauticsNoChunk && ( // Leaves - no chunk load
!worldserver.areChunksLoadedForMove(this.player.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(this.player.position()))) ||
!worldserver.areChunksLoadedForMove(entity.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(entity.position())))
)) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e9111c5f018815f70f171e606d6a7355be075e39..d8010922d90c8e6aa3951978001b49fe1172da53 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
Expand Down Expand Up @@ -85,7 +98,7 @@ index 352ef747063f9cb1a26bf906f8cb52351ec4ae1d..25e00eaf8971da42ee26ce3f0e3ea17c
public boolean fauxSleeping;
diff --git a/src/main/java/top/leavesmc/leaves/util/ElytraAeronauticsHelper.java b/src/main/java/top/leavesmc/leaves/util/ElytraAeronauticsHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..574a6b7f0d83beff15078ef0af32c40af9455ce5
index 0000000000000000000000000000000000000000..fc25e2f960a2936e656541c0fe13745e62451179
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/util/ElytraAeronauticsHelper.java
@@ -0,0 +1,39 @@
Expand All @@ -103,8 +116,8 @@ index 0000000000000000000000000000000000000000..574a6b7f0d83beff15078ef0af32c40a
+
+ public static void flightBehaviour(Player player, Vec3 velocity) {
+ if (LeavesConfig.elytraAeronauticsNoChunk) {
+ double speed = velocity.horizontalDistanceSqr();
+ if (speed >= LeavesConfig.elytraAeronauticsNoChunkSpeed && player.getY() >= LeavesConfig.elytraAeronauticsNoChunkHeight) {
+ if ((LeavesConfig.elytraAeronauticsNoChunkSpeed <= 0.0D || velocity.horizontalDistanceSqr() >= LeavesConfig.elytraAeronauticsNoChunkSpeed)
+ && (LeavesConfig.elytraAeronauticsNoChunkHeight <= 0.0D || player.getY() >= LeavesConfig.elytraAeronauticsNoChunkHeight)) {
+ if (!player.elytraAeronauticsNoChunk) {
+ player.elytraAeronauticsNoChunk = true;
+ ServerPlayer serverPlayer = (ServerPlayer) player;
Expand Down

0 comments on commit 4462df5

Please sign in to comment.