Add support for protocol version 1.21.100 (#12)

This commit is contained in:
Akmal Fairuz
2025-08-13 21:37:46 +07:00
committed by GitHub
parent d3fae5d3be
commit d9d8b0bc75
50 changed files with 9667 additions and 135 deletions

View File

@@ -2,9 +2,10 @@ package mapping
import (
"bytes"
"github.com/akmalfairuz/legacy-version/internal"
"sort"
"github.com/akmalfairuz/legacy-version/internal"
"github.com/df-mc/worldupgrader/blockupgrader"
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/sandertv/gophertunnel/minecraft/protocol"
@@ -23,6 +24,7 @@ type Block interface {
// Adjust adjusts the latest mappings to account for custom states.
Adjust([]protocol.BlockEntry)
Air() uint32
InfoUpdate() uint32
}
type DefaultBlockMapping struct {
@@ -36,6 +38,9 @@ type DefaultBlockMapping struct {
// airRID is the runtime ID of the air block in the latest version of the game.
airRID uint32
// infoUpdateRID is the runtime ID of the info_update block in the latest version of the game.
infoUpdateBlockRID uint32
}
func NewBlockMapping(raw []byte) *DefaultBlockMapping {
@@ -45,6 +50,7 @@ func NewBlockMapping(raw []byte) *DefaultBlockMapping {
stateRuntimeIDs := make(map[internal.StateHash]uint32)
runtimeIDToState := make(map[uint32]blockupgrader.BlockState)
var airRID *uint32
var infoUpdateBlockRID *uint32
var s blockupgrader.BlockState
for {
@@ -54,8 +60,11 @@ func NewBlockMapping(raw []byte) *DefaultBlockMapping {
rid := uint32(len(states))
states = append(states, s)
if s.Name == "minecraft:air" {
switch s.Name {
case "minecraft:air":
airRID = &rid
case "minecraft:info_update":
infoUpdateBlockRID = &rid
}
stateRuntimeIDs[internal.HashState(blockupgrader.Upgrade(s))] = rid
@@ -64,12 +73,16 @@ func NewBlockMapping(raw []byte) *DefaultBlockMapping {
if airRID == nil {
panic("couldn't find air")
}
if infoUpdateBlockRID == nil {
panic("couldn't find info_update block")
}
return &DefaultBlockMapping{
states: states,
stateRuntimeIDs: stateRuntimeIDs,
runtimeIDToState: runtimeIDToState,
airRID: *airRID,
states: states,
stateRuntimeIDs: stateRuntimeIDs,
runtimeIDToState: runtimeIDToState,
airRID: *airRID,
infoUpdateBlockRID: *infoUpdateBlockRID,
}
}
@@ -134,3 +147,7 @@ func (m *DefaultBlockMapping) Adjust(entries []protocol.BlockEntry) {
func (m *DefaultBlockMapping) Air() uint32 {
return m.airRID
}
func (m *DefaultBlockMapping) InfoUpdate() uint32 {
return m.infoUpdateBlockRID
}