59 Commits

Author SHA1 Message Date
Akmal Fairuz
269effcecf
Introduce Utils::getRandomFloat() (#6532)
Drop-in replacement for lcg_value() for PHP 8.4
2024-11-26 11:33:29 +00:00
Dylan K. Taylor
dbb5a32a96
Liquid: eliminate unnecessary Position allocations and getSide() calls 2023-10-19 17:09:13 +01:00
Dylan K. Taylor
9474324f75
Liquid: simplify code 2023-10-19 17:02:40 +01:00
Dylan K. Taylor
ada37899aa
Liquid: improve code legibility and fix a bunch of PHPStan errors 2023-10-19 17:02:22 +01:00
Dylan K. Taylor
f868c1d8c6
Liquid: Update legacy code with Facing::OFFSET 2023-10-19 16:38:34 +01:00
Dylan K. Taylor
d0d16cdeb7
RuntimeDataDescriber: Introduce boundedIntAuto, replacing boundedInt
closes #6096
boundedIntAuto automatically calculates the correct number of bits to use based on the given bounds. The bounds must be constant, of course.
2023-10-17 12:03:43 +01:00
Dylan K. Taylor
ae564e445d
Start migrating EnumTrait enums to PHP 8.1 native enums 2023-09-07 17:20:52 +01:00
Dylan K. Taylor
82f87cc2da
Reduce repeated block-change-event related code
the new helper code reveals even more repetition, but this is at least consistent now.
2023-08-02 13:40:12 +01:00
Dylan K. Taylor
537721fe7d
Replace Closure::fromCallable() usages with first-class callables
PHP 8.1 <3
2023-07-19 13:34:42 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
6c0ad9589b
Block: rename isSameType() to hasSameTypeId()
this should remove any ambiguity about its behaviour.
2023-04-21 20:25:21 +01: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
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
Dylan K. Taylor
c2f6d8139a
Added interface RuntimeDataDescriber 2023-02-16 16:23:32 +00:00
Colin
304bb84af2
BlockFormEvent: Added getCausingBlock() method (#5226) 2022-08-15 16:26:48 +01:00
Dylan K. Taylor
f6c9bf5cd1
Merge branch 'next-minor' into next-major 2022-07-20 20:55:33 +01:00
Dylan K. Taylor
2940547026
Eliminate repeated calls to Position->getWorld()
as well as improving readability, it also improves performance in some areas.
2022-07-20 20:44:05 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
4f2f9b4352
Block::readStateFromWorld() now returns the block object that should be used for the target position
this enables changing the block type completely if the situation calls for it.
2022-07-16 20:04:08 +01:00
Dylan K. Taylor
8b2d941502
Offset integer ranges in runtime block data serialization
this is useful for stuff like snow layers where the range doesn't start at 0.
2022-07-13 19:49:30 +01:00
Dylan K. Taylor
325f1cf82e
Generalize runtime block data serialization
we want to reuse this code for item type data
2022-07-05 14:13:37 +01:00
Dylan K. Taylor
3792ef5a50
Move blockstate data runtime serialization to a more appropriate package 2022-07-02 16:48:41 +01:00
Dylan K. Taylor
0afb67be7d
Improve BlockFactory initialization performance
as expected, expanding data range unconditionally resulted in some performance issues ...
2022-06-27 15:37:05 +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
d2613039ed
Replace BlockLegacyIds usages with BlockTypeIds where possible 2022-06-05 21:17:10 +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
6d7318af43
Liquid: fixed merge regression 2022-05-26 18:48:45 +01:00
ShockedPlot7560
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
Dylan K. Taylor
0642364a44
block: added constants for various integer property bounds 2022-01-28 21:27:30 +00:00
Dylan K. Taylor
79d1feff9c
Replace disallowed operators in src/block/ 2022-01-20 16:57:09 +00:00
Dylan K. Taylor
1ce388ca0b
Liquid: add getMinAdjacentSourcesToFormSource(), remove circular dependency between Liquid and Water
this unpleasantly-named method allows controlling the source-forming behaviour of liquids by changing the required number of adjacent sources that must be present in order for a new source to form. This allows stuff like non-infinite water.
2021-09-19 15:59:16 +01:00
Dylan K. Taylor
971cbe3929
Liquid: restore mistakenly removed check 2021-09-19 15:42:17 +01:00
Dylan K. Taylor
18de35ffc7
Liquid: use facing instead of hardcoded integers 2021-09-19 15:37:03 +01:00
Dylan K. Taylor
576c33ee8f
Liquid: make flow vector calculation less cancerous to read 2021-09-18 23:04:28 +01:00
Dylan K. Taylor
a9c4238c59
Liquid: Extract a big chunk of code to MinimumCostFlowCalculator 2021-09-18 16:13:38 +01:00
Dylan K. Taylor
34e1b244fa
Liquid: split canFlowInto() over multiple lines
the original version is very hard to read.
2021-09-18 15:53:54 +01:00
Dylan K. Taylor
b047100719
Liquid: improve minimum cost calculation handling 2021-09-18 15:52:16 +01:00
Dylan K. Taylor
1b5071e074
Liquid: make some code slightly less cancerous to read 2021-09-18 15:28:45 +01:00
Dylan K. Taylor
a1c82da2f2
Liquid: remove useless continue 2021-09-12 16:03:52 +01:00
SalmonDE
7fd712c1ff
Refactor Block & Tile: getPos() to getPosition() (#4395)
this also changes the name of the class property 'pos' to 'position' as well as Block->getPosOffset() to Block->getPositionOffset()
2021-08-23 14:01:32 +01:00
Dylan K. Taylor
f68b9e79e1
Use typed properties in block namespace 2021-05-22 23:52:31 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
376d2c4cd4
Consistently declare BlockBreakInfo at the constructor call site
instead of inside the class
2021-05-20 22:49:51 +01:00
Dylan K. Taylor
c1e5dd2a4e
Merge branch 'stable' 2021-03-07 20:15:11 +00:00
Dylan K. Taylor
32929925aa Block: added a bunch of state manipulation APIs 2020-11-03 19:13:32 +00:00
Dylan K. Taylor
3e21e47b7a Liquid: make getFlowVector() slightly less cancerous to read 2020-11-01 14:39:59 +00:00
Dylan K. Taylor
670ad9eb9d Position: rename getWorldNonNull() to getWorld(), remove original getWorld() 2020-06-29 21:19:46 +01:00
Dylan K. Taylor
f1048aeaa3 Block: rework addVelocityToEntity() to avoid vector3 mutation 2020-06-27 21:38:24 +01:00