196 Commits

Author SHA1 Message Date
Dylan K. Taylor
ce5e663a73
Assume chunks are dirty by default
having them be clean by default makes no sense. It only makes sense for them to be clean if they were loaded directly from disk without any alterations.

Default clean is a footgun.
2023-05-29 17:22:39 +01:00
Dylan K. Taylor
2c81446e5b
Move TreeType to generator package, added dedicated SaplingType enum
TreeType includes a bunch of stuff that don't have regular saplings associated with them, such as mangrove and azalea trees.
Mangrove has a dedicated propagule block with different behaviour than the others, and azalea trees are grown from azalea blocks, which are solid and have different behaviour to saplings.

We may also want to account for crimson and warped 'trees' in TreeType too, although I'm not sure if those belong there or not.
2023-05-04 16:54:10 +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
2f12bb9943
Merge branch 'next-minor' into next-major 2023-02-06 12:34:57 +00:00
alvin0319
981385cf4a
GeneratorManager: Removed redundant Closure wrapping (#5551) 2023-02-04 14:04:31 +00:00
Dylan K. Taylor
2b987b450b
always the CS... 2023-01-26 14:58:32 +00:00
Dylan K. Taylor
f56339c306
Fix build 2023-01-26 14:48:43 +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
7abfc46567
First look at 3D biome support 2023-01-17 21:41:30 +00:00
Dylan K. Taylor
4d79aced07
Merge branch 'next-minor' into next-major 2022-12-15 19:50:27 +00:00
Dylan K. Taylor
99996b62d6
Align PhpDoc @param tags according to PHP-CS-Fixer 2022-12-06 13:21:20 +00:00
Dylan K. Taylor
1ecb10acba
Merge branch 'next-minor' into next-major 2022-08-21 19:19:07 +01:00
Dylan K. Taylor
c13170a00b
Avoid implicit integer cast in Normal::pickBiome()
this throws deprecation warnings on PHP 8.1.
2022-08-20 17:16:38 +01:00
Dylan K. Taylor
d9b050fb68
First look at using (very) basic tags for dynamic block properties
this allows plugins to, for example, add their own custom dirt-like blocks which support having flowers placed on them.
2022-07-24 00:08:02 +01:00
Dylan K. Taylor
0a23e91329
Rename BlockFactory::fromFullBlock() -> BlockFactory::fromStateId() 2022-07-05 13:46:19 +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
aa9f8781ff
Merge branch 'next-minor' into next-major 2022-06-07 19:56:26 +01:00
Dylan K. Taylor
d2613039ed
Replace BlockLegacyIds usages with BlockTypeIds where possible 2022-06-05 21:17:10 +01:00
Dylan K. Taylor
083a35f970
Modernize property type declarations 2022-06-04 18:16:32 +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
d4b7f66e15
Promote some constructors 2022-05-17 22:34:58 +01:00
Dylan K. Taylor
b88a47929f
Modernize property declarations in src/world/* 2022-04-28 15:06:17 +01:00
Dylan K. Taylor
159392e738
wtf is this shitbox code 2022-04-28 14:57:57 +01:00
Dylan K. Taylor
ed2a239334
Modernize property declarations in src/world/generator 2022-04-28 13:16:21 +01:00
Dylan K. Taylor
aae5962f6a
Replace disallowed operators in src/world/ 2022-01-20 19:05:23 +00:00
Dylan K. Taylor
6d249026cc
Merge branch 'legacy/pm3' into stable 2022-01-07 20:15:15 +00:00
Dylan K. Taylor
0a58fd5472
GeneratorManager: fixed addGenerator() being case-sensitive when overwrite=true
this was caused by 083a1e1ff6b6ff5c0c1ba14250d2b026af103b90.

This was discovered by a new PHPStan rule I'm working on, which disallows overwriting the values of parameter variables. During the refactor of this function to correct the error, another error appeared: Variable might not be defined.

This is yet another excellent example of why mutability is bad.
2021-12-12 21:58:07 +00:00
Dylan K. Taylor
269231c228
Ban foreach(arrayWithStringKeys as k => v)
this is not as good as phpstan/phpstan-src#769 (e.g. array_key_first()/array_key_last() aren't covered by this, nor is array_rand()) but it does eliminate the most infuriating cases where this usually crops up.
2021-11-15 22:52:05 +00:00
Dylan K. Taylor
0356716e8e
PopulationTask: do not expose internal fields as public
this code dates back to pthreads v2, when visibility on Threaded object fields meant different things (wtf, krakjoe??)
2021-11-03 15:23:43 +00:00
Dylan K. Taylor
5c81b04813
PopulationTask: use typed properties 2021-11-03 15:22:49 +00:00
Dylan K. Taylor
8b3565b75d
PopulationTask no longer depends on a World object
this means it's now possible to test generation offline without too much hassle.
World::generateChunkCallback() has been removed from public API.
2021-11-02 15:40:51 +00:00
Dylan K. Taylor
65ef9f786a
Use standard chunkHash() to index population chunks 2021-11-02 15:25:03 +00:00
Dylan T
0f78a2b5ef
Advisory chunk locking for chunk population (#4513)
this allows chunks locked for population to be modified. If the PopulationTask detects that the chunk was modified during the onCompletion(), the result of the population will be discarded and rescheduled, so that it includes user modifications.
2021-10-31 21:11:20 +00:00
Dylan K. Taylor
faad2365e2
World: Register a temporary chunk loader on chunks used by PopulationTask
fixes #3839
2021-10-30 22:17:06 +01:00
Dylan K. Taylor
d410db4302
Chunk: rename DIRTY_FLAG_TERRAIN to DIRTY_FLAG_BLOCKS
we use the word 'terrain' elsewhere to refer to the combination of blocks and biomes, so using TERRAIN here is misleading.
2021-10-28 22:11:07 +01:00
Dylan K. Taylor
a62ce64fdd
Revert "Chunk: added modification counter"
This reverts commit a5418a019dc2a83210084632130db8ce06f529ea.

The more I assessed this, the more I realized that this implementation
doesn't actually offer any value. Since modcounters don't persist after
chunk unload + reload, they can't be reliably used to detect changes in
chunks without additional event subscriptions.
For the purpose I actually intended to use them for (population task
cancellation) there's a) another solution, and b) modcounts are
unreliable for that too, because of the aforementioned potential for
chunks to get unloaded and reloaded.
For the case of detecting dirty chunks within PopulationTask itself,
they are also unnecessary, since the dirty flags are sufficient within
there, since FastChunkSerializer doesn't copy dirty flags.

In conclusion, this was a misbegotten addition with little real value,
but does impact performance in hot paths.
2021-10-28 21:02:04 +01:00
Dylan K. Taylor
51fbff204b
World: make PhpStorm understand return type of getAdjacentChunks() 2021-10-26 20:32:09 +01:00
Dylan K. Taylor
1873457840
PopulationTask: stop using dynamic properties 2021-10-26 20:21:58 +01:00
Dylan K. Taylor
8f88393184
World: Specialize generateChunkCallback() for PopulationTask
this allows us to also set the adjacent chunks before calling ChunkPopulateEvent, to give a more accurate picture of what changed.
2021-10-26 15:28:00 +01:00
Dylan K. Taylor
94f4ef5862
PopulationTask: Throw AssumptionFailedError if center chunk is null for some reason 2021-10-25 21:07:03 +01:00
Dylan K. Taylor
2e2515354c
PopulationTask: fixed undefined method call
fuck you PhpStorm! fuck you PhpStorm! fuck you PhpStorm!
2021-10-25 20:57:43 +01:00
Dylan K. Taylor
d4cbde6f10
PopulationTask: use modification counters to detect changed chunks
instead of using terrain dirty flags, which aren't suitable for this purpose
2021-10-25 20:53:50 +01:00
Dylan K. Taylor
baba25953f
Chunk: make all parameters of __construct() mandatory and non-nullable
having the constructor fill in defaults for these invariably causes bugs.
2021-10-25 20:22:50 +01:00
Dylan K. Taylor
401e8d117b
Flat: use a less dumb way to build biome array 2021-10-25 20:15:33 +01:00
Dylan K. Taylor
d73ea8efe4
FlatGeneratorOptions: Do not hardcode biome ID 2021-10-11 21:32:20 +01:00
Dylan K. Taylor
34f54750c8
Added support for creation-time validation of generator options, closes #2717 2021-10-11 17:37:47 +01:00
Dylan K. Taylor
092aabeb97
fix CS 2021-10-11 17:21:19 +01:00
Dylan K. Taylor
70deea0ef9
Flat: Move preset handling to a FlatGeneratorOptions unit 2021-10-11 16:53:08 +01:00
Dylan K. Taylor
859cdfa5d2
GeneratorManager: removed unused parameter from getGenerator() 2021-10-11 16:18:38 +01:00