284 Commits

Author SHA1 Message Date
Dylan K. Taylor
2924303169 Sync NBT dependency 2019-01-07 22:38:04 +00:00
Dylan K. Taylor
78cb6445a5 Introduce TileFactory 2019-01-07 00:20:24 +00:00
Dylan K. Taylor
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
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
Dylan K. Taylor
7b3115c00c Moved network NBT serializer into network namespace 2018-12-29 20:12:00 +00:00
Dylan K. Taylor
b8f8a81704 Merge branch 'release/3.5' 2018-12-26 23:18:33 +00:00
Dylan K. Taylor
a71af952ba Sign: simplify network data reading, ensure text is always 4 lines, closes #2610 2018-12-26 22:57:42 +00:00
Dylan K. Taylor
ba33d8340a Merge branch 'release/3.5' 2018-12-26 22:26:44 +00:00
Dylan K. Taylor
98f903783c Chest: remove pairx and pairz on blockpick, fixes #2612 2018-12-26 22:26:17 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
2c6381632c Allow Tiles to decide how to copy data from an item 2018-12-26 20:01:14 +00:00
Dylan K. Taylor
f6983efec1 Revamp Tile creation (again)
This breaks down the handling of tile creation even further.
- Introduced a static Tile::override() method to allow overriding the construction class for a specific type of chest. This applies to classes as opposed to save IDs, so you can override Chest::class with MyCustomChest::class and it will take effect for any Chest save ID.
- Removed MCPE stringy save ID constants from public Tile interface. These are now only used for creating saved tiles from a stored chunk, and saving them.
- Renamed Tile::registerTile() to register()
- Tile::create() and Tile::createFromItem() now accept a class parameter instead of a stringy save ID.
- Tile::create() and Tile::createFromItem() were changed to throw \InvalidArgumentException on unknown/unregistered tile types. They also now never return null, but always (except in exception cases) return an object which is an instanceof the base class specified.
2018-12-26 19:21:37 +00:00
Dylan K. Taylor
a9dc447f8f Tile: make createFromData() retrieve the ID by itself 2018-12-11 14:56:25 +00:00
Dylan K. Taylor
d72e4cb9a1 Tile: remove createNBT(), add create(), createFromData(), createFromItem() 2018-12-10 19:40:37 +00:00
Dylan K. Taylor
6dbceda3e8 Tile: Fill defaults and move code to constructors where appropriate
this is leftovers from when NBT was required to construct a tile.
2018-12-10 18:35:26 +00:00
Dylan K. Taylor
b50e29085e Remove InventoryEventProcessor, use closures instead 2018-12-04 19:02:26 +00:00
Dylan K. Taylor
16006f9175 Make Tile constructors non-dependent on NBT 2018-11-30 17:05:36 +00:00
Dylan K. Taylor
650a2eee4b Tile: remove unused import 2018-11-27 20:04:47 +00:00
Dylan K. Taylor
d0e2cdb54c Tile: remove server field
it would be nice to get rid of the server dependency entirely... perhaps craftingmanager should be a singleton? it's contextless after all...
2018-11-25 15:58:24 +00:00
Dylan K. Taylor
3f3bdaeba5 Use dynamic state detection to localize stateinfo stored in tiles (hack) 2018-11-24 19:43:02 +00:00
Dylan K. Taylor
4879eac946 Merge branch 'release/3.4' 2018-10-30 15:43:27 +00:00
Dylan K. Taylor
c143834632 Merge branch 'release/3.3' into release/3.4 2018-10-30 15:43:06 +00:00
Dylan K. Taylor
31ceafa111 Chest: keep inventory better in sync when paired
should fix #2502
2018-10-30 15:42:44 +00:00
Dylan K. Taylor
159c3a1a91 Merge branch 'release/3.4' 2018-10-20 19:20:22 +01:00
Dylan K. Taylor
2a40c0d82c Make use of isInLoadedTerrain() 2018-10-20 19:13:34 +01:00
Dylan K. Taylor
831a35ec69 Merge branch 'release/3.4' 2018-10-20 15:26:17 +01:00
Dylan K. Taylor
d563b9e31b Level: Added API method broadcastPacketToViewers()
This supersedes addChunkPacket() in most cases, and has a more clear name. It broadcasts the given packet to every player who has the target position within their chunk load radius.
2018-10-20 15:14:41 +01:00
Dylan K. Taylor
495a0b1dc2 Merge branch 'release/3.3' 2018-10-05 18:11:33 +01:00
Dylan K. Taylor
1dd6591ac1 Migrate a bunch of PluginManager->callEvent() usages to Event->call
This has the triple bonus effect of a) making a lot of code easier to read, b) reducing Server::getInstance() usages, and c) removing a whole bunch of Server dependencies.

The network and block namespaces are untouched by this commit due to potential for merge conflicts. These should be dealt with separately on master.
2018-10-05 17:30:06 +01:00
Dylan K. Taylor
75f364fcf2 Level: Remove obsolete \$direct parameter from setBlock()
this parameter was previously used to send blocks with a different set of flags, immediately, to players. However, the flags have been demonstrated useless and the direct sending is pointless now since packets are buffered now per session, so we might as well take advantage of the batched block update sending.
2018-09-27 16:15:07 +01:00
Dylan K. Taylor
56d9943b0d Nuke Block->meta, split into variant and state properties, lots of cleanup
This is a major change to the way block metadata is handled within the PM core. This separates variant metadata (which really ought to be part of the ID) from state metadata, and in a couple of cases flattens separate states of blocks together.

The result of this is that invalid variants can be much more easily detected, and additionally state handling is much cleaner since meta is only needed at the serialize layer instead of throughout the code.
2018-09-21 19:28:10 +01:00
Dylan K. Taylor
f218868338 Separate facing/bearing handling from Vector3, deobfusticate a ton of @shoghicp old code 2018-09-05 19:56:14 +01:00
Dylan K. Taylor
ac8565fc2e Merge remote-tracking branch 'origin/release/3.2' 2018-08-19 19:54:34 +01:00
Dylan K. Taylor
ddcb2f002a
Tile: Be explicit about not calling Tile::createNBT() (#2388)
A common pitfall developers fall into with this function is that it has to be called from the scope of the tile class you're creating NBT for, but people commonly do Tile::createNBT() directly, which then results in cryptic "Tile is not registered" errors. This now throws a BadMethodCallException instead to be fully clear about this.

In the future this will be removed completely once NBT is no longer required to create a tile, but for now this is a confusing issue that should be dealt with.
2018-08-19 19:54:22 +01:00
Dylan K. Taylor
7c41bfcdf3 Removed Tile numeric runtime IDs, use block hashes instead
Tiles are level-local and are not indexed globally like entities. There is pretty much zero point to them having numeric runtime IDs.
2018-08-19 16:37:04 +01:00
Dylan K. Taylor
92aeab0d00 Merge branch 'release/3.2' 2018-08-19 16:03:04 +01:00
Dylan K. Taylor
5df601c817 Add @see docs so PhpStorm can see dynamic constructor usages
PhpStorm can't see constructor usages when the class name is dynamic. This causes maintenance problems because cross-referencing constructors called like this doesn't show up dynamic calls.
2018-08-19 16:00:15 +01:00
Dylan K. Taylor
be37236c76 Deduplicate code for general classpath registries 2018-07-26 15:21:03 +01:00
Dylan K. Taylor
d305a1342f Make Tile::registerTile() and Entity::registerEntity() throw exceptions instead of returning false 2018-07-26 14:55:55 +01:00
Dylan K. Taylor
c1843ac2d4 Player: remove dataPacket() and directDataPacket()
I considered renaming sendDataPacket() to dataPacket() to reduce the BC breaks, but the parameter set has changed, which might cause astonishing behaviour, so it's better to break it in a loud way. Also, this has a clearer name.
2018-07-22 12:04:53 +01:00
Dylan K. Taylor
5dbb0d177e
Fixed double chest inventory desync issues, closes #2261 (#2279)
chest pairing really needs rewriting... this code really sucks
2018-07-05 17:42:30 +01:00
Dylan K. Taylor
f315aca4c3 Tile: make saveNBT() return a CompoundTag
I don't know why I made it take a parameter for this...
2018-06-16 17:59:41 +01:00
Dylan K. Taylor
cfb10360ff Furnace: remove trailing whitespace 2018-06-11 13:31:05 +01:00
Dylan K. Taylor
05af87e1d4 Strip empty lines at the end of classes 2018-06-11 13:19:23 +01:00
Dylan K. Taylor
c4c6c58615 Added some missing typehints 2018-06-10 17:18:55 +01:00
Dylan K. Taylor
f6481eab8f
Implemented an InventoryEventProcessor, fixes #1986 (#2176)
* Implemented InventoryEventProcessor, fixes #1986
Event processors can now be registered and unregistered at will. Entity inventory/armor change events are now handled by event processors instead of the inventories themselves, which allows enabling/disabling the calling of these events at will.
This now avoids stupid things happening when initializing inventory contents, since the callers for those events are now registered _after_ the contents are initialized.
2018-06-09 17:37:10 +01:00
Dylan K. Taylor
14914781fc Added exception throws when a closed tile or entity attempts to schedule itself for updating
I can't believe it took so long to find what was causing these stdClass bugs.
2018-06-07 12:37:26 +01:00
Dylan K. Taylor
fe21f0e916 Spawnable: change visibility of addAdditionalSpawnData() 2018-06-03 19:58:48 +01:00
Dylan K. Taylor
4c1d29cdf7 Tile: remove unnecessary removeTag() calls
these CompoundTags are now ephemeral, so it's not necessary to remove potential garbage from them anymore.
2018-06-03 18:31:23 +01:00