Commit Graph
100 Commits
Author SHA1 Message Date
Spottedleaf c77d5f99f9 Fix MC-297591
Vanilla does not increment ticket timeouts if the chunk is
progressing in generation. They made this change in 1.21.6
so that the ender pearl ticket does not expire if the chunk
fails to generate before the timeout expires. Rather than
blindly adjusting the entire system behavior to fix this
small issue, we instead add non-expirable tickets to keep
ender pearls ticking.
2025-06-20 20:53:01 -07:00
Spottedleaf 8980ead7ea Directly walk text component after converting from JSON
It's important to convert the ItemStack present inside
the text component. The ItemStack nests TEXT_COMPONENT (written
book pages, custom name, ...) which would otherwise not be walked
since we have set a breakpoint at the version and moved the walker
to the next version step.

This fixes item names for hover events inside written book pages
failing to convert to NBT. This issue is also present on DFU.
2025-06-17 19:02:35 -07:00
Spottedleaf e4d7178a3c Implement WaypointTransmitter#isChunkVisible
The Vanilla chunk tracker on Moonrise always returns false. We need
to redirect to Moonrise's chunk loader.

https://github.com/Tuinity/Moonrise/commit/aef2b81d6e805f6af7d12d904fb88cdca1f721ca
2025-06-17 17:53:12 -07:00
Spottedleaf 1fcc4162d1 Implement FeatureHooks#isChunkSent for Moonrise chunk system
Need to use the player chunk loader, as that will contain the
sent chunks.
2025-06-17 17:47:50 -07:00
Spottedleaf 40d5d31c83 Fix recursively converting JSON Text Components
See https://github.com/PaperMC/DataConverter/commit/142ec80d2892a1978ccd0a85a8f99e704e4b3a8d
2025-06-17 16:38:01 -07:00
Spottedleaf 8318dcb74b Update DataConverter to 1.21.6-rc1
https://github.com/PaperMC/DataConverter/commit/b388a85809b1af6a762339d33c6afa6a4bd45d50

The 1.21.6 update will include better handling of legacy
hover events.
2025-06-17 10:00:54 -07:00
Spottedleaf b28d77b3e3 Update Moonrise to 1.21.6
https://github.com/Tuinity/Moonrise/commit/0451444abfd5f0011afe13054347c11a8f57de59
2025-06-17 09:46:59 -07:00
Spottedleaf 519e4224b1 Fix infinite loop in RegionFile IO
If an exception is thrown during decompress then the read process
would be started again, which of course would eventually throw in
the decompress process.
2025-06-09 02:46:34 -07:00
Spottedleaf 2ba1675c75 Replace deprecated Thread#getId usage with Thread#threadId 2025-05-29 04:59:52 -07:00
Spottedleaf 6f315356b6 Add MCUtil#toLocation from Folia
Helper methods to convert NMS world/position to Bukkit Location
2025-05-29 04:58:00 -07:00
Spottedleaf d2ad2e668d Add missing EntityLookup#getAllMapped from Moonrise
Not used but the sources should remain synced.
2025-05-07 18:31:25 -07:00
Spottedleaf 5f0b82925e Re-add chunk position check to regionfile recalculation patch 2025-04-19 12:40:59 -07:00
SpottedleafandSpottedleaf 1a7288aa05 Adjust unloaded chunk check for block digging 2025-03-09 11:11:02 -07:00
Spottedleaf 4519857817 Set old position / rotation for newly created entities
Set the old pos/rot to be the same as the current pos/rot for new
entities as the default value for the old pos/rot is zero.

Fixes https://github.com/PaperMC/Folia/issues/302
2025-03-08 06:33:29 -08:00
Spottedleaf 636ae0cd87 Add missing Paper comments to player movement patch 2025-02-24 21:32:39 -08:00
Spottedleaf 8927091a08 Do not record movement for vehicles/players unaffected by blocks
If the player is not affected by movement through blocks, then
storing the movement would eventually invoke logic to apply effects
caused by moving through such blocks. For example, moving through
a portal in spectator mode and then later switching to creative mode
would portal the player.
2025-02-02 11:16:59 -08:00
Spottedleaf 54b2e9d973 Add buffer to CraftWorld#warnUnsafeChunk
This allows plugins to access chunks slightly outside of the
max world border (such as ones which may be loaded naturally
by players) without tripping any logs.
2025-01-28 17:43:30 -08:00
Spottedleaf e2f0efd1af Remove nms.Entity#isChunkLoaded
This method was used pre 1.17 era where an Entity was explicitly
tied to a (then called) Chunk's entity slices. If an entity
was not inside a Chunk, then it was considered invalid as
it was not possible to save the entity.

In 1.17+, entities are now tied to a separately tracked entity
section management system. This system is far more reliable now
as it no longer requires a full chunk load to properly track
entities for saving. As a result, an Entity if inside the world
is always attached to some entity chunk section (except in rare
cases in Vanilla which are fixed in Moonrise).

As a result, whether the chunk the entity is in is loaded is no
longer an indication of whether they are tracked in the world
and we can reliably infer that the entity is correctly in the
world through the valid field alone.

Additionally drop the isInWorld() check, as valid=true implies
isInWorld=true. More importantly, the isInWorld() check invokes
getHandle which may trip a thread check on Folia. This will fix
World#getEntities() and friends exploding on Folia.

However, World#getEntities() on Folia still cannot reliably return
all entities in the world as actions such as cross-region
(not cross-world) teleporting will remove entities from the world.
2025-01-28 17:33:48 -08:00
Spottedleaf 1004374a83 Add further information to thread check errors
The entity data is more complete, which will help debug problems
on Folia.
2025-01-28 13:43:34 -08:00
Spottedleaf a392d475c2 Make Watchdog thread extend TickThread
This allows the watchdog thread to be seen as the
primary thread during shutdown, which prevents it
from tripping thread checks in various areas.

Fixes https://github.com/PaperMC/Paper/issues/12030
2025-01-27 16:35:23 -08:00
Spottedleaf 5a34bf0425 Correctly retrun true for empty input shapes in EntityGetter#isUnobstructed
Vanilla will return true for empty shapes, so we should as well.
2025-01-27 13:45:44 -08:00
Spottedleaf 88bbead13b Flush regionfiles on save configuration option
The windows file system does not write metadata unless
the FileChannel is explicitly flushed with metaData=true.

Note: Setting SYNC (not DSYNC) on the FileChannel does not appear
to write the metadata.

Specifically, we are interested in writing the last modified
timestamp so that fs watchers can detect when RegionFiles are
modified.
2025-01-22 11:55:39 -08:00
Spottedleaf 3ad3fbc19a Update to Concurrentutil 0.0.3 2025-01-11 06:28:56 -08:00
Spottedleaf 3d9ecc4e08 Log thread check parameters when the thread check fails
This provides additional debug information that may be useful.
2025-01-11 04:56:54 -08:00
Spottedleaf 6316a50dbd Make CraftServer#isPrimaryThread use TickThread check
This diff was accidentally dropped when updating to hard fork.

This diff importantly:
 - Does not return true if the async catcher is disabled
 - Does not return true during shutdown
 - Returns true for any instance of TickThread (enables
   watchdog and Folia threads to be considered main)
2025-01-11 00:13:45 -08:00
Spottedleaf 86378c66b3 Fix compile errors in Moonrise patch 2024-12-20 11:06:19 -08:00
Spottedleaf 48f34f8c90 Port CB changes from Moonrise patch 2024-12-20 10:52:51 -08:00
Spottedleaf 3af380ba08 Rebase on latest 2024-12-20 09:36:39 -08:00
Spottedleaf 45c905b928 Apply Moonrise patch minus CB diff 2024-12-20 09:22:42 -08:00
Spottedleaf 6186079231 Migrate ChunkSystem class to PaperHooks 2024-12-20 09:22:42 -08:00
Spottedleaf 0ed399bb41 Fix file paths in Moonrise patch 2024-12-20 09:22:42 -08:00
Spottedleaf f25d4a6b28 Fix indices/line numbers in Moonrise patch 2024-12-20 09:22:42 -08:00
Spottedleaf 09aea75701 Move Moonrise patch 2024-12-20 09:22:42 -08:00
Spottedleaf 7d29c678f7 Add in DataConverter 2024-12-16 09:39:14 -08:00
Spottedleaf df3be3f436 Fix patch line numbers and indices 2024-12-16 09:38:31 -08:00
Spottedleaf 9539f74ff0 Move rewrite dataconverter system patch 2024-12-16 09:38:31 -08:00
Spottedleaf 48be22a63e Use forkjoin thread pool for background executor
ForkJoin thread pools are specially handled with CompletableFuture.
Specifically, join()/get() calls will allow work stealing from other
fork join threads.

This fixes a deadlock where the worldgen worker is waiting on the
I/O worker.
2024-12-16 08:31:15 -08:00
Spottedleaf 8999170435 Apply coordinate offset only to VoxelShape
VoxelShape coordiantes generally are an integer + a sum of powers of
two between [-1, -3]. Most offsets are generally an integer. As
a result, applying an offset to the coordinates generally results
in an error of 0. However, coordinate inputs do not follow such
trends. Thus, when applying an offset to the coordinate input,
there may be some floating point error.

By applying the offset to the VoxelShape coordinates, we can
eliminate additional floating point error.

This change also fixes the inconsistency when using
the single AABB, as input coordinates were not offset
when using the single AABB as the single AABB is already
offset.

Fixes https://github.com/Tuinity/Moonrise/issues/81
This specific issue is caused by floating point error resulting
in the falling anvil's y position becoming around -8E-17 when it
should be 0.
While this is still very comfortably in the collision
epsilon (1.0E-7), this results in the falling anvil's y block
position to become -1 (as the block position is simply
the floor of the coordinate).
2024-12-04 02:52:58 -08:00
Spottedleaf 65ca4c1911 Fix several off-by-one errors in view distance calculations
1. For NearbyPlayers, we need to be using the view distance, and
   not the load distance (which is +1 of the view distance).
2. Correctly clamp tick distance to view distance. Since
   load distance is +1 of view distance, we need to subtract
   one from the load distance when clamping.

Additionally, add checks inside ViewDistances to ensure that
the inputs are in range to catch future errors.

Also, clamp simulation distance, as values < 0 or above
MAX_VIEW_DISTANCE do not make sense to configure.
2024-12-01 15:43:56 -08:00
Spottedleaf e9eb96862c Properly handle large values of spawnChunkRadius
The chunk system does not allow ticket levels below 0, so we need
to add tickets for each individual chunk instead.
2024-12-01 14:07:46 -08:00
Spottedleaf de3742283b Do not break when PlayerNaturallySpawnCreaturesEvent is cancelled
If there is a player nearby which had its event not cancelled,
then that should take precedence.
2024-12-01 13:53:04 -08:00
Spottedleaf 6788ba5e80 Fix non-null initialisation of context collision shape
Force LazyEntityCollisionContext#getEntity() to delegate

- By delegating when the entity is retrieved, we can correctly catch
  cases where the collision method is inspecting some entity state.

Adjust constant collision shape determination

- Our previous hack did not actually catch every case. For now,
  it will only assume a constant collision shape of EMPTY for
  air blocks.

Fixes https://github.com/PaperMC/Paper/issues/11697
2024-12-01 13:43:37 -08:00
Spottedleaf b37a391c02 Remove chunk save reattempt patch
This patch does not appear to be doing anything useful, and may
hide errors.

Currently, the save logic does not run through this path either
so it did not do anything.

Additionally, properly implement support for handling
RegionFileSizeException in Moonrise.
2024-11-28 17:39:40 -08:00
Spottedleaf c8457716c4 Use Player view distance for PlayerNaturallySpawnCreaturesEvent
The spigot view distance may not be correct, as the player may
have a specific view distance configured.
2024-11-28 14:22:32 -08:00
Spottedleaf cb0a972b9f Copy items when constructing ClientboundSetCursorItemPacket
Unlike ClientboundContainerSetSlotPacket, the constructor
itself does not copy the item. Thus, we need to pass a copy of
the item to the constructor.
2024-11-28 14:02:35 -08:00
Spottedleaf 63d0de648f Do not call modifyEntityTrackingRange on own range
The range is already modified, so this call will not do anything.
2024-11-27 12:19:39 -08:00
Spottedleaf f9b1c374e4 Replace SimpleRandom with (Simple)ThreadUnsafeRandom
ThreadUnsafeRandom is a random implementation that is
identical to LegacyRandomSource behaviourally, but
without the thread checks.

SimpleThreadUnsafeRandom is ThreadUnsafeRandom except with
its nextInt(int) function replaced with a faster
but more biased implementation when bound is very large.

Additionally, replace Level/Entity randoms with ThreadUnsafeRandom.
This avoids the expensive CAS logic at the expense of losing the
thread check.
2024-11-27 06:16:27 -08:00
Spottedleaf 22dea6efbd Add Server#isGlobalTickThread
This method should be present in Paper, not just in Folia, given
that the GlobalRegionScheduler is present.

Additonally, add Server#isOwnedByCurrentRegion(World, int, int, int, int)
for checking of a rectangle of chunks is owned by the current region.
2024-11-25 10:43:28 -08:00
Spottedleaf c9731fc93d Change MinecraftServer#pluginsBlockingSleep to be Set
A plugin should not be allowed to be added twice or more, as this
would require two or more remove calls to unset the pause block.
2024-11-25 10:13:34 -08:00
Spottedleaf c4ea377273 Add missing NotNull annotation for getChunksAtAsync cb param 2024-11-18 22:58:46 -08:00
Spottedleaf 70ccc97b36 Fix non block ticking chunks not sending block/light updates
Needed to redirect the getTickingChunk call in
broadcastChangedChunks to use the chunk to send method.
2024-11-18 22:48:40 -08:00
Spottedleaf f7086a34b5 Do not create unneccessary callback in ChunkTaskScheduler#scheduleChunkLoad
If the parameter has addTicket = false and onComplete = null,
then the loadCallback would do no work and as a result does
not need to be created.
2024-11-18 22:47:09 -08:00
Spottedleaf 989fd77808 Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.

Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.

Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.

Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.

Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-18 22:34:32 -08:00
Spottedleaf d0a2d92713 Fix experimental minecart collisions on sloped rails
We are supposed to ignore some collisions on the sloped
rail.
2024-11-14 21:01:04 -08:00
Spottedleaf 8480d09670 Handle corrupt light data gracefully
First, if the light data is not marked as correct, we should not be
parsing it in the first place. This will eliminate errors from
parsing possibly different versioned light data.

Secondly, if parsing the light data throws an exception (from
the SWMRNibbleArray constructor), then we can simply mark
the returned chunk as having incorrect light data - rather than
propagating the exception and causing the chunk to be re-generated.
2024-11-02 16:33:08 -07:00
Spottedleaf d6cb65cd0f Fix boats/minecarts not dropping when destroyed
Diff to clone the item was lost, which meant that the spawned
item was air.
2024-10-25 15:04:29 -07:00
Spottedleaf 9f5bf318a5 Add startup flag to disable gamerule limits
-DPaper.DisableGameRuleLimits=true will disable gamerule limits
2024-10-25 14:22:01 -07:00
Spottedleaf 352bf9dc13 Revert "Add max minecarft speed gamerule config"
This reverts commit c46650d89f.
2024-10-25 14:10:40 -07:00
Spottedleaf c46650d89f Add max minecarft speed gamerule config 2024-10-25 14:06:01 -07:00
Spottedleaf c0a178dc45 Fix MSPT command
Used wrong variable for tick length
2024-10-25 13:19:27 -07:00
Spottedleaf 0fc6c032fb Fix Anti-Xray using wrong data in chunk deserialize 2024-10-25 12:57:20 -07:00
Spottedleaf 97d6e76ee5 fix compile issues 2024-10-25 12:47:52 -07:00
Spottedleaf 3d5706bf30 Rebase fixups 2024-10-25 12:24:15 -07:00
Spottedleaf 9b124dba9b Review patch-to-patch diff
Looks OK
2024-10-25 12:11:20 -07:00
Spottedleaf d83a56b430 Fix compile issues 2024-10-25 11:46:53 -07:00
Spottedleaf 1d63b06b5e Finish rebase 2024-10-25 11:40:25 -07:00
Spottedleaf d7d227d746 Prepare rebase 2024-10-25 11:24:51 -07:00
Spottedleaf 93271dfe39 Finish mixin diff review
The mixin diff review looks OK, but need to check the
patch diff now.
2024-10-24 12:47:34 -07:00
Spottedleaf f35b3d7460 Complete rebase, start review 2024-10-24 11:51:29 -07:00
Spottedleaf 89ad2785a8 Prepare rebase 2024-10-24 11:22:17 -07:00
Spottedleaf df7fb7760b Fix some compile errors from patches 2024-10-24 11:20:51 -07:00
Spottedleaf 7199166cb2 Implement chunk system 2024-10-24 11:11:56 -07:00
Spottedleaf 9472b1ddf5 Implement Starlight 2024-10-24 10:39:36 -07:00
Spottedleaf eb57d32c94 Implement explosion optimisations 2024-10-24 10:16:56 -07:00
Spottedleaf 5d63f12602 Implement chunk tick iteration optimisations 2024-10-24 10:06:01 -07:00
Spottedleaf 065aecac6c Implement config hooks in PaperHooks 2024-10-24 08:36:07 -07:00
Spottedleaf 4b1beb1404 Merge patches 2024-10-24 08:20:45 -07:00
Spottedleaf 77baea3bf9 Begin fixing issues
See diff in the update text file
2024-10-24 08:18:20 -07:00
Spottedleaf c4d6fdcff0 Move common diffs to MCUtils 2024-10-23 20:45:35 -07:00
Spottedleaf 249fdac7ee Start Moonrise update
This is based on Moonrise's 1.21.2 branch, but this on
1.21.1 so some diffs cannot be applied (and this doesn't
compile).

See moonrise_update_1_21_2.txt for progress
2024-10-21 21:01:00 -07:00
Spottedleaf d24e41986e Add proper async player disconnections
Blocking can cause performance problems
2024-10-16 07:00:40 -07:00
Spottedleaf 9804f7ffe1 Use player file, not directory, when checking for offline player data
When trying to fall back to offline player data in onlide mode,
we need to use the player file. This fixes a mistake during
update where 'file' was used, but the new code uses 'file1'
for the player file.
2024-08-18 15:32:25 -07:00
Spottedleaf 9ceadbe9f1 Fix entity limit patch deleting unnecessary entities
We need to continue the save loop, not break from it
when a limit is reached.
2024-08-18 11:14:39 -07:00
Spottedleaf 1d4d2dc5f9 Apply optimise collision checking in move packet handling patch 2024-08-16 06:56:13 -07:00
Spottedleaf 842831a3cf ConcurrentUtil: Fix concurrent long map resize chain pull function
The function assumed that the current resize chain pointed to
the previous table, when in fact it pointed to the current table.

The function is supposed to restore the resize chain to the previous
table, previous increment, and previous index + new increment.
2024-08-01 16:55:33 -07:00
Spottedleaf bad7a89384 Make loadChunksForMoveAsync use new chunk system load calls
This is to allow the call to work properly when on Folia,
as Folia does not have a main thread.
2024-07-30 19:50:14 -07:00
Spottedleaf 5bb7bd0f66 Move TickThread changes from Moonrise patch to MCUtils
The common changes from Moonrise should be entirely in MCUtils
2024-07-30 05:32:20 -07:00
Spottedleaf e9a408f93f Add mob bucket items to item id to entity map in DataConverter
Mojang missed these in their mapping. Since the entity data
is used when spawning the bucketed mob, we need to have these
inside the id map to ensure that the entity data is converted
correctly if the entity id is missing.
2024-07-28 17:36:53 -07:00
Spottedleaf 78866a364d Do not allow chunk unloading outside of the regular tick loop
Allowing chunk loading to occur at any point via purgeUnload()
introduces possible undesirable behavior to occur recursively
inside the chunk system.
2024-07-28 16:18:25 -07:00
Spottedleaf ce8b79d47e Null check tracker in Entity#resendPossiblyDesyncedEntityData
Accidentally dropped this check last commit. It is possible
that this is called while the entity is not tracked.
2024-07-28 15:49:38 -07:00
Spottedleaf 3badc8385a Copy missed changes to chunk system from Folia 2024-07-28 15:34:07 -07:00
Spottedleaf 08e9cfb799 Remove Entity tracker field
Now the only tracker field is from the entity tracker
optimisations.
2024-07-28 15:28:28 -07:00
Spottedleaf f9a133bd33 Log throwable when failing to save chunk/poi/entity data 2024-07-17 11:48:24 -07:00
Spottedleaf e43b9191b2 Finish chunk tick iteration optimisation port from Moonrise 2024-07-17 11:33:13 -07:00
Spottedleaf 077f411288 Remove unused chunk system hooks in MCUtils 2024-07-17 11:08:28 -07:00
Spottedleaf cc8d4390d4 Remove Moonrise utils to MCUtils, remove duplicated/unused utils 2024-07-17 10:24:53 -07:00
Spottedleaf e2a85cf6d9 Optimise chunk tick checking during chunk tick
We don't need to check for this with the chunk system, as
ticking chunks are actually guaranteed to ticking. Additionally,
ticking chunks may only become non-ticking during the chunk holder
manager tick - which will not happen during chunk ticking.
2024-07-17 07:43:49 -07:00
Spottedleaf efa4155840 Fix priority scheduling logic
This resolves sync loads not being properly prioritised.
2024-07-17 07:39:30 -07:00
Spottedleaf e3d92c508f Do not try to stop main thread during watchdog shutdown
In Java 21, Thread#stop is no longer implemented and wiill throw
an exception when called. As a result, we simply cannot halt
the main thread during shutdown anymore.
2024-07-15 12:46:23 -07:00
Spottedleaf 043559513c Apply automatic regionfile header recalculation patch 2024-07-15 12:20:47 -07:00