gophertunnel icon indicating copy to clipboard operation
gophertunnel copied to clipboard

Auto-Generate Protocol Types

Open smell-of-curry opened this issue 1 week ago • 1 comments

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)

smell-of-curry avatar Dec 13 '25 00:12 smell-of-curry

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)
}

Happy2018new avatar Dec 13 '25 05:12 Happy2018new

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

TwistedAsylumMC avatar Dec 16 '25 12:12 TwistedAsylumMC

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

HashimTheArab avatar Dec 17 '25 15:12 HashimTheArab