Skip to content

Commit 75ebb28

Browse files
committed
dontdiedontdiedontdie aaaaa
1 parent 389a8ac commit 75ebb28

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/en/reference/i18n.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Internationalization
2+
3+
`AUTHOR: Seggan`
4+
`HAS CONTEXT: Seggan`
5+
6+
Right... where do I even start...
7+
8+
## Translation in Paper
9+
10+
The Paper server translates most things for us already, as they are translated on the server before being sent to the client. This includes chat messages, bossbars, and action bars. However, for some strange reason, this does not extend to item names and lore. That leaves us with two options: either we translate items on the server side (which is what we do now), or we send the client a resource pack with translations included. One of the implicit goals of Pylon is to avoid requiring resource packs, so we went with server-side translation.
11+
12+
## Packet injection
13+
14+
Now for obvious reasons we cannot translate the item stacks themselves, as different people may use different languages and that would cause confusion. Instead, we inject a handler into the player's Nettey channel to intercept both incoming and outgoing packets.
15+
16+
The following outgoing packets are intercepted:
17+
18+
- `ClientboundContainerSetContentPacket`: sent when opening an inventory, contains the items in the inventory
19+
- `ClientboundContainerSetSlotPacket`: sent when an item in an inventory changes, contains the new item
20+
- `ClientboundSetCursorItemPacket`: sent when the item on the cursor changes, contains the new item
21+
- `ClientboundRecipeBookAddPacket`: sent when recipes are added to the recipe book, contains the items of the recipes
22+
- `ClientboundMerchantOffersPacket`: sent when opening a villager trade GUI, contains the items in the trades
23+
- `ClientboundPlaceGhostRecipePacket`: sent when placing a ghost recipe in a crafting grid, contains the items in the recipe
24+
25+
When the packet is intercepted, we translate the item stack(s) in the packet, using the Paper translation API to translate the name and lore of the item stack. As these items are copies, we can freely modify them in-place without affecting the actual item stacks.
26+
27+
Unlike outgoing, only two incoming packets are intercepted: `ServerboundSetCreativeModeSlotPacket` and `ServerboundContainerClickPacket`. These packets are intercepted to un-translate the item stacks back to their original names and lore, so that when the server receives them, it can process them correctly. This is done by looking up the original item stack in the Pylon item registry

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ nav:
5757
- Data-oriented interfaces: reference/data-oriented-interfaces.md
5858
- Fluids: reference/fluids.md
5959
- Cargo: reference/cargo.md
60+
- Internationalization: reference/i18n.md
6061
- Javadocs: javadocs.md
6162
- Contributing:
6263
- Getting started: contributing/getting-started.md

0 commit comments

Comments
 (0)