Commit Graph

24 Commits

Author SHA1 Message Date
015c668885 Change confusing 'type data' and 'state data' terminology for blocks and items
For blocks, we now use 'block-item state' and 'block-only state', which should be much clearer for people implementing custom stuff.
'block-item state', as the name suggests, sticks to the item when the block is acquired as an item.
'block-only state' applies only to the block and is discarded when the block is acquired as an item.

'type data' for items was also renamed, since 'type' is too ambiguous to be anything but super confusing.
2023-05-16 14:07:29 +01:00
6c0ad9589b Block: rename isSameType() to hasSameTypeId()
this should remove any ambiguity about its behaviour.
2023-04-21 20:25:21 +01:00
874fdf5adb ItemBlock: reference blocks directly (take 2)
This was first attempted in f64dc01bd1, but reverted, since I hadn't considered how to handle stripping state data from blocks.

This removes the abusable API RuntimeBlockStateRegistry::fromTypeId() and related methods. These were only used to allow ItemBlocks to magically start referencing other blocks if the blocks were overridden by a plugin, but this was never a well-supported use-case anyway.

Instead of relying on RuntimeBlockStateRegistry, we remember the state that the block had during its constructor, and use that to normalize the non-item properties for asItem().

closes #5609
2023-04-13 12:44:54 +01:00
7c974a12e1 Revert "ItemBlock: drop the charade about overriding built-in block types"
This reverts commit f64dc01bd1.

I forgot that the ItemBlock constructor implicitly strips off any states
of the origin block, which is something that we unfortunately can't do
any other way right now, since the blocks don't remember their default
states.
2023-03-02 15:51:55 +00:00
f64dc01bd1 ItemBlock: drop the charade about overriding built-in block types
this allows cleaning up a whole lot of abusable mess from the API, and we never properly supported overriding built-in block types anyway.
2023-03-02 15:50:18 +00:00
55a48e0c84 Block: specifying required type/state data bits is no longer required
RuntimeDataSizeCalculator allows calculating the number of required bits from describeType directly, which considerably reduces boilerplate code.
2023-02-16 16:45:19 +00:00
c2f6d8139a Added interface RuntimeDataDescriber 2023-02-16 16:23:32 +00:00
6a2315a63d Accept BlockTypeInfo in Block constructor, instead of BlockBreakInfo
this will allow more stuff to be passed via the constructor without having to change dozens of classes to do it.
2022-07-23 20:42:54 +01:00
6d4279671e A giant hack to cut down code needed for runtime block serialization by 50%
this also avoids repeated information and inconsistencies.
2022-07-18 18:25:41 +01:00
8660dfe576 Generate traits for runtime enum serialization instead of helper classes 2022-07-18 15:16:33 +01:00
325f1cf82e Generalize runtime block data serialization
we want to reuse this code for item type data
2022-07-05 14:13:37 +01:00
3792ef5a50 Move blockstate data runtime serialization to a more appropriate package 2022-07-02 16:48:41 +01:00
0afb67be7d Improve BlockFactory initialization performance
as expected, expanding data range unconditionally resulted in some performance issues ...
2022-06-27 15:37:05 +01:00
f24f2d9ca9 Hit block legacy metadata with the biggest nuke you've ever seen
This commit completely revamps the way that blocks are represented in memory at runtime.

Instead of being represented by legacy Mojang block IDs and metadata, which are dated, limited and unchangeable, we now use custom PM block IDs, which are generated from VanillaBlocks.
This means we have full control of how they are assigned, which opens the doors to finally addressing inconsistencies like glazed terracotta, stripped logs handling, etc.

To represent state, BlockDataReader and BlockDataWriter have been introduced, and are used by blocks with state information to pack said information into a binary form that can be stored on a chunk at runtime.
Conceptually it's pretty similar to legacy metadata, but the actual format shares no resemblance whatsoever to legacy metadata, and is fully controlled by PM.
This means that the 'state data' may change in serialization format at any time, so it should **NOT** be stored on disk or in a config.

In the future, this will be improved using more auto-generated code and attributes, instead of hand-baked decodeState() and encodeState(). For now, this opens the gateway to a significant expansion of features.
It's not ideal, but it's a big step forwards.
2022-06-24 23:19:37 +01:00
38d6284671 Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
6482aa7c64 Block: introduce logic for face support types (#4886)
fixes #4856
fixes #458
fixes #4529
fixes #3299

Added API method Block::getSupportType(Facing) : SupportType
Added SupportType enum
fixes torch, lantern, door etc. placement on slabs and upside-down stairs
2022-05-20 15:18:34 +01:00
79d1feff9c Replace disallowed operators in src/block/ 2022-01-20 16:57:09 +00:00
f68b9e79e1 Use typed properties in block namespace 2021-05-22 23:52:31 +01:00
73c229a236 Block: fixed LSP violations in blocks using BlockIdentifierFlattened
a property's type can't be changed by a subclass
2021-05-22 23:40:54 +01:00
8e2b9b686b Block: Invert default behaviour of silk touch (more logical)
Now, blocks do not respond to silk touch unless specifically opted into. Since this always involves custom drops in one way or another, it's easy enough to figure out which blocks need to be marked for silk touch - anything that overrides getDrops, getDropsForCompatibleTool or getSilkTouchDrops is a block which _might_ need to be flagged. Using these criteria to reduce the number of blocks needing to be checked, I was able to manually invert the behaviour as needed.

This fixes reoccurring bugs with blocks erroneously dropping themselves whenever new blocks are added and someone forgot to set that flag, granting players access to internal blocks with strange behaviour.
2020-05-21 13:02:36 +01:00
72f59eca3c Slab: ignore silk touch on breaking tools, closes #2794 2020-05-21 11:46:43 +01:00
67bcc1c0fb phpdoc armageddon for master, pass 1 2020-01-22 11:55:03 +00:00
4898a35613 cleanup block dual bounding box clusterfuck
"bounding box" serves no tangible purpose, only collision boxes do right now.
2019-08-15 17:23:55 +01:00
5499ac620c Removed pocketmine subdirectory, map PSR-4 style 2019-07-30 19:14:57 +01:00