1151 Commits

Author SHA1 Message Date
Dylan K. Taylor
926f68d8c5
Move SkinAdapter under TypeConverter, remove SkinAdapterSingleton
this is legacy cruft from PM3, which didn't have TypeConverter or SingletonTrait.
2023-05-06 17:53:24 +01:00
Dylan K. Taylor
ed11fd5a83
CS again... 2023-05-06 17:51:00 +01:00
Dylan K. Taylor
e0a6ec0c24
Start deglobalizing TypeConverter
there's a bunch of places we can't reach with this right now:

- particles
- sounds
- tile NBT
- entity metadata
- crafting data cache
- chunk encoding
- world block update encoding

this is a work in progress, but ultimately we want to get rid of these singletons entirely.
2023-05-06 17:47:09 +01:00
Dylan K. Taylor
5c7f4570b4
Merge branch 'minor-next' into major-next 2023-05-06 17:20:37 +01:00
Dylan K. Taylor
bb60a9057f
Merge branch 'stable' into minor-next 2023-05-06 17:08:29 +01:00
Dylan K. Taylor
4caa2c7690
NetworkSession: send FLYING flag on spectator ability layer
fixes #5722

I'm not very clear why this works. PM doesn't use real spectator mode yet (we're still using the faux spectator mode PM has had for years, because I haven't yet assessed how real spectator mode will affect stuff like block interactions), so this ability layer shouldn't have any effect.

thank you @Alemiz112
2023-05-06 15:54:23 +01:00
Dylan K. Taylor
8a374df801
BlockTranslator: remove useless call to generateDataFromStateId()
BlockStateDictionary doesn't retain BlockStateData anymore, so this optimisation is just wasting CPU cycles.
2023-05-05 17:02:50 +01:00
Dylan K. Taylor
02cf5ed388
RuntimeBlockMapping: lazy-load NBT blockstates
this saves a considerable amount of memory.

we don't actually need this state array in PM4 anyway, since we don't support the client-side chunk cache yet.
when the time comes to support it, it'll be much more practical to cache binary states and copy bytes anyway, instead of doing it the current way, which is both slow and memory-intensive.

Measured footprint change: 9 MB -> 400 KB.
2023-05-05 16:18:03 +01:00
Dylan K. Taylor
f2c6a75145
BlockStateDictionary: reduce memory footprint of id/meta -> state ID lookup by >60%
the aim of the game here is to avoid allocating lots of tiny arrays, which have a terrible overhead:useful-data ratio.
This reduces the footprint of the mapping from 1.6 MB to 600 KB.
2023-05-05 15:26:54 +01:00
Dylan K. Taylor
09e823e304
BlockStateDictionary: remove useless indirection 2023-05-05 14:52:21 +01:00
Dylan K. Taylor
289ede669d
BlockTranslator: use less ambiguous function names 2023-05-05 14:47:23 +01:00
Dylan K. Taylor
4f32f5e0b7
BlockStateDictionaryEntry: encode property names as well as values
sadly we need these to reconstruct the state upon deserialization
2023-05-05 13:41:06 +01:00
Dylan K. Taylor
633e77a34c
RuntimeBlockMapping: share states CompoundTags if they are the same
this allows saving about 4 MB of memory, because there are many blocks which have identical states, although they have different IDs.

this relies on a potentially risky assumption that the tags in knownStates won't be modified. If they are modified, the changes will influence all blockstates which share the tag.
However, I don't expect this to happen, and the 4 MB memory saving is substantial enough to be worth the risk.
2023-05-04 23:21:54 +01:00
Dylan K. Taylor
092d130c96
RuntimeBlockMapping: borrow a hack from PM5 to reduce memory footprint
we can't change the internals of this on a patch release, but this hack provides a 12 MB memory usage reduction, which is very significant.
2023-05-04 23:01:10 +01:00
Dylan K. Taylor
f1417e8dc9
BlockStateDictionaryEntry: deduplicate encoded states
this saves about 500 KB of memory at no cost.
2023-05-04 16:14:41 +01:00
Dylan K. Taylor
897ba9f2d9
BlockStateLookupCache: combine arrays for stateless and stateful blocks
this reduces memory usage by another 20 KB or so.
2023-05-04 15:29:27 +01:00
Dylan K. Taylor
d2c37d8bcf
BlockStateLookupCache: avoid allocating useless arrays for blocks with only 1 permutation
this saves about 120 KB of memory.
2023-05-04 15:16:18 +01:00
Dylan K. Taylor
43fe819862
BlockStateDictionary: added a smelly hack that saves another 40 KB
this is really diminishing returns at this point...
2023-05-03 23:18:06 +01:00
Dylan K. Taylor
f9d9cbd0f6
BlockStateDictionary: slash another 14% off memory usage by deduplicating block type names
perhaps we could construct a dictionary from BlockTypeNames reflection??
2023-05-03 23:14:53 +01:00
Dylan K. Taylor
ed021d193d
BlockTranslator: cut memory usage in half
this was achieved by storing binary representations of the blockstates, rather than the original BlockStateData.

Due to the insane object:data ratio of Tag objects (40:1 for ByteTag for example), modestly sized NBT can explode in memory footprint. This has been previously seen with the absurd 25 MB footprint on file load.
Previously, I attempted to mitigate this by deduplicating tag objects, but this was mitigating a symptom rather than addressing the cause.

We don't actually need to keep the NBT around in memory, since we don't actually use it for anything other than matching blockstates. In this case, we can allow the code to be possibly a little slower, since the lookup is anyway slow and the result will be cached.
In fact, using encoded ordered states as hash keys significantly improves the speed of lookups for stuff like walls, which have many thousands of states.

We keep around generateStateData(), since it's still possible we may need the BlockStateData associated, and it can be easily reconstructed from the binary-encoded representation in BlockStateDictionaryEntry.
2023-05-03 23:11:00 +01:00
Dylan K. Taylor
32e6fdd95a
Rename RuntimeBlockMapping -> BlockTranslator 2023-05-03 22:18:27 +01:00
Dylan K. Taylor
01f340985a
Centralize all conversion-related stuff under TypeConverter
instead of having singletons for everything, which are a nightmare to manage for multi version
2023-05-03 16:33:17 +01:00
Dylan K. Taylor
5e462db0f8
Move MOTD game mode stringifying to RakLibInterface
since this is contextless (there's no way to know the version of the client requesting the MOTD), we can safely assume that this is not going to vary between protocol versions.
2023-05-03 13:36:24 +01:00
kenzeve
17fe894229
TypeConverter: fixed crash on unknown blockitems (#5729)
morton2d_encode is 64-bit function when NBT int tag is 32-bit only, resulting in crash
2023-04-30 12:11:07 +01:00
Dylan K. Taylor
b70ff32548
ItemTranslator: Fixed log items not displaying correctly on the client
closes #5724

this uses a (potentially bogus) assumption that the lowest mapped meta value associated with an ID is valid. I don't want to break this during a patch release, and this works for now.

In the future it would probably make more sense to bypass ItemTranslator entirely, and rely solely on the blockstate returned by RuntimeBlockMapping to fetch the correct ID. This is similar to how we serialize items for saving on disk in PM5.
2023-04-28 13:54:40 +01:00
Dylan K. Taylor
7c19f14cf5
Fixed up offhand handling for ItemStackRequest, fixes #5723 2023-04-27 13:25:08 +01:00
Dylan K. Taylor
5a54d09869
InventoryManager: verify slot existence in locateWindowAndSlot()
previously, this would happily return invalid slot IDs, potentially leading to a crash.
2023-04-27 13:18:28 +01:00
Dylan K. Taylor
0dca85af44
Merge branch 'minor-next' into major-next 2023-04-26 23:28:27 +01:00
Dylan K. Taylor
0d21e591d1
Support sign editing UI in 1.19.80, with APIs to allow plugins to use it
this doesn't support editing the rear side of a sign, since the 1.12 format doesn't allow us to represent the rear text, and it would necessitate API breaks to support anyway.

However, we can quite trivially support APIs for the sign GUI, which plugins can use to enable editing signs. PocketMine-MP doesn't currently permit this, since it's currently an experimental feature in 1.20, but plugins can simply use Player->openSignEditor() to mimic it.

This is, however, a byproduct of the fact that APIs needed to be added in order to facilitate the use of OpenSignPacket in 1.19.80.
2023-04-26 22:55:05 +01:00
Dylan K. Taylor
408616723c
Changes for 1.19.80 2023-04-26 22:52:02 +01:00
Dylan K. Taylor
a0346fb6d3
Merge branch 'minor-next' into major-next 2023-04-26 14:29:32 +01:00
Dylan K. Taylor
a4f2b99ed5
InGamePacketHandler: queue slots for syncing if they appear in requestChangedSlots
this is essentially a prediction without the actual predicted item. We have to sync these regardless of what happens.

fixes #5708
2023-04-24 14:06:29 +01:00
Dylan K. Taylor
3ecc980bc4
ÂInventoryManagerEntry: fixed incorrect PHPDoc type 2023-04-24 13:42:11 +01:00
Dylan K. Taylor
107b56154b
ItemStackRequestExecutor: fixed stonecutter recipes
this uses the same dodgy hack used by CraftingTransaction, which assumes that getResultsFor() does not care about the crafting inputs.

While this is currently OK, since none of the currently-implemented recipes care about inputs anyway, it will become a problem when we implement shulker box recipes, so this needs to be addressed.

However, it can't be addressed without BC breaks, so this will have to be dealt with in PM5.

closes #5715
2023-04-24 13:35:00 +01:00
Dylan K. Taylor
c878bd8289
Merge remote-tracking branch 'origin/minor-next' into major-next 2023-04-20 00:18:19 +01:00
Dylan K. Taylor
a77fc8109f
TypeConverter: avoid repeated calls to getId() and getMeta() 2023-04-18 15:02:52 +01:00
Dylan K. Taylor
6102740ee3
TypeConverter: use a less slow hack to restore meta values on items sent by the client
this isn't even really needed anymore, since we don't decode items from the client since 4.18.

However, this may still be useful for tools.
2023-04-18 15:00:34 +01:00
Dylan K. Taylor
40168a457e
TypeConverter: fixed coreItemStackToNet() causing item NBT to be prepared twice
hasNamedTag() calls getNamedTag(), which calls serializeCompoundTag(), which writes the item's properties into the given NBT tag.
2023-04-18 14:43:25 +01:00
Dylan K. Taylor
d07acd0013
RakLibInterface: split error ID into 4-character chunks
this makes it easier to read, since the error ID can't be copy-pasted from the disconnection screen on the client.
2023-04-17 14:05:46 +01:00
Dylan K. Taylor
499b29b53a
Merge branch 'minor-next' into major-next 2023-04-12 21:04:08 +01:00
Dylan K. Taylor
18b528f72d
ItemStackRequestExecutor: fixed borked taking of created items
closes #5695
2023-04-12 21:01:46 +01:00
Dylan K. Taylor
a0dadc6e37
Merge branch 'minor-next' into major-next 2023-04-10 14:38:23 +01:00
Dylan K. Taylor
9e9b4db00f
Merge branch 'stable' into minor-next 2023-04-10 14:32:33 +01:00
Dylan K. Taylor
017fcde6aa
always the CS... 2023-04-10 13:56:53 +01:00
Dylan K. Taylor
24374297e7
NetworkSession: extract rate limiting functionality into its own unit, and apply a separate rate limit to game packets 2023-04-10 13:53:22 +01:00
Dylan K. Taylor
7b55c984bf
InGamePacketHandler: reduce debug noise on outdated movements 2023-04-07 21:40:46 +01:00
Dylan K. Taylor
61b0ad3e7f
PreSpawnPacketHandler: added dedicated timer for the humongous amount of crap that has to be sent pre-spawn 2023-04-05 20:58:49 +01:00
Dylan K. Taylor
7e1467f3f7
Merge branch 'minor-next' into major-next 2023-04-05 20:14:59 +01:00
Dylan K. Taylor
2936726bf8
Fixed packets sent by EntityEventBroadcaster not firing DataPacketSendEvent
closes #5670

I'm not super happy with this fix, since it can still be broken if StandardPacketBroadcaster is replaced by something else. However, fixing that problem is probably going to require internal BC breaks, which are not suitable for a patch release.
2023-04-03 22:46:14 +01:00
Dylan K. Taylor
9cd07f6721
NetworkBroadcastUtils: remove dead code
we don't allow changing the target list anymore, since it increases internal complexity, so this code is redundant.
2023-04-03 22:37:22 +01:00