964 Commits

Author SHA1 Message Date
Dylan K. Taylor
e1b7bf31bb
World: make the second parameter for getCollidingEntities() mandatory and non-nullable
the only reason to use getCollidingEntities() instead of getNearbyEntities() is if you have an entity that may or may not be collidable depending on certain conditions.
Really, I don't think this logic belongs in World at all, but for now it has to stay, because some other stuff depends on it.
2021-09-05 15:22:12 +01:00
Dylan K. Taylor
2fc33d3bff
World: remove unused variable 2021-09-05 15:15:48 +01:00
Dylan K. Taylor
19513c65f0
World: avoid code duplication between getCollidingEntities() and getNearbyEntities()
these two methods are very misleadingly named, but they do almost exactly the same thing - the only difference is that getCollidingEntities() does a couple of additional checks.
2021-09-05 15:13:22 +01:00
Dylan K. Taylor
2fe03757d5
PopulationTask: fixed PHPStan errors 2021-08-30 00:26:54 +01:00
Dylan K. Taylor
e0d6357eb7
OreType: use promoted constructo properties 2021-08-30 00:18:34 +01:00
Dylan K. Taylor
0289b45202
Chunk: Drop dirty flags for tiles and entities
instead, just ungate this and allow the provider to decide what to do.
Any chunk that contains entities or tiles is already always considered dirty, so the only thing the flags are good for is flagging chunks that previously had tiles and/or entities but no longer do.
In those cases, it's just removing keys from LevelDB anyway, so it's already very cheap.
Avoiding these redundant deletions is not worth the extra complexity and fragility of relying on flags to track this stuff.
2021-08-30 00:09:36 +01:00
Dylan K. Taylor
994a2c9eb9
Clean up entity/tile data loading from world providers 2021-08-29 23:11:18 +01:00
Dylan K. Taylor
938e430b0f
Convert Populator into an interface 2021-08-27 20:41:54 +01:00
Dylan K. Taylor
6c1fec8a29
Tree: renamed generateChunkHeight to generateTrunkHeight
I guess it must have been late at night when I originally wrote this code.
2021-08-27 20:32:07 +01:00
Dylan K. Taylor
beba0ffe15
Remove circular dependency between Tree and its children 2021-08-27 20:25:21 +01:00
Dylan K. Taylor
4778c1483a
Tree: fixed formatting error 2021-08-27 20:14:31 +01:00
Colin
8f89c04c51
Refactor Tree classes (#4407) 2021-08-27 20:11:05 +01:00
marshall
ee16a00c57
World: do not attempt placement of itemblock if stack size is zero (#4410)
This doesn't make any sense, and also caused a crash.
2021-08-27 13:14:56 +01:00
Colin
4189fbdaef
Added StructureGrowEvent (#4354)
This event is currently fired for tree and bamboo growth. Its intended use is for any plant growth that affects multiple blocks at once.

TODO: We could explore using this for cacti and sugarcane?
2021-08-25 14:05:30 +01:00
Colin
224d71f272
World: renamed getChunks() to getLoadedChunks() (#4393) 2021-08-23 21:23:35 +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
270ee5c085
Simplify registry method generation 2021-08-22 23:02:36 +01:00
Dylan K. Taylor
7d9f8ff4ed
World: do not use static:: for private property access 2021-08-21 15:46:19 +01:00
Dylan K. Taylor
8b9d7d6390
Support for nested TranslationContainers 2021-08-14 20:57:13 +01:00
Dylan K. Taylor
2293bd948d
Added KnownTranslationFactory and use it in as many places as possible
this makes translation usage much more statically analysable.
The only places this isn't used are:
- places that prefix translations with colours (those are still a problem)
- places where server/client translations don't match (e.g. gameMode.changed accepts different parameters in vanilla than in PM)
2021-08-10 14:50:40 +01:00
Dylan K. Taylor
91cb374220
LevelDB: fixed isPopulated state getting lost after chunk unload/reload 2021-08-08 16:01:45 +01:00
Dylan K. Taylor
22c3736d63
LightUpdate: micro optimisations opcache isn't smart enough for
this removes 6 unnecessary opcodes from computeSpreadLight() and 3 from computeRemoveLight(). Tested with opcache.opt_debug_level=0x20000.
2021-07-30 23:30:28 +01:00
Dylan K. Taylor
772935cd7e
Updated biome ID constants 2021-07-23 22:39:54 +01:00
Dylan K. Taylor
5874ce582a
Implemented bells 2021-07-19 17:00:56 +01:00
Dylan K. Taylor
676bacbee1
Improve the flexibility of WorldProvider registration
WorldProviders now have the following requirements removed:
- __construct() is no longer required to have a specific signature
- static isValid() no longer needs to be implemented (you will still need it for registering, but it can be declared anywhere now)
- static generate() no longer needs to be implemented

This paves the way for more interesting types of world providers that use something other than local disk to store chunks (e.g. a mysql database).

WorldProviderManager no longer accepts class-string<WorldProvider>. Instead, WorldProviderManagerEntry is required, with 2 or 3 callbacks:
- ReadOnlyWorldProviderManager must provide a callback for isValid, and a callback for fromPath
- WritableWorldProviderManagerEntry must provide the same, and also a generate() callback

In practice, this requires zero changes to the WorldProviders themselves, since a WorldProviderManagerEntry can be created like this:
`new WritableWorldProviderManagerEntry(\Closure::fromCallable([LevelDB::class, 'isValid']), fn(string ) => new LevelDB(), \Closure::fromCallable([LevelDB::class, 'generate']))`

This provides identical functionality to before for the provider itself; only registration is changed.
2021-07-13 16:55:21 +01:00
Dylan K. Taylor
654fc9a2a6
LegacyStringToItemParser: Throw more specific exceptions 2021-07-10 21:03:12 +01:00
Dylan K. Taylor
9afc5be0f5
Shulker open/close sounds != shulker box open/close sounds 2021-07-10 19:59:59 +01:00
Aericio
fc090e238d
Add Shulker Boxes (#3678)
this implementation is working, although incomplete:

- The shulker close sound should not be played until the end of the shulker closing animation, which takes approximately 1 second.
- An open shulker box has a different collision box than a closed one - it should be +0.5 in whichever direction the shulker is facing. (During the animation, the bounding box also dynamically changes size - you can see this in vanilla by shooting an arrow into the top of an open shulkerbox facing UP, and then closing it - the arrow will fall and collide with the lid multiple times.

However, resolving both of these issues requires significant internal changes which are beyond the scope of this PR.
2021-07-10 19:48:38 +01:00
Dylan K. Taylor
91d54ff0ad
Removed unnecessary and/or obsolete GC hacks
the intent of these hacks was to break cyclic references to avoid having objects lingering in memory. However, all of the stuff that's being removed in this commit no longer has any effect anyway, due to the fact that these things don't circularly reference each other anymore. Notably, Tile inventories now keep Position instead of a Tile ref.
2021-06-30 19:16:25 +01:00
Dylan K. Taylor
94e16f416d
Added KnownTranslationKeys (generated) and start using it 2021-06-29 22:46:04 +01:00
Dylan T
32d7b1e6af
Start using webmozart/pathutil for joining paths (#4287) 2021-06-29 19:40:43 +01:00
Dylan K. Taylor
02fab77e55
World: change 'closed' to 'unloaded'
this makes more sense overall from a reader's perspective.
and also provide a rug-jerk for any idiots using World->close() when they aren't supposed to? ....
2021-06-26 21:54:18 +01:00
Dylan K. Taylor
fc70b625b3
ExperienceOrb: Require providing XP value in constructor 2021-06-19 19:42:13 +01:00
Dylan K. Taylor
981b0285d1
Isolate config casting nastiness in one place
this doesn't solve the underlying problem, but it does reduce the amount of noise made by PHPStan about it, as well as avoiding code litter.
2021-06-19 19:14:02 +01:00
Dylan K. Taylor
d96fc17339
World: Check placed block collision boxes after place()
since we write these into a transaction instead of actually modifying the world directly, we can use the transaction to verify that the placement location is OK before setting the blocks.
closes #4248
2021-06-18 19:07:38 +01:00
Dylan K. Taylor
f1583f44df
LightArray: Avoid allocating 7 useless arrays for every node processed
instead, use a const array of the offsets and add them to the coordinates, which avoids the allocations.
In synthetic benchmarks, this method takes 40-50% less CPU time by eliding ZEND_INIT_ARRAY and ZEND_ADD_ARRAY opcodes. In practice, the benefit will likely be much smaller (perhaps even irrelevant).
2021-06-17 22:21:58 +01:00
Dylan K. Taylor
71a4ea2a95
FastChunkSerializer: remove useless variable initialization 2021-06-17 20:59:40 +01:00
Dylan K. Taylor
43f71d0d63
FormatConverter: Copy worlds for backup if rename fails
this can fail if the backups directory points to a different drive than the original worlds location. In this case, we have to copy and delete the files instead, which is much slower, but works.
I REALLY advise against putting backups on a different mount point than worlds if you plan to convert large worlds.
2021-06-17 20:46:34 +01:00
Dylan K. Taylor
61c59be299
Replace hardcoded block metadata shifts and masks with constants
we might want to make these bigger than 4 bits in the future.
2021-06-16 12:48:09 +01:00
Dylan K. Taylor
e7b21cf9dc
World: remove obsolete TODO comment
[ci skip]
2021-05-21 13:10:48 +01:00
Dylan K. Taylor
2ab751f985
World: fixed potential bug scheduling async light updates multiple times 2021-05-21 13:09:38 +01:00
Dylan K. Taylor
e4750ad2cd
WorldTimings: apply native typehints 2021-05-17 23:23:46 +01:00
Dylan K. Taylor
7217ff5ff5
World: added an extra subtiming for random chunk updates 2021-05-17 23:18:56 +01:00
Dylan K. Taylor
4736b5968d
WorldTimings: change some idiotic timer names 2021-05-17 23:14:30 +01:00
Dylan K. Taylor
cdaf734470
World: Clean up ticking chunk loader tracking 2021-05-17 23:07:48 +01:00
Dylan K. Taylor
643c3ed14e
World: Require all adjacent chunks to a ticking chunk candidate to be unlocked, generated, loaded and light-populated
this should address the remaining problems with grass spread/death.
2021-05-17 20:59:40 +01:00
Dylan K. Taylor
7abf50f503
World: Extracted a tickChunk() method from tickChunks()
most of what's left in tickChunks() is just selecting the chunks, rather than actually ticking them.
2021-05-17 20:54:51 +01:00
Dylan K. Taylor
bab76f4a6e
World: extract some blocks of logic from tickChunks() into their own methods
the amount of nested loops, cx/dx/chunkx/etc clusterfuck in this code makes it very difficult to work with...
2021-05-17 20:50:46 +01:00
Dylan K. Taylor
bdce781c6d
Chunk: do not close preexisting tiles in addTile()
if it's desired to actually replace a tile, the old tile should be explicitly removed and closed first.
2021-05-12 12:32:36 +01:00
Dylan K. Taylor
b2e806e2fa
World: Harden chunk loading against bad data in entity/tile NBT 2021-05-12 12:26:41 +01:00