Commit Graph

790 Commits

Author SHA1 Message Date
5052b75565 Separate Level management functionality from Server, clean up a bunch of mess 2019-01-12 19:11:05 +00:00
7d827a1c65 Introduce EntityFactory
This contains all of the static stuff that was previously embedded in the Entity static root. This solves a bunch of problems like circular dependencies between parent and child classes, encapsulating logic and reducing the size of the enormous Entity.php.
2019-01-06 23:54:29 +00:00
b1cef8509a Revamp Entity construction
This is a similar refactor to the one I recently did for tiles.

- Entity::createEntity() is removed. In its place are Entity::create() (runtime creation, use where you'd use a constructor, accepts a ::class parameter, throws exceptions on unknown entities) and Entity::createFromData() (internal, used to restore entities from chunks, swallows unknown entities and returns null).
- Entity::registerEntity() is renamed to Entity::register().
- Added Entity::override() to allow overriding factory classes without touching save IDs. This allows more cleanly extending & overriding entities. This method only allows overriding registered Entity classes with children of that class, which makes code using the factory much more sane and allows to provide safety guarantees which make the code less nasty.
- Entity::getKnownEntityTypes() is renamed to Entity::getKnownTypes().
- ProjectileItem::getProjectileEntityType() now returns a ::class constant instead of a stringy ID.
- Cleaned up a bunch of nasty code, particularly in Bow.
2019-01-06 23:33:36 +00:00
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
4b9a142a5d Import global functions and constants for enhanced performance
This is better for performance because these then don't need to be reevaluated every time they are called.

When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace.
This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified.

However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement.
But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations.
We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
2019-01-04 20:43:15 +00:00
e1064a9e36 Merge branch '3.5' 2019-01-04 00:37:48 +00:00
d71a543d10 Fixed a bunch of things PHPStan finds unpalatable
close #2614, fix a bunch of docs bugs, fix sendCreativeContents() crash on Human holders, move some inline variable declarations
2019-01-04 00:23:09 +00:00
39c0fa6103 Merge branch 'release/3.5' 2018-12-29 20:58:12 +00:00
5ecc5ed7e0 Get rid of catch-all on chunk unload
god only knows what the fuck is going on in here that warrants this catch-all... so let's remove it and find out!
2018-12-29 16:37:59 +00:00
cd80ae00d4 Handle errors properly on chunk load
Only CorruptedChunkException and UnsupportedChunkFormatException are expected. Anything else should crash the server.
2018-12-29 16:37:10 +00:00
a6cd9ae029 Implemented #2556: don't send tile NBT updates until the end of tick
this eliminates spam when tile spawn NBT changes a lot during a tick, for example the lines of a sign being updated.

closes #2556
2018-12-26 22:18:52 +00:00
16ffd99005 Merge branch 'release/3.5' 2018-12-21 18:40:04 +00:00
2664a1b4d8 Merge branch 'release/3.4' into release/3.5 2018-12-21 18:39:42 +00:00
4249c00c3e Level: Fixed generation/send race condition causing blocks to be missing on the client
this FINALLY fixes the remaining occurrences of half-trees.
2018-12-21 18:39:33 +00:00
b709e21622 Merge branch 'release/3.5' 2018-12-21 17:27:02 +00:00
517c4e5143 Merge branch 'release/3.4' into release/3.5 2018-12-21 17:26:32 +00:00
69c343bb9b Level: fix setChunk() deleting tiles when replacing a chunk with the same chunk
this can be desirable to trigger events related to chunks changing, such as chunk sending.
2018-12-21 17:24:08 +00:00
20aaa8373a Sound no longer extends Vector3 2018-12-16 14:26:42 +00:00
3c520aa786 Particle no longer extends Vector3 2018-12-16 14:15:41 +00:00
e0558d2551 Merge branch 'release/3.5' 2018-12-14 10:03:36 +00:00
c05697f506 Merge branch 'release/3.4' into release/3.5 2018-12-14 09:39:21 +00:00
ed88684e71 Fixed invisible FloatingTextParticle crashing the server, closes #2560 2018-12-14 09:30:14 +00:00
ffa733fe0c Merge branch 'release/3.5' 2018-12-12 19:51:41 +00:00
ec4c61e113 fix extradata defaults for broadcastLevelSoundEvent
fixes TNT sounds not working, amongst other things
2018-12-12 17:42:52 +00:00
30f5a8fac6 Protocol changes for 1.8.0 release 2018-12-11 21:05:03 +00:00
cd5b81bdb9 ChunkManager: Remove getBlockIdAt()/setBlockIdAt()/getBlockDataAt()/setBlockDataAt(), add getBlockAt() and setBlockAt() 2018-12-04 22:27:00 +00:00
8dd2ea22b8 Level: make use of fromFullState() in getBlockAt() 2018-12-04 22:05:00 +00:00
47e62b1b38 Level: Add setBlockAt() which accepts integers instead of Vector3 2018-12-04 21:59:58 +00:00
8051fa4f6d Remove some direct Position->level accesses 2018-12-03 21:39:17 +00:00
9fb365306a Make Block->position() accept Level,x,y,z instead of Position
since this is an internal method, it doesn't make sense to force a single parameter that requires potentially constructing a separate object just for the parameters, so we pass primitives instead, which are also easier to typehint against.
2018-12-03 21:18:22 +00:00
c3623478c1 Merge branch 'release/3.4' 2018-12-03 18:33:44 +00:00
e4223bb7dc Level: Duct tape fix for crashy trees at the top of the world
this doesn't fix shit but it at least doesn't crash. Fixing this properly can't be effectively done any other way without backwards compatibility breaks. Fortunately it's not common practice to grow trees at the top of the world.
2018-12-03 18:30:27 +00:00
16006f9175 Make Tile constructors non-dependent on NBT 2018-11-30 17:05:36 +00:00
0fec58730b Level: fixed recursion bug when reading dynamic states
calculating dynamic states in some cases requires getting properties from neighbouring blocks, but getting these blocks also causes their dynamic states to be calculated, leading to a bouncing recursion.
This change allows retrieving blocks without calculating dynamic state information, if the call was generated by calculating dynamic state information.
Since these blocks are incomplete, they should not be cached and are only used to allow another adjacent block to complete its state. It is therefore not possible for a block's dynamic states to depend on another block's dynamic states.

This recursion bug was observable by running /gc and walking into a door, which would cause the server to freeze and crash.
2018-11-24 19:44:31 +00:00
1170b66fd5 Automate creation of tiles when they are used to store block properties 2018-11-24 19:44:31 +00:00
3af293f024 Added a mechanism for blocks to detect dynamic state properties from surroundings 2018-11-24 19:43:02 +00:00
b2201c8c59 Further cleanup to general AABB handling 2018-11-24 19:17:03 +00:00
98efd27543 Remove ability to set blockID and blockdata independently
This was the cause of many inconsistency and broken world bugs. In the future (once we switch to paletted chunks) this won't be possible anyway. For now, some temporary API is provided to allow modifying chunkdata directly, but it is required that **both** must be provided.
2018-11-22 16:53:22 +00:00
8b9ec5dde3 Merge branch 'release/3.4' 2018-11-07 22:11:27 +00:00
a5f776af2f Merge branch 'release/3.3' into release/3.4 2018-11-07 22:11:13 +00:00
342a74ffcb Level: Collect garbage from chunk internals in doChunkGarbageCollection() 2018-11-07 20:01:07 +00:00
38d419fb29 Level: use isInWorld() where appropriate 2018-11-04 12:59:34 +00:00
a6c31b72ae Level: throw exceptions on bad positions in setBlock() 2018-10-28 16:42:16 +00:00
7607e484dd Expose chunk locking to the API 2018-10-28 16:32:56 +00:00
90482e79bc Merge branch 'release/3.4' 2018-10-21 18:23:54 +01:00
6dd2597934 Merge branch 'release/3.3' into release/3.4 2018-10-21 18:17:07 +01:00
45c9caa38c Fixup some formatting issues 2018-10-21 18:15:25 +01:00
159c3a1a91 Merge branch 'release/3.4' 2018-10-20 19:20:22 +01:00
8ac1b18b17 Level: add API method isInLoadedTerrain() 2018-10-20 19:09:53 +01:00
fb128d0276 Merge branch 'release/3.4' 2018-10-20 16:43:25 +01:00