Compare commits

..

5 Commits

Author SHA1 Message Date
M2ke4U
1cecb38fee Merge pull request #46 from adabugra/fix/lobotomized-villagers-not-restocking
Fix: Lobotomized villagers not restocking
2025-02-01 08:36:39 +08:00
adabugra
78636dc0bd Fix lobotomized villagers not restocking 2025-02-01 00:12:32 +03:00
M2ke4U
cdb8ff1aba Merge pull request #45 from adabugra/feature/disable-moved-wrongly
Feature: Add Leaves Disable moved wrongly threshold
2025-02-01 01:09:01 +08:00
adabugra
f8f537423c Add Leaves Disable moved wrongly threshold 2025-01-31 19:19:15 +03:00
MrHua269
23fc8891ed Added missing NPE checks and make async teleport event position mutable 2025-01-31 22:26:43 +08:00
5 changed files with 129 additions and 16 deletions

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Add missing teleportation apis for folia
diff --git a/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65468dfc38
index 0000000000000000000000000000000000000000..4635a56c60c836675150faca51755dbe09543840
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java
@@ -0,0 +1,80 @@
@@ -0,0 +1,90 @@
+package me.earthme.luminol.api.entity;
+
+import org.apache.commons.lang3.Validate;
@@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65
+
+ private final Entity entity;
+ private final PlayerTeleportEvent.TeleportCause teleportCause;
+ private final Location destination;
+ private Location destination;
+
+ public EntityTeleportAsyncEvent(Entity entity, PlayerTeleportEvent.TeleportCause teleportCause, Location destination) {
+ Validate.notNull(entity, "entity cannot be a null value!");
@@ -70,6 +70,16 @@ index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65
+ return this.destination;
+ }
+
+ /**
+ * Set the destination of the teleport
+ * @param destination the destination
+ */
+ public void setDestination(Location destination) {
+ Validate.notNull(destination, "destination cannot be a null value!");
+
+ this.destination = destination;
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return HANDLERS;

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Purpur Lobotomize stuck villagers
diff --git a/net/minecraft/world/entity/npc/Villager.java b/net/minecraft/world/entity/npc/Villager.java
index 7ea74aeb905b95e5919d74df5fbc5e8f7a9985e3..d6e337ac8cf3d40f60a20b07826a4eee1c865bc3 100644
index 7ea74aeb905b95e5919d74df5fbc5e8f7a9985e3..b61da3d0d7d24b674cae155b95f7fab0669f4a20 100644
--- a/net/minecraft/world/entity/npc/Villager.java
+++ b/net/minecraft/world/entity/npc/Villager.java
@@ -193,6 +193,53 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
@@ -62,7 +62,7 @@ index 7ea74aeb905b95e5919d74df5fbc5e8f7a9985e3..d6e337ac8cf3d40f60a20b07826a4eee
@Override
public Brain<Villager> getBrain() {
return (Brain<Villager>)super.getBrain();
@@ -289,10 +336,18 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
@@ -289,11 +336,21 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
// Paper start - EAR 2
this.customServerAiStep(level, false);
}
@@ -71,6 +71,7 @@ index 7ea74aeb905b95e5919d74df5fbc5e8f7a9985e3..d6e337ac8cf3d40f60a20b07826a4eee
// Paper end - EAR 2
ProfilerFiller profilerFiller = Profiler.get();
profilerFiller.push("villagerBrain");
- if (!inactive) this.getBrain().tick(level, this); // Paper - EAR 2
+ // Purpur start
+ if (me.earthme.luminol.config.modules.optimizations.LobotomizeVillageConfig.villagerLobotomizeEnabled) {
+ // treat as inactive if lobotomized
@@ -79,6 +80,9 @@ index 7ea74aeb905b95e5919d74df5fbc5e8f7a9985e3..d6e337ac8cf3d40f60a20b07826a4eee
+ this.isLobotomized = false;
+ }
+ // Purpur end
if (!inactive) this.getBrain().tick(level, this); // Paper - EAR 2
+ if (!inactive) {
+ this.getBrain().tick(level, this); // Paper - EAR 2
+ } else if (this.isLobotomized && shouldRestock()) restock(); // Purpur - Lobotomize stuck villagers
profilerFiller.pop();
if (this.assignProfessionWhenSpawned) {
this.assignProfessionWhenSpawned = false;

View File

@@ -19,26 +19,46 @@ index 9fd3fe181df2ce6dbe695f6463d3940ac4c01167..822d401150d3764004b2570da828b4f6
);
});
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f3234953ba81 100644
index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..e41aef2b9e7204b35202d66eb17985e3731d9611 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4164,6 +4164,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4164,6 +4164,35 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// TODO any events that can modify go HERE
+ // Luminol start - Add missing teleportation apis
+ if (!new me.earthme.luminol.api.entity.EntityTeleportAsyncEvent(
+ org.bukkit.Location destinationLoc;
+
+ if (pitch == null) {
+ if (yaw == null) {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, Float.NaN, Float.NaN);
+ } else {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw, Float.NaN);
+ }
+ }else {
+ if (yaw == null) {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, Float.NaN, pitch);
+ }else {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw, pitch);
+ }
+ }
+
+ final me.earthme.luminol.api.entity.EntityTeleportAsyncEvent wrapped = new me.earthme.luminol.api.entity.EntityTeleportAsyncEvent(
+ this.getBukkitEntity(),
+ cause,
+ io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw ,pitch)
+ ).callEvent()) {
+ destinationLoc
+ );
+ if (!wrapped.callEvent()) {
+ return false;
+ }
+
+ destination = ((org.bukkit.craftbukkit.CraftWorld) wrapped.getDestination().getWorld()).getHandle();
+ pos = io.papermc.paper.util.MCUtil.toVec3(wrapped.getDestination());
+ // Luminol end
// check for same region
if (destination == this.level()) {
@@ -4280,7 +4289,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4280,7 +4309,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// we just select the spawn position
case END: {
if (destination.getTypeKey() == net.minecraft.world.level.dimension.LevelStem.END) {
@@ -60,7 +80,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// need to load chunks so we can create the platform
destination.moonrise$loadChunksAsync(
targetPos, 16, // load 16 blocks to be safe from block physics
@@ -4305,7 +4327,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4305,7 +4347,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
);
} else {
@@ -82,7 +102,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// need to load chunk for heightmap
destination.moonrise$loadChunksAsync(
spawnPos, 0,
@@ -4355,8 +4390,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4355,8 +4410,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
WorldBorder destinationBorder = destination.getWorldBorder();
double dimensionScale = net.minecraft.world.level.dimension.DimensionType.getTeleportationScale(origin.dimensionType(), destination.dimensionType());
@@ -104,7 +124,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
ca.spottedleaf.concurrentutil.completable.CallbackCompletable<BlockUtil.FoundRectangle> portalFound
= new ca.spottedleaf.concurrentutil.completable.CallbackCompletable<>();
@@ -4493,9 +4540,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4493,9 +4560,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (!this.canPortalAsync(destination, takePassengers)) {
return false;
}
@@ -124,7 +144,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// Kaiiju end
Vec3 initialPosition = this.position();
@@ -4569,6 +4625,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4569,6 +4645,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
tpComplete.accept(teleported);
}
// Kaiiju end

View File

@@ -0,0 +1,47 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: adabugra <57899270+adabugra@users.noreply.github.com>
Date: Fri, 31 Jan 2025 19:17:01 +0300
Subject: [PATCH] Leaves Disable moved wrongly threshold
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 9c4f1ecf3327c000d48bbcb8f2720b366a0a587d..d949bd77b10722611280ce5930f06dd83174d587 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -579,7 +579,7 @@ public class ServerGamePacketListenerImpl
return;
}
// Paper end - Prevent moving into unloaded chunks
- if (d7 - d6 > Math.max(100.0, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) {
+ if (!me.earthme.luminol.config.modules.misc.DisableMovedWronglyThreshold.enabled && d7 - d6 > Math.max(100.0, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && !this.isSingleplayerOwner()) { // Leaves - disable can
// CraftBukkit end
LOGGER.warn(
"{} (vehicle of {}) moved too quickly! {},{},{}", rootVehicle.getName().getString(), this.player.getName().getString(), d3, d4, d5
@@ -609,7 +609,7 @@ public class ServerGamePacketListenerImpl
d5 = d2 - rootVehicle.getZ();
d7 = d3 * d3 + d4 * d4 + d5 * d5;
boolean flag2 = false;
- if (d7 > org.spigotmc.SpigotConfig.movedWronglyThreshold) { // Spigot
+ if (!me.earthme.luminol.config.modules.misc.DisableMovedWronglyThreshold.enabled && d7 > org.spigotmc.SpigotConfig.movedWronglyThreshold) { // Spigot / Leaves - disable can
flag2 = true; // Paper - diff on change, this should be moved wrongly
LOGGER.warn("{} (vehicle of {}) moved wrongly! {}", rootVehicle.getName().getString(), this.player.getName().getString(), Math.sqrt(d7));
}
@@ -1434,7 +1434,7 @@ public class ServerGamePacketListenerImpl
if (this.shouldCheckPlayerMovement(isFallFlying)) {
float f2 = isFallFlying ? 300.0F : 100.0F;
- if (d7 - d6 > Math.max(f2, Mth.square(org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed))) {
+ if (!me.earthme.luminol.config.modules.misc.DisableMovedWronglyThreshold.enabled && d7 - d6 > Math.max(f2, Mth.square(org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed))) { // Leaves - disable can
// CraftBukkit end
// Paper start - Add fail move event
io.papermc.paper.event.player.PlayerFailMoveEvent event = fireFailMove(io.papermc.paper.event.player.PlayerFailMoveEvent.FailReason.MOVED_TOO_QUICKLY,
@@ -1506,7 +1506,8 @@ public class ServerGamePacketListenerImpl
d5 = d2 - this.player.getZ();
d7 = d3 * d3 + d4 * d4 + d5 * d5;
boolean movedWrongly = false; // Paper - Add fail move event; rename
- if (!this.player.isChangingDimension()
+ if (!me.earthme.luminol.config.modules.misc.DisableMovedWronglyThreshold.enabled // Leaves - disable can
+ && !this.player.isChangingDimension()
&& d7 > org.spigotmc.SpigotConfig.movedWronglyThreshold // Spigot
&& !this.player.isSleeping()
&& !this.player.gameMode.isCreative()

View File

@@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: adabugra <57899270+adabugra@users.noreply.github.com>
Date: Fri, 31 Jan 2025 19:17:02 +0300
Subject: [PATCH] Leaves Disable moved wrongly threshold
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/DisableMovedWronglyThreshold.java b/src/main/java/me/earthme/luminol/config/modules/misc/DisableMovedWronglyThreshold.java
new file mode 100644
index 0000000000000000000000000000000000000000..04d35765409781a31504e11c8ace44fd4dba2fe7
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/DisableMovedWronglyThreshold.java
@@ -0,0 +1,20 @@
+package me.earthme.luminol.config.modules.misc;
+
+import me.earthme.luminol.config.ConfigInfo;
+import me.earthme.luminol.config.EnumConfigCategory;
+import me.earthme.luminol.config.IConfigModule;
+
+public class DisableMovedWronglyThreshold implements IConfigModule {
+ @ConfigInfo(baseName = "enabled")
+ public static boolean enabled = false;
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.MISC;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "disable_moved_wrongly_threshold";
+ }
+}