Skip to content

Auto-Generate Protocol Types#370

Draft
smell-of-curry wants to merge 1 commit intoSandertv:masterfrom
smell-of-curry:auto-protocol-generator
Draft

Auto-Generate Protocol Types#370
smell-of-curry wants to merge 1 commit intoSandertv:masterfrom
smell-of-curry:auto-protocol-generator

Conversation

@smell-of-curry
Copy link
Contributor

@smell-of-curry smell-of-curry commented Dec 13, 2025

Remaining Tasks:

  • Properly handle the rest of the TODO's (requires handling of the complex mapping)
  • Figure out lack of ids
  • Remove all old protocol docs
  • Make a clean way to share types between (currently it just creates them again in same file)

@Happy2018new
Copy link
Contributor

Happy2018new commented Dec 13, 2025

It seems that the documents from mojang not support optional data type.
The following are some examples.

Debug Drawer Packet

Yours

func (x *ShapeDataPayload) Marshal(r protocol.IO) {
	r.Varuint64(&x.NetworkID)
	r.Uint8(&x.ShapeType)
	r.Vec3(&x.Location)
	r.Float32(&x.Scale)
	r.Vec3(&x.Rotation)
	r.Float32(&x.TotalTimeLeft)
	r.Int32(&x.Color)
	r.Varint32(&x.DimensionID)
	switch val := x.ExtraShapeData.(type) {
	case nil:
		var typeID uint32 = 0
		r.Uint32(&typeID)
		_ = val // nil value, nothing more to write
	}
}

But the real

// Marshal ...
func (x *DebugDrawerShape) Marshal(io IO) {
	io.Varuint64(&x.NetworkID)
	OptionalFunc(io, &x.Type, io.Uint8)
	OptionalFunc(io, &x.Location, io.Vec3)
	OptionalFunc(io, &x.Scale, io.Float32)
	OptionalFunc(io, &x.Rotation, io.Vec3)
	OptionalFunc(io, &x.TotalTimeLeft, io.Float32)
	OptionalFunc(io, &x.Colour, io.BEARGB)
	io.Varint32(&x.DimensionID)
	io.ShapeData(&x.ExtraShapeData)
}

Camera Instruction Packet

Yours

func (x *CameraInstructionEntry) Marshal(r protocol.IO) {
	protocol.Single(r, &x.Set)
	r.Bool(&x.Clear)
	protocol.Single(r, &x.Fade)
	protocol.Single(r, &x.Target)
	r.Bool(&x.RemoveTarget)
	protocol.Single(r, &x.FieldOfView)
	protocol.Single(r, &x.Spline)
	r.Int64(&x.AttachToEntity)
	r.Bool(&x.DetachFromEntity)
}

But the real

func (pk *CameraInstruction) Marshal(io protocol.IO) {
	protocol.OptionalMarshaler(io, &pk.Set)
	protocol.OptionalFunc(io, &pk.Clear, io.Bool)
	protocol.OptionalMarshaler(io, &pk.Fade)
	protocol.OptionalMarshaler(io, &pk.Target)
	protocol.OptionalFunc(io, &pk.RemoveTarget, io.Bool)
	protocol.OptionalMarshaler(io, &pk.FieldOfView)
	protocol.OptionalMarshaler(io, &pk.Spline)
	protocol.OptionalFunc(io, &pk.AttachToEntity, io.Int64)
	protocol.OptionalFunc(io, &pk.DetachFromEntity, io.Bool)
}

@TwistedAsylumMC
Copy link
Collaborator

Unfortunately the JSON docs still have a lot of discrepancies between what they say and what is actually required, as pointed out by Happy with a few examples. On top of this, there's still a large amount of packets not in the JSON format. Until all this issues are resolved, we will not be generating anything. If you're going to continue working on this, then it can stay open as a draft, but if you do not plan on turning this into something usable in the near future then I believe we should close this and come back to it at a better time

@HashimTheArab
Copy link
Contributor

It can be done using prismarine js minecraft-data which has reliable full json definitions for packets and protocol
https://github.com/PrismarineJS/minecraft-data

Heres an example of that
https://github.com/axolotl-stack/axolotl-stack/tree/main/crates/valentine_gen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants