357 Commits

Author SHA1 Message Date
Dylan K. Taylor
86c4e936cb Player now drops the contents of temporary inventories
these inventories are just glorified crafting tables.
2019-04-26 12:27:52 +01:00
Dylan K. Taylor
898009a91b Sync crafting data changes
this seems to fix #2881, at least the reproducing case that was given.
2019-04-25 16:22:12 +01:00
Dylan K. Taylor
fa70127241 1.11.0 protocol changes 2019-04-24 19:54:16 +01:00
Dylan K. Taylor
ab5b4d112b BaseInventory: fixed items with userdata stacking with items without userdata 2019-03-03 11:12:36 +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
93dd05a03e Fixed ender chest sounds, closes #2611 2018-12-26 22:33:51 +00:00
Dylan K. Taylor
6dd2597934 Merge branch 'release/3.3' into release/3.4 2018-10-21 18:17:07 +01:00
Dylan K. Taylor
45c9caa38c Fixup some formatting issues 2018-10-21 18:15:25 +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
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
70635d0870 DropItemAction: Consider invalid if the target item is null
it's not possible to drop a null item.
2018-08-05 11:32:50 +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
697723b551 DoubleChestInventory: remove redundant clear() override
this calls setItem() which deals with the necessary logic anyway.
2018-07-04 20:06:42 +01:00
Dylan K. Taylor
5926d80525 DoubleChestInventory: fixed wrong logic for setting items into the right-hand side 2018-07-04 20:04:40 +01:00
Dylan K. Taylor
d2a037de71 InventoryTransaction: Avoid crashing when trying to compact slot changes with invalid slot numbers
fixes #2250
2018-06-19 18:31:13 +01:00
Dylan K. Taylor
9f7f62e9e5 Don't use Config for builtin JSON resources
it doesn't make sense to use a config in these cases, and also it just hides problems when the files are missing.
2018-06-16 16:35:47 +01:00
Dylan K. Taylor
2e9e44ba05 Moved JSON blobs to submodule 2018-06-12 18:49:18 +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
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
Anton
aeb551b317 Remove double use of spl_object_hash (#2226) 2018-06-09 14:15:50 +01:00
Dylan K. Taylor
75d13be38e EnderChestInventory: remove unused import 2018-05-19 11:37:22 +01:00
Dylan K. Taylor
d8dc89e7c8 EnderChestInventory: Removed unnecessary owner parameter 2018-05-18 16:46:48 +01:00
Dylan K. Taylor
8312ad709e InventoryTransaction: Removed creationTime
this is no longer necessary because transactions now always arrive in a single packet.
2018-05-16 12:14:29 +01:00
Dylan K. Taylor
2660448601 Crafting: Match recipe based only on transaction inputs/outputs
As of 1.2.13 release, the client now skips the crafting grid step when it crafts with right-click on the recipe book. This means that we can't validate crafting based on the crafting grid contents anymore. The only way to do it now is to use the inputs and outputs calculated by the transaction balance.
2018-04-04 12:48:17 +01:00
Dylan K. Taylor
eb354916d4 CraftingTransaction: simplifiy repetition calculation handling 2018-04-04 12:18:24 +01:00
Dylan K. Taylor
033b44df5a CraftingTransaction: Start from pre-computed iteration count for input matching
This will be faster to bail out on failures.
2018-04-04 12:15:46 +01:00
Dylan K. Taylor
ef2dd1de92 Inventory: Use exceptions to report back why a transaction failed
Returning false all the time could mean any one of a range of things. Throwing exceptions is better in that it allows us to catch them and see what actually broke.
2018-04-04 12:11:24 +01:00
Dylan K. Taylor
eba1ca030c Fix variadic type docs ...again
PhpStorm changed its mind how it wants these documenting in 2018.1, and apparently the correct syntax follows the PHP code.
2018-04-02 12:33:24 +01:00
Dylan K. Taylor
8ce0fab8cc Remove unused imports 2018-04-02 12:26:13 +01:00
Dylan K. Taylor
56328f66a7 InventoryAction: remove useless creationTime field 2018-03-29 12:20:13 +01:00
Dylan K. Taylor
f41a731493 DropItemAction: don't require a source item in constructor 2018-03-29 12:18:19 +01:00
Dylan K. Taylor
ec332e3e60 Fill null UUIDs in CraftingDataPacket, remove all UUID things from CraftingRecipe
This allows deleting lots of code, and additionally provides a huge reduction in the compressed size of CraftingDataPacket. Since we don't care about these UUIDs (they are only used in CraftingEventPacket, which is broken and unused in PM) we fill them with zeros instead.
2018-03-29 12:05:23 +01:00
Dylan K. Taylor
a1090623a2 CraftingRecipe: added methods to allow recipes to derive outputs from inputs
this will be needed for special recipes like shulker-box and banner recipes.
2018-03-29 12:05:22 +01:00
Dylan K. Taylor
8572e9e560 Crafting: nuke
This commit brings in a much-needed rewrite of crafting transaction handling.

The following classes have been removed:
- CraftingTransferMaterialAction
- CraftingTakeResultAction

The following classes have significant changes:
- CraftingTransaction
	- All API methods have been removed and are now handled in CraftItemEvent
- CraftItemEvent
	- added the following:
		- getInputs()
		- getOutputs()
		- getRepetitions() (tells how many times a recipe was crafted in this event)
- Recipe interface:
	- Removed getResult() (individual recipes may handle this differently)
- CraftingRecipe interface
	- removed the following:
		- matchItems()
		- getExtraResults()
		- getAllResults()
	- added the following
		- getResults()
		- getIngredientList() : Item[], which must return a 1D array of items that should be consumed (wildcards accepted).
		- matchesCraftingGrid(CraftingGrid)
- ShapedRecipe
	- constructor now accepts string[], Item[], Item[]
- ShapelessRecipe
	- constructor now accepts Item[], Item[]
2018-03-29 12:05:22 +01:00
Dylan K. Taylor
bc836aaec1 Make CraftingManager::sort() more cool with spaceship operators 😎 2018-03-29 11:45:12 +01:00
Dylan K. Taylor
145a4fad0f CraftingManager: Make sort() static
this doesn't need access to $this
2018-03-29 11:45:06 +01:00
Dylan K. Taylor
08c48d8145 CraftingRecipe: removed requiresCraftingTable()
the requirement for a crafting table is determined by the number of ingredients can fit on the grid (shapeless) or the max height and width (shaped). It's impossible to craft a big recipe with a small crafting table simply because you're not able to put the required resources into the grid.
2018-03-29 11:43:31 +01:00
Dylan K. Taylor
81ecb56095 ShapedRecipe: fixed bug in constructor 2018-03-29 11:32:39 +01:00
Dylan K. Taylor
a6d7365a28 Moved CraftingManager init to its own function
this allows the crafting manager to be re-initialized on the fly without recreating it.
2018-03-29 11:32:22 +01:00
Dylan K. Taylor
1f4f8ab3f0 Inventory: Removed BigCraftingGrid, allow arbitrary size parameter
This is more flexible and requires less classes.
2018-03-29 11:24:28 +01:00
Dylan K. Taylor
1420cd1fa5 InventoryTransaction: Added a more robust action flattening mechanism
This now handles the case where there are multiple options which could be taken, and opts for the first result which successfully ties all the actions together. Previously it would be entirely down to chance (ordering) whether the actions would get ordered successfully.
2018-03-29 11:23:52 +01:00
Dylan K. Taylor
30a83544a0 don't break double chests 2018-03-27 10:23:18 +01:00
Dylan K. Taylor
7e20385bdb BaseInventory: improved performance of getContents()
this old code is extremely inefficient. This showed up distinctly in my crafting bruteforce benchmarks, where I discovered that getContents() accounted for the vast majority of the time taken to match shaped recipes.
2018-03-27 10:13:55 +01:00
Dylan K. Taylor
c7e803372c Inventory: added API method isSlotEmpty() 2018-03-26 09:24:00 +01:00
Dylan K. Taylor
cf3638ad8d BaseInventory: fixed doc comment for slots field 2018-03-26 09:22:38 +01:00
Dylan K. Taylor
0dd8fd2651 CraftingTransaction: fixed ingredient map trimming (again)
closes #2118
2018-03-25 13:46:39 +01:00
Dylan K. Taylor
a4c50d3204 Remove unused imports 2018-03-24 11:59:15 +00:00
Dylan K. Taylor
1648fff916 Replaced Position->getLevel() null checks with isValid() 2018-03-20 11:10:36 +00:00
Dylan K. Taylor
73e09392b6 Timings: Clean up some terrible code, move namespaces 2018-03-19 19:05:51 +00:00