Commit Graph
100 Commits
Author SHA1 Message Date
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
Spottedleaf 900c617ae5 Apply incremental player/level saving patch 2024-07-15 11:57:56 -07:00
Spottedleaf 479ca6ef4d Port random ticking optimisation from Moonrise 2024-07-15 11:11:04 -07:00
Spottedleaf e08de25a2a Avoid collision shapes outside world border in findFreePosition
This is to correctly adhere to Vanilla behavior.
2024-07-15 09:56:17 -07:00
Spottedleaf 7c3194af85 Update last chunk position in findSupportingBlock
Fixes fetching chunks needlessly multiple times.

Thanks Lulu13022002 for pointing this out
2024-07-13 11:44:52 -07:00
Spottedleaf 467c178970 Port watchdog detail patch 2024-07-11 12:28:27 -07:00
Spottedleaf 235d6cc2dd Port lag compensation patch 2024-07-11 12:22:59 -07:00
Spottedleaf 8a7d58d082 Drop unapplied patches
1012-Use-distance-map-to-optimise-entity-tracker.patch:
1025-Collision-optimisations.patch:
1034-Actually-optimise-explosions.patch:
1039-Send-full-pos-packets-for-hard-colliding-entities.patch:
Implemented in Moonrise patch

1037-Distance-manager-tick-timings.patch:
Not needed

0668-Implement-regenerateChunk.patch:
API does not appear to be used, and it is a real pain to
implement this properly. The old patch did not handle
populators correctly, for example.
2024-07-11 12:11:49 -07:00
Spottedleaf 1237931f88 Port collision optimisation patch from Moonrise
Drop random ticking optimisation for now
2024-07-11 12:09:15 -07:00
Spottedleaf bde31b3ce4 Optimise entity tracker
Patch is ported from Folia
2024-07-11 09:23:56 -07:00
Spottedleaf 68cacfe830 Increment ChunkHolderManager current tick
This is an oversight from copying from Folia. The current tick
should be incremented so that incremental autosave can properly
occur.
2024-07-11 08:57:31 -07:00
Spottedleaf eea4ab322d Fix entities not being visible to clients when teleporting
When teleporting, the spawn position packet will contain the
old position. Then the following tracking update will send a
teleport packet, but the client will lerp the position change
over 3 ticks. However, the client does not tick entities in
unloaded chunks - resulting in the lerp never occuring.

We fix this by sending the current position in the spawn packet.
2024-07-11 08:32:15 -07:00
Spottedleaf 14eb93fb65 Apply entity tracker desync patch 2024-07-11 08:15:36 -07:00
Spottedleaf ed3350e66e Fix recursive chunk loading in chunk unload event
Since the chunk may not even be at a loaded ticket level, the
getChunk call may invoke a sync load. To prevent this, we can
retrieve the full loaded chunk first which is guaranteed to be
non-null when unloading.
2024-07-11 07:16:42 -07:00
Spottedleaf 7058cbc1aa Execute chunk tasks mid-tick
If the server tick length is high, then the amount of time
available to process chunk tasks inbetween ticks is low. As a
result, chunk loading and generation may appear to slow down.

To ensure that chunk tasks are always processed, we add logic to
execute chunk tasks during tile entity tick, entity tick, chunk
random ticking, and scheduled block/fluid ticking. The mid-tick task
execution is timed so that it is not prioritised over the server
tick.
2024-07-03 19:22:00 -07:00
Spottedleaf 17824b557c Fix NPE when retrieving an entity with a null UUID
While the null UUID is almost certainly an error, the old
implementation did not NPE as it used a plain HashMap for lookup
by UUID, whereas we use a ConcurrentHashMap which will NPE on
null keys.
2024-06-23 18:58:31 -07:00
Spottedleaf 89961bad94 Fix unload queue storing chunks in wrong sections
The unload queue stored the chunks in the same section as
the chunk coordinate, when it needed to apply the unload shift.

Additionally, change the default region shift to the ticket
propagator shift as there is no benefit to using a low region
shift since no regionizing is occuring. This makes the unload
queue shift 6, which should reduce the number of sections to deal
with while processing unloads.
2024-06-21 11:57:03 -07:00
Spottedleaf 72883ff600 Re-add chunk system debug commands
Re-adds the 'chunkinfo', 'holderinfo' and 'debug chunks' commands.

Additionally, this re-adds chunk debug dumping during watchdog
long timeouts.
2024-06-19 12:11:21 -07:00
Spottedleaf 287baeab18 Add debug for chunk system unload crash
Somehow, a chunkholder is present in the unload queue after
it has been unloaded. It is likely that this is a result of
adding the chunk holder to the unload queue while it is
unloading. However, that should not be possible.

To find out where it is being added to the unload queue, track
the last stacktrace which adds to the unload queue and check
on chunk holder remove if the holder is present in the unload queue
and log the stacktrace.
2024-06-19 10:55:04 -07:00
Spottedleaf e985ffabb2 Fix ChunkHolder#getFullChunkNow returning non-null when it should not
In the new chunk system, the chunk is only at FULL when either
the FULL callbacks have been invoked or during the FULL callbacks.
2024-06-19 10:42:48 -07:00
Spottedleaf 3c4ca08b26 Cleanup MCUtils patch for chunk system
Remove utilities that are unused, as well as replacing
the full chunk map with a concurrentutil implementation.

Additionally, fix the addition/removal of chunks to/from the
full chunk map so that getChunkIfLoaded correctly returns a
non-null chunk when calling the load or unload events.
2024-06-19 10:29:03 -07:00