Commit Graph

4679 Commits

Author SHA1 Message Date
Aikar
8e9459eadc
Fix missing flag pass for isUrgent 2020-05-11 00:19:40 -04:00
Josh Roy
7befec4420
Potential bed api (#3339) 2020-05-11 00:19:04 -04:00
Spottedleaf
27945a6b1f
Optimize WorldBorder collision checks and air
Port part of leafs changes from Tuinity, will worry about rest later with larger changes coming
2020-05-10 22:52:20 -04:00
Aikar
55e17a8599
Wait for Async Tasks during shutdown
Server.reload() had this logic to give time for tasks to shutdown,
however shutdown did not...

Adds a 5 second grace period for any async tasks to finish and warns
if any are still running after that delay just as reload does.

Closes #3337
2020-05-10 22:17:55 -04:00
Aikar
b59052566b
Ensure Entity AABB's are never invalid
If anything used setPositionRaw, it left potential for an AABB
to be left stale at their old location, which could cause massive
AABB boxes if movement ever then got called on the new position.

This guarantees any time we set the entities position, we also
update their AABB.
2020-05-10 22:14:47 -04:00
Aikar
a054aa6f02
Properly remove Entities from current chunk
We store a reference to the chunk the entity is currently in, so use it
to more accurately unregister it in chunkCheck

Should maybe fix some entity loss issues.
2020-05-10 05:52:31 -04:00
Aikar
c894ddfd38
Fix teleporting onto a chunk line
Obscure detail in that if you teleport right on a chunk line, it
adds +1 to your collision check and will check the unloaded neighbor.

but the call to load the chunk then returned null if it was pending unload, such
as the load we did in Player List

However we want gen=true for players here anyways, so use getType
2020-05-10 05:52:26 -04:00
Aikar
57d6cc0158
Send LOGIN protocol packets immediately - Fix disconnect during async prelogin 2020-05-10 03:12:05 -04:00
Aikar
cd93e54df3
Don't use our modified chunk checks for collision in world gen
Fixes issues with errors in logs on generating chunks
2020-05-10 02:27:50 -04:00
Aikar
b4003ef1ca
Allow loading entities current chunk if needed to fix collision checks
Having trouble reproducing this myself, but this should do it.
2020-05-10 01:04:45 -04:00
Aikar
e5f6489602
Add Urgent API for Async Chunks API and use it for Async Teleport
This also cleans up the implementation of Async Chunks to get rid of most
Consumer callbacks and instead return futures.

This lets us propogate errors correctly up the future chain
(barring one isn't lost even deeper in the chain...)

So exceptions can now bubble to plugins using getChunkAtAsync
2020-05-10 00:57:03 -04:00
Aikar
ad8e59dc79
Ensure chunks loaded on respawn for suffocation check 2020-05-09 21:13:30 -04:00
Aikar
b1691e7b69
Remove some Streams usage in Entity Collision
While there is more down the collision system, remove some of the wrapping
Spliterator stuff as even this wrapper stream has shown up in profiling.

With other collision optimizations, we might also even avoid inner streams too.
2020-05-09 19:38:31 -04:00
JellySquid
d454bbd5e1
Implement JellySquid's Entity Collision optimisations patch
This patch replaces the vanilla collision code for both block and entity collisions with faster implementations by JellySquid, used originally in her Lithium mod.

Optimizes Full Block voxel collisions, and removes streams from Entity collisions

Original code by JellySquid, licensed under GNU Lesser General Public License v3.0
you can find the original code on https://github.com/jellysquid3/lithium-fabric/tree/1.15.x/fabric (Yarn mappings)

Ported by
Co-authored-by: Zoutelande <54509836+Zoutelande@users.noreply.github.com>

Touched up by Aikar to keep previous paper optimizations
2020-05-09 19:19:18 -04:00
Aikar
8e85f841d8
Optimize Collision to not load chunks
The collision code takes an AABB and generates a cuboid of checks rather
than a cylinder, so at high velocity this can generate a lot of chunk checks.

Treat an unloaded chunk as a collision for entities, and also for players if
the "prevent moving into unloaded chunks" setting is enabled.

If that setting is not enabled, collisions will be ignored for players, since
movement will load only the chunk the player enters anyways and avoids loading
massive amounts of surrounding chunks due to large AABB lookups.

Fixes #3321
2020-05-09 19:19:08 -04:00
Aikar
ceb824dbde
Fix ChunkCache .getXIfLoaded to use the local chunks in the cache
It was calling back out to world for it, we already have them.

Also use the nocache method for building the chunk cache too.
2020-05-09 14:58:08 -04:00
Aikar
f6f9157bd4
Don't toString block unless actually showing the message
This is causing MASSIVE performance issues with hoppers and block states
in general.
2020-05-09 13:55:41 -04:00
Aikar
b3f0527ac4
Add Spawn Entity SpawnReason API
So you can specify why an entity is spawning, ie NATURAL
2020-05-09 13:18:20 -04:00
Aikar
ec8d7387ad
MC-183249: Don't generate Carving Masks BitSet unless needed
This was using SIGNIFICANT amounts of memory allocating many
long[]'s for BitSets for every ProtoChunk in the cache that had
been unloaded and reloaded.

This will result in a nice memory reduction.
2020-05-09 12:13:29 -04:00
Aikar
2d401d2dfb
Improve BlockPosition hashCode/equals
Actually showed up in profiling as decent time spent here...

Noticed y/z was missing its final that it use to have, when x had it. some how
must of got messed up on some update. though people suggest this shouldn't of
mattered anyways, but lets put it back for safety.

Added cache of hashcode, as well as optimized the hash code using larger primes.
Also stored the long value of the x/y/z so that for equals we can compare a single long,
as well as have that long value cached for .asLong()
2020-05-09 10:59:29 -04:00
Aikar
2572bd017c
Fix world unload toLowercase - Fixes #3326 2020-05-09 10:59:10 -04:00
virustotalop
dda9680be5
Optimize brigadier child sorting performance
Use a TreeMap instead of a LinkedHashMap and then manually sorting

This will significantly reduce CPU usage on logging in and changing worlds.
2020-05-08 20:55:44 -04:00
Aikar
a71a4ec215
Fix CraftServer.unloadWorld Leak
The dimension manager was still registered which leaked the entire World
2020-05-08 20:40:42 -04:00
Aikar
f6fc0d4cd4
Don't create region files for chunk checks - mistake on upstream merge
Accidently handled a conflict wrong in a previous upstream merge and set wrong param.
2020-05-08 18:22:37 -04:00
Aikar
cfed00cf54
Fix Light Command
This lets you run /paper fixlight <chunkRadius> (max 5) to automatically
fix all light data in the chunks.

Permission node is same "bukkit.command.paper"
2020-05-07 19:44:33 -04:00
Aikar
a6ff84add7
Revert Nibble patch, causing issues still 2020-05-07 05:30:40 -04:00
Aikar
f1a8eb7fda
Use a finalizer for light packet instead of onPacketDone
Sadly sharing packets is breaking the ability to do this :(

We can prob still do a little better than this but will save that
for another commit.
2020-05-07 01:58:23 -04:00
Aikar
03c9bb05c1
Optimize NibbleArray to use pooled buffers
Massively reduces memory allocation of 2048 byte buffers by using
an object pool for these.
2020-05-07 01:32:02 -04:00
Aikar
d0a528b1cb
Move delayed init down later in tick, improve accuracy of startup time
Now tracks the full startup time for "Done" message at end, as apparently
Vanillas was done in a place that skipped tracking a lot of code too.

This fixes an issue with ViaVersion
2020-05-06 21:24:43 -04:00
Aikar
cc477e6abb
Force Plugins that use delayed tasks for init back in their place
Will now run those tasks just before we print "Done" so that startup
time is appropriately accounted for a plugin, as well as will no longer
trip the watchdog on startup.

Any plugin that tries to bypass this is just going to then trip watchdog
on Spigot too, so don't you dare.

Stop trying to cheat the delay your plugin added to startup time.

This isn't a behavior change because the first thing the tick does....
was run these tasks....

So it's just moving it slightly a few lines to be before a watchdog tick and
to account for it in "Done" time.

Fixes #3294
2020-05-06 20:18:31 -04:00
Aikar
597263fd55
Don't skip full player connection tick when dead
Still need to send keep alives and kick for idle

Fixes #3299
2020-05-06 19:30:47 -04:00
Spottedleaf
e2c23475b5
Revert loaded entity list (#3304) 2020-05-06 11:31:29 -05:00
Spottedleaf
fa87db6b91
Move another NetworkManager util into the inner class (#3303)
Those poor souls running outdated ProtocolLib.
2020-05-06 10:07:51 -05:00
Spottedleaf
841c7d1879
Make loaded entity list logic more consistent (#3301)
When adding/removing to a chunk, we need to also look at
editing the loaded entity list.

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2020-05-06 09:57:18 -05:00
Aikar
36f34f01c0
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots
3abebc9f #492: Let Tameable extend Animals rather than Entity
941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent
4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME

CraftBukkit Changes:
933e9094 #664: Add methods to get/set ItemStacks in EquipmentSlots
18722312 #662: Expose ItemStack and hand used in PlayerShearEntityEvent
2020-05-06 06:05:22 -04:00
Aikar
5ca5f131bb
Rebuild all patches using the new rebuild pattern 2020-05-06 05:48:49 -04:00
Mariell Hoversholm
1ccff6fabb
Add villager reputation API 2020-05-06 05:48:06 -04:00
Minecrell
5c0bfffa09
Speed up rebuilding patches and reduce diff 2020-05-06 05:31:08 -04:00
Aikar
f37381ea8a
Optimize Network Manager to not need synchronization
Removes synchronization from sending packets
Makes normal packet sends no longer need to be wrapped and queued like it use to work.
Adds more packet queue immunities on top of keep alive to let the following scenarios go out
without delay:
  - Keep Alive
  - Chat
  - Kick
  - All of the packets during the Player Joined World event

Hoping that latter one helps join timeout issues more too for slow connections.

Removes processing packet queue off of main thread
  - for the few cases where it is allowed, order is not necessary nor
    should it even be happening concurrently in first place (handshaking/login/status)

Ensures packets sent asynchronously are dispatched on main thread

This helps ensure safety for ProtocolLib as packet listeners
are commonly accessing world state. This will allow you to schedule
a packet to be sent async, but itll be dispatched sync for packet
listeners to process.

This should solve some deadlock risks

This may provide a decent performance improvement because thread synchronization incurs a cache reset
so by avoiding ever entering a synchronized block, we get to avoid that, and packet sending is a really
hot activity.
2020-05-06 05:28:47 -04:00
stonar96
8f9df2ed43
Anti Xray cleanup
Undo the accidental renaming of a method in 0aad8bf
Aikar wanted to rename DataPalette#getDataBits(T object) to getOrCreateIdFor
in 0aad8bf but he also accidentally renamed
ChunkPacketInfo#getDataBitsIndex(int chunkSectionIndex) to
getOrCreateIdForIndex.

Remove chunk-edge-mode and chunk loading entirely from Anti-Xray
The chunk-edge-mode is broken since several versions.
Loading chunk neighbors for chunk edge obfuscation isn't needed anymore.
Unlike in previous versions, these are under normal circumstances already loaded
at the time we need them (plugins for example can bypass this).

Use the modified methods and constructors everywhere
Anti-Xray provides support for the default nms methods and constructors,
which where modified by Anti-Xray to avoid breaking stuff (plugins)
which somehow uses these methods.
However, the modified versions of those methods and constructors should be used
where possible.
2020-05-06 04:35:20 -04:00
Spottedleaf
878c66f116
No-Tick view distance implementation - Closes #3196
Implements world view distance getters/setters

Per-Player is absent due to difficulty of maintaining
the diff required to make it happen.
2020-05-06 03:50:52 -04:00
Spottedleaf
b87743c1e0
Stop copy-on-write operations for updating light data
Causes huge memory allocations + gc issues
2020-05-06 03:48:56 -04:00
Spottedleaf
97a9c9724a
Optimize isOutsideRange to use distance maps
Use a distance map to find the players in range quickly
2020-05-06 03:48:18 -04:00
Spottedleaf
b4e629a283
Use distance map to optimise entity tracker / Misc Utils
Use the distance map to find candidate players for tracking.

This also ports a few utility changes from Tuinity
2020-05-06 03:47:24 -04:00
Spottedleaf
d80d15174b
Optimize Entity Ticking to Loaded Chunks only
We retain a list of loaded entities specifically for this usage
2020-05-06 03:43:11 -04:00
Nassim
31d7686d26
Add item slot helper methods for various inventories (#3221) 2020-05-05 19:49:16 -04:00
MiniDigger
75e1e3b3e1 Mob Goal API 2020-05-05 18:05:27 +02:00
Aikar
c7bc393a87
Revert "Don't flush packet queue off main thread"
This reverts commit 1abd2bd279.

Sadly not gonna work due to server pings
2020-05-04 04:50:08 -04:00
Aikar
1abd2bd279
Don't flush packet queue off main thread
Increases risk of deadlock if a plugin using protocollib sends a packet
async, and then a listener then reads world state, and main thread is then
blocked waiting for the queue to flush.

This will break out of the synchronized block when it jumps to the netty event loop.

See: https://gist.github.com/aikar/e7abb2ba7059149d0a91f7a226e98590
2020-05-04 03:07:04 -04:00
Aikar
a4ed58a9ab
Clean up Direct Memory Region Files Fix for different Java versions
Java 9+ doesn't allow using the exposed cleanup method, but added
a new method on Unsafe to do it.

So have to detect java version and use the appropriate strategy.
2020-05-04 02:19:38 -04:00