480 Commits

Author SHA1 Message Date
Dylan K. Taylor
461233db09 ItemFactory: Sort items lexicographically ascending 2019-02-22 11:52:22 +00:00
Dylan K. Taylor
3037f45a0c Implement new dye types, split bonemeal and cocoa beans into their own classes 2019-02-22 11:43:48 +00:00
Dylan K. Taylor
7170d9009d Enchantment: more static getters, firehose magic numbers
This is similar in nature to 646fea5a4ecbbdf3f0cbfc590d874dedc1a7bfc0.

On a side note: Migrating this way is a pain in the ass due to lack of types. What the heck is int supposed to mean?!?!?!?! At least if we wanted to go _back_ to magic numbers, it would be easy to locate everything with an Enchantment typehint...
2019-02-20 13:45:50 +00:00
Dylan K. Taylor
646fea5a4e Effect: Introduce a bunch of static getters, change a bunch of API to use objects
This introduces static getters for every currently-known effect type. At some point in the near future, the magic number constants (which are really network IDs, by the way) will disappear.

Migrating:
- If you used constants (like any sensible person would): for the most part it's just a case of adding a () anywhere you used an Effect constant.
- If you hardcoded magic numbers: ... well, have fun fixing your code, and I reserve the right to say "I told you so" :)

This achieves multiple goals:
1) creating an EffectInstance for application is much less verbose (see diff for examples, especially the Potion class)
2) plugin devs cannot use magic numbers to apply effects anymore and are forced to use type-safe objects. :)

This is a warning shot for plugin devs who use magic numbers. More changes like this are coming in the not-too-distant future.
2019-02-20 12:05:17 +00:00
Dylan K. Taylor
2c8a065b94 Standardise SNAKE_CASE for surrogate enums 2019-02-20 11:14:07 +00:00
Dylan K. Taylor
36e9db4c07 Generate methods for surrogate enums, nip stupidity in the bud
this also allows changing the internal implementation later without breaking plugins.
2019-02-20 11:09:22 +00:00
Dylan K. Taylor
88c4b836f0 Make factory register methods less verbose 2019-02-20 10:24:44 +00:00
Dylan K. Taylor
84cf7c11e6 Fixed some overlooked returns from dce08b4e88bea4065149d6843d64344f7a25872a 2019-02-17 06:01:08 -05:00
Dylan K. Taylor
b252be1c7a Added ItemFactory::air() sugar
This makes it easier to create air stacks without accidents, and also reduces the amount of throwaway air objects which get created.
2019-02-16 12:19:54 +00:00
Dylan K. Taylor
dce08b4e88 Introduce Item use results - can be success, fail or none
closes #2693, closes #2705, closes #2734
2019-02-14 19:21:29 +00:00
Dylan K. Taylor
55be0716d8 Use DyeColor instead of ints for banners 2019-02-13 13:49:44 +00:00
Dylan K. Taylor
1496eefb8b Regenerated TODOs for item and b,locks
this sucks because it doesn't tell us anything about things that are meta values of other things (like dyes), but it's enough to start with.
2019-02-12 19:15:19 +00:00
Dylan K. Taylor
d30316101a Of course, there was a bug in the script... 2019-02-12 16:30:31 +00:00
Dylan K. Taylor
5227679602 sync item/block magic numbers with 1.9.0.15 2019-02-12 16:01:25 +00:00
Dylan K. Taylor
7b3993730a Block: Replace Color and WoodType magic numbers with type-safe objects
this provides automatic type safety without the need for magic number value checking everywhere.
2019-02-12 13:52:59 +00:00
Dylan K. Taylor
0c89159cf2 Merge branch '3.6' 2019-02-09 19:22:00 +00:00
Dylan K. Taylor
30b49e0d22 Merge branch '3.5' into 3.6 2019-02-08 15:32:20 +00:00
Dylan K. Taylor
769cc91543 ItemFactory: fix crash when getting negative item IDs
these are now treated the same as any unknown item, and are now not possible to place.
2019-02-08 13:51:41 +00:00
Dylan K. Taylor
b8703d5dff Protocol changes for 1.9.0 2019-02-07 21:56:42 +00:00
Dylan K. Taylor
78dfcc5f2d Move Effect and EffectInstance to entity\effect namespace 2019-01-28 15:41:07 +00:00
Dylan K. Taylor
6b7710e62b Introduce dedicated NBT data exceptions, fix up some corrupted chunk handling 2019-01-19 12:43:47 +00:00
Dylan K. Taylor
c34a4f45d4 Merge branch '3.5' 2019-01-15 14:46:03 +00:00
Dylan K. Taylor
0f545c410a Bow: Improve consistency with vanilla (JE at least), closes #2660
This change causes the existing test I did to now report ~55-60 blocks, which is much closer to parity with vanilla.
2019-01-15 14:42:41 +00:00
Dylan K. Taylor
2924303169 Sync NBT dependency 2019-01-07 22:38:04 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
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
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
e1064a9e36 Merge branch '3.5' 2019-01-04 00:37:48 +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
ff3d2ba19e Fixed no-NBT banner items always placing black banners, closes #2624 2018-12-31 22:04:08 +00:00
Dylan K. Taylor
f64cef7eb6 ItemFactory: Get rid of $multiple crap
this is required in a specialized format, which doesn't make any sense. Plugins with multiple packed item formats should parse them themselves.
2018-12-28 11:55:52 +00:00
Dylan K. Taylor
8564efc011 Sync item and block legacy IDs 2018-12-27 15:02:14 +00:00
Dylan K. Taylor
20aaa8373a Sound no longer extends Vector3 2018-12-16 14:26:42 +00:00
Dylan K. Taylor
ffa733fe0c Merge branch 'release/3.5' 2018-12-12 19:51:41 +00:00
Dylan K. Taylor
30f5a8fac6 Protocol changes for 1.8.0 release 2018-12-11 21:05:03 +00:00
Dylan K. Taylor
d72e4cb9a1 Tile: remove createNBT(), add create(), createFromData(), createFromItem() 2018-12-10 19:40:37 +00:00
Dylan K. Taylor
8051fa4f6d Remove some direct Position->level accesses 2018-12-03 21:39:17 +00:00
Dylan K. Taylor
ed531c0009 Merge branch 'release/3.4' 2018-11-29 19:57:35 +00:00
Dylan K. Taylor
05dba61a69 Merge branch 'release/3.3' into release/3.4 2018-11-29 19:47:28 +00:00
Dylan K. Taylor
60dddcd12a Painting: clean up guard checks, remove unnecessary checks 2018-11-29 19:29:10 +00:00
Twisted
3c86944a7c Item: make addEnchantment(), removeEnchantment() and removeEnchantments() fluent (#2523) 2018-11-13 16:48:13 +00:00
Dylan K. Taylor
95be571481 Fixed Item->equals() not working for no-NBT items since 9bb3c93285d8589cde855b08318e32514eff78c4 2018-10-29 12:45:39 +00:00
Dylan K. Taylor
e1795dfd49
Fixed wtf in Durable->setDamage() exception throw 2018-10-27 21:50:14 +01:00
Dylan K. Taylor
9bb3c93285 Remove network-serialized item NBT from API layer, item NBT is now retained for the lifetime of the stack 2018-10-27 15:26:01 +01:00
Dylan K. Taylor
0ef81e701a ItemFactory: Use a simple hashmap for item types
this is slower but yields less complicated code. Since this isn't in a hot path it's acceptable for this to slow down a little for the sake of sanity.
2018-10-26 18:38:24 +01:00
Dylan K. Taylor
93131b4d92 Rename some meta usages to variant 2018-10-26 18:20:37 +01:00
Dylan K. Taylor
7dd3b5b996 Durable: fixed leftover wtf from damage refactor 2018-10-26 18:17:34 +01:00
Dylan K. Taylor
327c8361bd Remove variant parameters from TieredTool 2018-10-26 18:16:31 +01:00
Dylan K. Taylor
f438736af5 Make some item constructor variant parameters mandatory 2018-10-26 16:51:02 +01:00