494 Commits

Author SHA1 Message Date
Dylan K. Taylor
6f54b53f7a thanks for being useless PhpStorm
these problems didn't show up in any inspections until I opened the fucking files...
2019-03-17 15:53:59 +00:00
Dylan K. Taylor
ad19696364 Make Effect and Enchantment functions less verbose 2019-03-13 15:26:21 +00:00
Dylan K. Taylor
01904adf49 Improve enum implementations, move some components to traits
The reason this uses a trait is because `self` refers to the including class in a trait, which offers a small amount of automatic type safety.
If we had templates or generics, this would be a generic class instead.
2019-03-13 15:10:31 +00:00
Dylan K. Taylor
0e1a88f7e5 Armor: Implement right-click to equip, closes #2641 2019-03-12 19:01:36 +00:00
Dylan K. Taylor
8b9eeb0b7f Clean up Armor classes 2019-03-12 18:53:51 +00:00
Dylan K. Taylor
fc9a61859a Item: remove misleading methods & premature optimization 2019-03-03 12:36:46 +00:00
Dylan K. Taylor
abbdd7efdd Item: make __toString() use base64 for displaying NBT 2019-03-03 12:33:28 +00:00
Dylan K. Taylor
6c8fa8ae28 More nullable and void typehints 2019-03-02 10:29:11 +00:00
Dylan K. Taylor
d961b272c7 Remove Tool <-> Block circular dependency in efficiency calculation 2019-03-01 18:18:56 +00:00
Dylan K. Taylor
e9125af51d Revamp Banner API (still rather ghetto)
this needs more work, like signs do.
2019-03-01 17:57:07 +00:00
Dylan K. Taylor
9ad0ea85c7 Rename two misleadingly-named functions 2019-02-27 12:59:12 +00:00
Dylan K. Taylor
cb91afcc00 Added SkullType enum, some cleanup to skull handling
this is still more ugly than I'd like it to be because of the way the blockfactory currently works.
2019-02-26 18:27:30 +00:00
Dylan K. Taylor
97687f2236 Dye, banner and bed items now store DyeColor objects instead of using magic meta values 2019-02-24 10:48:40 +00:00
Dylan K. Taylor
c26544475e More PHP 7.1 nullables 2019-02-22 12:55:34 +00:00
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