Skip to content

Commit

Permalink
Fix crash, and rebase some patch
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jun 25, 2024
1 parent d06a408 commit 3c991d1
Show file tree
Hide file tree
Showing 87 changed files with 337 additions and 466 deletions.
10 changes: 6 additions & 4 deletions patches/server/0003-Delete-Timings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Subject: [PATCH] Delete Timings


diff --git a/src/main/java/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java
index 6b3cde6d4d1e63bec01f502f2027ee9fddac08aa..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644
deleted file mode 100644
index 6b3cde6d4d1e63bec01f502f2027ee9fddac08aa..0000000000000000000000000000000000000000
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package co.aikar.timings;
-
Expand Down Expand Up @@ -582,9 +583,10 @@ index 7620c72a4c243cbeea245203ce03a97cbfa7d922..00000000000000000000000000000000
- }
-}
diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
index 2f0d9b953802dee821cfde82d22b0567cce8ee91..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644
deleted file mode 100644
index 2f0d9b953802dee821cfde82d22b0567cce8ee91..0000000000000000000000000000000000000000
--- a/src/main/java/co/aikar/timings/WorldTimingsHandler.java
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package co.aikar.timings;
-
Expand Down
106 changes: 106 additions & 0 deletions patches/server/0004-Leaves-Server-Utils.patch
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,109 @@ index 0000000000000000000000000000000000000000..440c4d903e145229bc54eb5b6f3578fd
+ return backingMap.size();
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/util/MathUtils.java b/src/main/java/org/leavesmc/leaves/util/MathUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..a6a4fd61644815a7fb01ab1a5844a34f39e57e6d
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/util/MathUtils.java
@@ -0,0 +1,100 @@
+package org.leavesmc.leaves.util;
+
+import org.bukkit.util.NumberConversions;
+import org.bukkit.util.Vector;
+
+import java.util.regex.Pattern;
+
+public class MathUtils {
+ // Lag ?
+ public static void clean(Vector vector) {
+ if (!NumberConversions.isFinite(vector.getX())) vector.setX(0);
+ if (!NumberConversions.isFinite(vector.getY())) vector.setY(0);
+ if (!NumberConversions.isFinite(vector.getZ())) vector.setZ(0);
+ }
+
+ private static final Pattern numericPattern = Pattern.compile("^-?[1-9]\\d*$|^0$");
+
+ public static boolean isNumeric(String str) {
+ return numericPattern.matcher(str).matches();
+ }
+
+ public static float[] fetchYawPitch(Vector dir) {
+ double x = dir.getX();
+ double z = dir.getZ();
+
+ float[] out = new float[2];
+
+ if (x == 0.0D && z == 0.0D) {
+ out[1] = (float) (dir.getY() > 0.0D ? -90 : 90);
+ } else {
+ double theta = Math.atan2(-x, z);
+ out[0] = (float) Math.toDegrees((theta + 6.283185307179586D) % 6.283185307179586D);
+
+ double x2 = NumberConversions.square(x);
+ double z2 = NumberConversions.square(z);
+ double xz = Math.sqrt(x2 + z2);
+ out[1] = (float) Math.toDegrees(Math.atan(-dir.getY() / xz));
+ }
+
+ return out;
+ }
+
+ public static float fetchPitch(Vector dir) {
+ double x = dir.getX();
+ double z = dir.getZ();
+
+ float result;
+
+ if (x == 0.0D && z == 0.0D) {
+ result = (float) (dir.getY() > 0.0D ? -90 : 90);
+ } else {
+ double x2 = NumberConversions.square(x);
+ double z2 = NumberConversions.square(z);
+ double xz = Math.sqrt(x2 + z2);
+ result = (float) Math.toDegrees(Math.atan(-dir.getY() / xz));
+ }
+
+ return result;
+ }
+
+ public static Vector getDirection(double rotX, double rotY) {
+ Vector vector = new Vector();
+
+ rotX = Math.toRadians(rotX);
+ rotY = Math.toRadians(rotY);
+
+ double xz = Math.abs(Math.cos(rotY));
+
+ vector.setX(-Math.sin(rotX) * xz);
+ vector.setZ(Math.cos(rotX) * xz);
+ vector.setY(-Math.sin(rotY));
+
+ return vector;
+ }
+
+ private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
+
+ public static int floorLog2(int value) {
+ return ceilLog2(value) - (isPowerOfTwo(value) ? 0 : 1);
+ }
+
+ public static int ceilLog2(int value) {
+ value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
+ return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) ((long) value * 125613361L >> 27) & 31];
+ }
+
+ public static boolean isPowerOfTwo(int value) {
+ return value != 0 && (value & value - 1) == 0;
+ }
+
+ public static int smallestEncompassingPowerOfTwo(int value) {
+ int i = value - 1;
+ i |= i >> 1;
+ i |= i >> 2;
+ i |= i >> 4;
+ i |= i >> 8;
+ i |= i >> 16;
+ return i + 1;
+ }
+}
27 changes: 19 additions & 8 deletions patches/server/0006-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Leaves Server Config And Command


diff --git a/build.gradle.kts b/build.gradle.kts
index c46b46d10b37e60d1565273f7ca2560165165088..dcaeee69130a58f17ad59dd6e353a96e5875e89c 100644
index 5025c5df3ee6ed84106782e3f9228874bebe63ca..268193499b9f1fae0c01963e8004a3e7422f77ca 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -212,6 +212,14 @@ tasks.registerRunTask("runDevServer") {
Expand Down Expand Up @@ -97,10 +97,10 @@ index 459f47244bdfeab63b5f16d780b0291d36310de8..a872421bc3e67fdcc929f104f4b085fb
.withRequiredArg()
diff --git a/src/main/java/org/leavesmc/leaves/LeavesConfig.java b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..b6f1b823be544662c5cb6e42acde9e39a219b55e
index 0000000000000000000000000000000000000000..9676585f170ffdde3ab96382efd9a1de078536a2
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,916 @@
@@ -0,0 +1,922 @@
+package org.leavesmc.leaves;
+
+import com.destroystokyo.paper.util.SneakyThrow;
Expand Down Expand Up @@ -307,6 +307,12 @@ index 0000000000000000000000000000000000000000..b6f1b823be544662c5cb6e42acde9e39
+ }
+ }
+
+ @GlobalConfig(name = "use-action", category = {"modify", "fakeplayer"})
+ public static boolean fakeplayerUseAction = true;
+
+ @GlobalConfig(name = "modify-config", category = {"modify", "fakeplayer"})
+ public static boolean fakeplayerModifyConfig = false;
+
+ // Leaves end - modify - fakeplayer
+
+ // Leaves start - modify - minecraft-old
Expand Down Expand Up @@ -1019,10 +1025,10 @@ index 0000000000000000000000000000000000000000..b6f1b823be544662c5cb6e42acde9e39
+}
diff --git a/src/main/java/org/leavesmc/leaves/command/CommandArgument.java b/src/main/java/org/leavesmc/leaves/command/CommandArgument.java
new file mode 100644
index 0000000000000000000000000000000000000000..381cd8b33137a5b7dc688306b56805f35c57012a
index 0000000000000000000000000000000000000000..2f0e6671dd8bfe4f320eab92c5f5bbc10abc3b05
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/command/CommandArgument.java
@@ -0,0 +1,43 @@
@@ -0,0 +1,49 @@
+package org.leavesmc.leaves.command;
+
+import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -1057,6 +1063,12 @@ index 0000000000000000000000000000000000000000..381cd8b33137a5b7dc688306b56805f3
+ return this;
+ }
+
+ public CommandArgument setAllTabComplete(List<List<String>> tabComplete) {
+ this.tabComplete.clear();
+ this.tabComplete.addAll(tabComplete);
+ return this;
+ }
+
+ public CommandArgumentResult parse(int index, String @NotNull [] args) {
+ Object[] result = new Object[argumentTypes.size()];
+ Arrays.fill(result, null);
Expand All @@ -1068,10 +1080,10 @@ index 0000000000000000000000000000000000000000..381cd8b33137a5b7dc688306b56805f3
+}
diff --git a/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java b/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java
new file mode 100644
index 0000000000000000000000000000000000000000..e50ca0473ab4d40e2623ab15f8566276cc14f4e7
index 0000000000000000000000000000000000000000..6549037cf0bb8460fef8bef41d2335be079b9e9b
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java
@@ -0,0 +1,62 @@
@@ -0,0 +1,61 @@
+package org.leavesmc.leaves.command;
+
+import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -1132,7 +1144,6 @@ index 0000000000000000000000000000000000000000..e50ca0473ab4d40e2623ab15f8566276
+ return null;
+ }
+ }
+
+}
diff --git a/src/main/java/org/leavesmc/leaves/command/CommandArgumentType.java b/src/main/java/org/leavesmc/leaves/command/CommandArgumentType.java
new file mode 100644
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,35 @@ Subject: [PATCH] Make snowball and egg can knockback player


diff --git a/src/main/java/net/minecraft/world/entity/projectile/Snowball.java b/src/main/java/net/minecraft/world/entity/projectile/Snowball.java
index 2b4d206c0d31ba38d7b2af654bd420e85145d441..9711279772d1617395c6fc34ae0b4bea6a215fae 100644
index 2b4d206c0d31ba38d7b2af654bd420e85145d441..f1070a44cd51b8d611f64e7e30691de372d9567f 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Snowball.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Snowball.java
@@ -3,6 +3,7 @@ package net.minecraft.world.entity.projectile;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
+import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
@@ -61,6 +62,13 @@ public class Snowball extends ThrowableItemProjectile {
@@ -61,6 +61,13 @@ public class Snowball extends ThrowableItemProjectile {
int i = entity instanceof Blaze ? 3 : 0;

entity.hurt(this.damageSources().thrown(this, this.getOwner()), (float) i);
+
+ // Leaves start - make snowball can knockback player
+ if (org.leavesmc.leaves.LeavesConfig.snowballAndEggCanKnockback && entity instanceof ServerPlayer) {
+ entity.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
+ ((ServerPlayer) entity).knockback(0.4000000059604645D, this.getX() - entity.getX(), this.getZ() - entity.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE);
+ if (org.leavesmc.leaves.LeavesConfig.snowballAndEggCanKnockback && entity instanceof net.minecraft.server.level.ServerPlayer player) {
+ player.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
+ player.knockback(0.4000000059604645D, this.getX() - player.getX(), this.getZ() - player.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE);
+ }
+ // Leaves end - make snowball can knockback player
}

@Override
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownEgg.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownEgg.java
index dbd60cc8c39f5d2d4c77e2de4f2567e7fa456cd2..01a381678a489b3965b0cc9f0de79e5c5d5394f5 100644
index dbd60cc8c39f5d2d4c77e2de4f2567e7fa456cd2..2b8c8d0e813cd673f593dab49ecd4ee2d04dc6fa 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownEgg.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownEgg.java
@@ -49,7 +49,14 @@ public class ThrownEgg extends ThrowableItemProjectile {
@Override
@@ -50,6 +50,12 @@ public class ThrownEgg extends ThrowableItemProjectile {
protected void onHitEntity(EntityHitResult entityHitResult) {
super.onHitEntity(entityHitResult);
+ Entity entity = entityHitResult.getEntity(); // Leaves - make egg can knockback player
entityHitResult.getEntity().hurt(this.damageSources().thrown(this, this.getOwner()), 0.0F);
+ // Leaves start - make egg can knockback player
+ if (org.leavesmc.leaves.LeavesConfig.snowballAndEggCanKnockback && entity instanceof ServerPlayer) {
+ entity.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
+ ((ServerPlayer) entity).knockback(0.4000000059604645D, this.getX() - entity.getX(), this.getZ() - entity.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE);
+ if (org.leavesmc.leaves.LeavesConfig.snowballAndEggCanKnockback && entityHitResult.getEntity() instanceof ServerPlayer player) {
+ player.hurt(this.damageSources().thrown(this, this.getOwner()), 0.0000001F);
+ player.knockback(0.4000000059604645D, this.getX() - player.getX(), this.getZ() - player.getZ(), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.DAMAGE);
+ }
+ // Leaves end - make egg can knockback player
}
Expand Down
Loading

0 comments on commit 3c991d1

Please sign in to comment.