PrismarineJS / PrismarineJS/minecraft-data
Express Enum X metadata somewhere for each protocol version
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 938
- Forks
- 294
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 23
Description
I'm currently implementing a generator for minecraft-data that will produce complete Haskell implementations for each protocol version currently present. However, due to how significant static typing is to my target language, it would be very useful to have the various enum values in the protocol included somewhere such that I can bound their respective packet fields to only valid values that actually have meaning.
For instance, this enum exists:
Animation
0 Swing main arm
1 Take damage
2 Leave bed
3 Swing offhand
4 Critical effect
5 Magic critical effect
This information can be statically encoded through Haskell's type system as an algebraic data type like such:
data Animation
= SwingMainArm
| TakeDamage
| LeaveBed
| SwingOffhand
| CriticalEffect
| MagicCriticalEffect
deriving (Show,Eq,Enum)
Where the Enum at the bottom automatically maps SwingMainArm to 0, TakeDamage to 1, etc.
This allows me to generate functions that encode and decode the field to recognize and enforce valid animation values.
encodeAnimation :: Animation -> Word8
decodeAnimation :: Word8 -> Either String Animation
This way my API abstracts away from raw bytes and can instead talk at a type level in terms of the meanings those bytes have from the perspective of the protocol.
Even better, Haskell's API documentation tool can produce some very helpful documentation if it's fed types like the one above instead of just explanatory comments informing the user which byte values actually mean something within the context of the current version of the protocol. They shouldn't have to keep track of how game state and behaviors serialize, that's the whole reason I'm writing this library in the first place.
So I guess the realization of this feature request would probably take the form of a enum.json included in each protocol version directory that provides mappings of bytes to names for each enum present in the given protocol version. So something like:
"enum": [
"container",
[
{
"name": "animation",
"type": [
"mapper",
{
"type": "u8",
"mappings": {
"0x00": "swing_main_arm",
"0x01": "take_damage",
"0x02": "leave_bed",
"0x03": "swing_offhand",
"0x04": "critical_effect",
"0x05": "magic_critical_effect"
}
}
]
},
etc,etc,etc...
]
]
There would then need to be some way to map these enums onto their intended fields in protocol.json. Perhaps by specifying packet ID for all packets that use the enum field.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the protocol.json files and the protocol version directories mentioned in the request, then determine how enum.json should represent mappings and associate them with packet fields. Done means an agreed schema and complete per-version enum data with a defined link to the fields that use each enum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, javascript
- Domain
- data, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100