53 Commits

Author SHA1 Message Date
Dylan K. Taylor
2ef02a2c5e
Upgraded block consistency check to detect tile changes 2024-12-05 19:57:13 +00:00
Dylan K. Taylor
5325ecee37
Deal with a whole lot of PHPStan suppressed key casting errors
closes #6534
2024-11-25 14:30:58 +00:00
Dylan K. Taylor
de6a91dabc
Rework consistency check to tolerate dynamic type IDs
we don't actually care about the specific values, only whether all the blocks and their states have been correctly registered.
I'd prefer to track all of the state data permutations, but the APIs for that are private, so tracking the number of permutations will have to suffice (this should be good enough to detect bugs anyway, and also takes way less space).
2024-04-01 18:44:01 +01:00
Dylan K. Taylor
63fcf9879a
Block: Use xxhash'd XOR mask to improve state data lower bits distribution
xxhash is generally well known for its hash key properties, so this is a suitable use case.
We XOR the state data with a partial hash of xxh3(typeID), which provides sufficient hash distribution regardless of the size of state data.
The previous method started to break down as the number of bits exceeded the number of significant bits of type ID (about 10 currently).

As well as being better for hash distribution regardless of state data size, this also reduces the load factor of RuntimeBlockRegistry to 1.08 (previously around 1.24), which is a nice bonus.
2023-10-17 15:21:22 +01:00
Dylan K. Taylor
9c6d4093ae
Fixed crash when getting an item from a block which came from an item which came from a block
had a stroke yet?
2023-06-02 16:16:54 +01:00
Dylan K. Taylor
8744032ab6
Fixed empty block handling after blockstate ID XOR change 2023-05-29 18:26:23 +01:00
Dylan K. Taylor
9621836e36
Clean up confusing mess around block and item overriding
right now, I don't see an obvious reason to do this. If it turns out I was wrong later on, we can add functionality back, but we can't remove functionality after release.
2023-05-17 15:21:49 +01:00
Dylan K. Taylor
d4ca566fd0
Move block permutation generation into Block
this allows sealing off a whole bunch of internal APIs.
2023-04-21 20:38:28 +01:00
Dylan K. Taylor
1c626baf1a
Fixed dodgy custom block registration test 2023-04-13 12:27:55 +01:00
Dylan K. Taylor
95c18ef99a
Block: change confusing naming of decode/computeStateData
these actually accept a combination of type and state data, so it's a bit inconsistent with other references to 'state data'.
2023-03-02 17:42:44 +00:00
Dylan K. Taylor
7c974a12e1
Revert "ItemBlock: drop the charade about overriding built-in block types"
This reverts commit f64dc01bd1c14ff3f79bd6c18d0c337dbc0e87e0.

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
Dylan K. Taylor
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
Dylan K. Taylor
0a3ecfdae9
Clean up terminology around block state IDs and their handling 2023-01-25 19:01:15 +00:00
Dylan K. Taylor
4d79aced07
Merge branch 'next-minor' into next-major 2022-12-15 19:50:27 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
b0c76f4db5
Fixed botched unit tests 2022-07-06 23:28:08 +01:00
Dylan K. Taylor
0a23e91329
Rename BlockFactory::fromFullBlock() -> BlockFactory::fromStateId() 2022-07-05 13:46:19 +01:00
Dylan K. Taylor
b125d4d25f
Strip all remaining legacy item ID/meta stuff from blocks
the doors are now finally open, we can:
- make all the wood types dynamic
- fix glazed terracotta
- add all the new blocks

LET'S GOOOOOOOOOOOO
2022-07-02 17:48:11 +01:00
Dylan K. Taylor
00b4e4016c
Obliterate BlockLegacyIds 2022-06-25 14:42:32 +01:00
Dylan K. Taylor
e3a9324e8d
Updated BlockFactory tests to avoid BlockFactory::get() (which is getting ready to die) 2022-06-24 23:44:55 +01:00
Dylan K. Taylor
8e002fc1ca
BlockTest: fixed unintentional use of global BlockFactory 2022-06-24 23:41:13 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
1ff69136a3
Merge branch 'next-major' into modern-world-support 2022-06-07 20:01:40 +01:00
Dylan K. Taylor
38d6284671
Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
Dylan K. Taylor
bd8dd48dee
Assign new IDs to every block 2022-05-27 18:07:31 +01:00
Dylan K. Taylor
3c5300556a
Fixed tests 2022-03-23 15:27:57 +00:00
Dylan K. Taylor
334c9daa6a
BlockFactory: change property cache arrays to use regular arrays instead of SplFixedArray
this does come at a performance cost, but is necessary for metadata expansion.

we finally concede that this is not going to happen without BC breaks, however small they might be ...
2022-03-23 15:22:57 +00:00
Dylan K. Taylor
c2d3b23449
fixed BlockFactory consistency test - remapped states are no longer returned by getAllKnownStates() 2022-02-07 18:04:02 +00:00
Dylan K. Taylor
52f0c4f3ed
Removed dodgy test using invalid block metadata 2021-11-27 22:51:14 +00:00
Dylan K. Taylor
e43bca95bf
Fixed build 2021-06-26 17:40:43 +01:00
Dylan K. Taylor
2a6009f8bf
Check consistency of block remaps 2021-06-21 20:45:30 +01:00
Dylan K. Taylor
81ced66bd0
BlockIdentifier: variant parameter of constructor is now mandatory 2021-04-16 20:14:29 +01:00
Dylan K. Taylor
870d237260 BlockFactory::get() second parameter is now mandatory 2020-11-18 00:50:01 +00:00
Dylan K. Taylor
73a8c90bee Merge remote-tracking branch 'origin/stable'
# Conflicts:
#	resources/vanilla
#	src/world/Explosion.php
#	tests/phpunit/item/ItemTest.php
#	tests/phpunit/world/format/io/region/RegionLoaderTest.php
#	tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php
#	tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php
2020-11-01 14:21:47 +00:00
Dylan K. Taylor
500fd2d842 tests: strip useless phpdoc 2020-10-26 15:59:17 +00:00
Dylan K. Taylor
13d784cd0c Convert BlockFactory to singleton 2020-04-23 23:45:13 +01:00
Dylan K. Taylor
fb1126797a Merge branch 'stable' 2020-02-07 18:13:55 +00:00
Dylan K. Taylor
5ad66c3c9b BlockTest: throw exception instead of always-false assert 2020-02-06 13:21:39 +00:00
Dylan K. Taylor
532dc0fb6f tests/phpunit: populate iterable types for phpstan 2020-02-06 13:11:56 +00:00
Dylan K. Taylor
54216c2fee Block: Blow away a bunch of useless classes 2019-05-24 19:38:43 +01:00
Dylan K. Taylor
9e72bc91a2 Separate block break-info to a separate dynamic unit 2019-05-10 16:24:59 +01:00
Dylan K. Taylor
2a3e6dcf00 Rename BlockIds -> BlockLegacyIds 2019-03-23 19:46:31 +00:00
Dylan K. Taylor
79ef8e0803 Replace all legacy blockID references with BlockIds:: 2019-03-23 19:44:33 +00:00
Dylan K. Taylor
9ad0ea85c7 Rename two misleadingly-named functions 2019-02-27 12:59:12 +00:00
Dylan K. Taylor
6cb263fcca BlockFactory: enforce stricter checks
this can help catch out variant-related bugs.
2019-02-24 17:59:09 +00:00
Dylan K. Taylor
023fecabac Added an annoying consistency check for BlockFactory
This test is intended to enforce that the BlockFactory always has the same blocks in it from one commit to the next. Since there are a lot of changes going on right now around this, it's important that this is checked because bugs can go under the radar when large changes are happening.

The consistency check will need to be regenerated whenever a new block is registered, new states are found or when things are removed.
2019-02-24 13:56:55 +00:00
Dylan K. Taylor
f669677d17 BlockTest: fixed failing test
this is a bad fix, but it doesn't matter a whole lot. The problem stems from furnace not having a valid 0 variant, so things go haywire when the default mapped 0 variant is registered to LIT_FURNACE because the default state is of course unlit.
2019-02-22 18:56:14 +00:00
Dylan K. Taylor
707faef0f7 BlockTest: remove redundant name test
name is mandatory in the constructor now, so this isn't necessary anymore.
2019-02-22 18:54:21 +00:00
Dylan K. Taylor
6ab171d629 Fixed unit tests 2019-02-21 10:41:06 +00:00
Dylan K. Taylor
15d4201c3a Fixed tests broken by 88c4b836f09278a2d81a14356ff3c29ce465de1d 2019-02-20 11:16:08 +00:00