From a450f5087fa63a61dca16d4f16e8536810d05789 Mon Sep 17 00:00:00 2001 From: codestech <56263050+Codestech1@users.noreply.github.com> Date: Sat, 31 Oct 2026 12:25:43 +0100 Subject: [PATCH 1/2] Add EntityChangeChunkSectionEvent --- .../entity/EntityChangeChunkSectionEvent.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 paper-api/src/main/java/io/papermc/paper/event/entity/EntityChangeChunkSectionEvent.java diff --git a/paper-api/src/main/java/io/papermc/paper/event/entity/EntityChangeChunkSectionEvent.java b/paper-api/src/main/java/io/papermc/paper/event/entity/EntityChangeChunkSectionEvent.java new file mode 100644 index 000000000000..0adcdcaf2077 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/event/entity/EntityChangeChunkSectionEvent.java @@ -0,0 +1,64 @@ +package io.papermc.paper.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Called when a registered entity moves to another chunk section. + */ +@NullMarked +public final class EntityChangeChunkSectionEvent extends EntityEvent { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final int previousX; + private final int previousY; + private final int previousZ; + + @ApiStatus.Internal + public EntityChangeChunkSectionEvent(Entity entity, int previousX, int previousY, int previousZ) { + super(entity); + this.previousX = previousX; + this.previousY = previousY; + this.previousZ = previousZ; + } + + /** + * Gets the {@code X} coordinate of the previous chunk section. + * + * @return the {@code X} coordinate + */ + public int getPreviousX() { + return this.previousX; + } + + /** + * Gets the {@code Y} coordinate of the previous chunk section. + * + * @return the {@code Y} coordinate + */ + public int getPreviousY() { + return this.previousY; + } + + /** + * Gets the {@code Z} coordinate of the previous chunk section. + * + * @return the {@code Z} coordinate + */ + public int getPreviousZ() { + return this.previousZ; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} From b4c523392cf33eaf1a0567f203bc987bac04cd61 Mon Sep 17 00:00:00 2001 From: codestech <56263050+Codestech1@users.noreply.github.com> Date: Sat, 31 Oct 2026 14:33:46 +0100 Subject: [PATCH 2/2] Actually call the EntityChangeChunkSectionEvent --- .../features/0002-Rewrite-dataconverter-system.patch | 6 +++--- .../features/0003-Moonrise-optimisation-patches.patch | 6 +++--- .../spottedleaf/moonrise/paper/PaperHooks.java.patch | 11 +++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/paper-server/patches/features/0002-Rewrite-dataconverter-system.patch b/paper-server/patches/features/0002-Rewrite-dataconverter-system.patch index 8acc12568102..490b899452fd 100644 --- a/paper-server/patches/features/0002-Rewrite-dataconverter-system.patch +++ b/paper-server/patches/features/0002-Rewrite-dataconverter-system.patch @@ -34050,10 +34050,10 @@ index 0000000000000000000000000000000000000000..863a9785c84af6e0c961ae32f0102b5d + } +} diff --git a/ca/spottedleaf/moonrise/paper/PaperHooks.java b/ca/spottedleaf/moonrise/paper/PaperHooks.java -index 7050fd6efb6fec16ba5657e254c54de1c671c9a0..aa14dd369d5d2c5c843839f289afdc39c200f0c3 100644 +index dd7210ad012bc555941c876dbbfc0a7963b2f1e6..733738c9d8ac9df0ec8260a37b33ad576c9dadea 100644 --- a/ca/spottedleaf/moonrise/paper/PaperHooks.java +++ b/ca/spottedleaf/moonrise/paper/PaperHooks.java -@@ -216,6 +216,11 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo +@@ -223,6 +223,11 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo @Override public CompoundTag convertNBT(final DSL.TypeReference type, final DataFixer dataFixer, final CompoundTag nbt, final int fromVersion, final int toVersion) { @@ -34065,7 +34065,7 @@ index 7050fd6efb6fec16ba5657e254c54de1c671c9a0..aa14dd369d5d2c5c843839f289afdc39 return (CompoundTag)dataFixer.update( type, new Dynamic<>(NbtOps.INSTANCE, nbt), fromVersion, toVersion ).getValue(); -@@ -257,4 +262,4 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo +@@ -264,4 +269,4 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo public boolean addTicketForEnderPearls(final ServerLevel world) { return !world.paperConfig().misc.legacyEnderPearlBehavior; } diff --git a/paper-server/patches/features/0003-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0003-Moonrise-optimisation-patches.patch index a94fd82ee50c..34f952166d6c 100644 --- a/paper-server/patches/features/0003-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0003-Moonrise-optimisation-patches.patch @@ -300,7 +300,7 @@ index 0000000000000000000000000000000000000000..fff7a796a61542213bdaa417d44e25cd + } +} diff --git a/ca/spottedleaf/moonrise/paper/PaperHooks.java b/ca/spottedleaf/moonrise/paper/PaperHooks.java -index aa14dd369d5d2c5c843839f289afdc39c200f0c3..76f990f150f040b1ad6d7d5b91cfb34ebd6f436a 100644 +index 733738c9d8ac9df0ec8260a37b33ad576c9dadea..dc0cb8025405f17139acf62b35a66a8ac1176069 100644 --- a/ca/spottedleaf/moonrise/paper/PaperHooks.java +++ b/ca/spottedleaf/moonrise/paper/PaperHooks.java @@ -13,6 +13,7 @@ import net.minecraft.server.level.ChunkHolder; @@ -311,7 +311,7 @@ index aa14dd369d5d2c5c843839f289afdc39c200f0c3..76f990f150f040b1ad6d7d5b91cfb34e import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.boss.enderdragon.EnderDragonPart; import net.minecraft.world.level.BlockGetter; -@@ -150,7 +151,15 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo +@@ -157,7 +158,15 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo @Override public long[] getCounterTypesUncached(final net.minecraft.server.level.TicketType type) { @@ -328,7 +328,7 @@ index aa14dd369d5d2c5c843839f289afdc39c200f0c3..76f990f150f040b1ad6d7d5b91cfb34e } @Override -@@ -249,7 +258,7 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo +@@ -256,7 +265,7 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo @Override public void postLoadProtoChunk(final ServerLevel world, final ProtoChunk chunk) { try (final net.minecraft.util.ProblemReporter.ScopedCollector scopedCollector = new net.minecraft.util.ProblemReporter.ScopedCollector(chunk.problemPath(), LOGGER)) { diff --git a/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch b/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch index f78f7f79c550..6b23f85e9c47 100644 --- a/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch +++ b/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch @@ -1,6 +1,6 @@ --- /dev/null +++ b/ca/spottedleaf/moonrise/paper/PaperHooks.java -@@ -1,0 +_,260 @@ +@@ -1,0 +_,267 @@ +package ca.spottedleaf.moonrise.paper; + +import ca.spottedleaf.moonrise.common.PlatformHooks; @@ -143,7 +143,14 @@ + + @Override + public void entityMove(final Entity entity, final long oldSection, final long newSection) { -+ ++ // Paper start - Add EntityChangeChunkSectionEvent ++ new io.papermc.paper.event.entity.EntityChangeChunkSectionEvent( ++ entity.getBukkitEntity(), ++ ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkSectionX(oldSection), ++ ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkSectionY(oldSection), ++ ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkSectionZ(oldSection) ++ ).callEvent(); ++ // Paper end - Add EntityChangeChunkSectionEvent + } + + @Override