bot can receive chunks now

This commit is contained in:
Tnze
2022-03-13 11:57:02 +08:00
parent d8695636b6
commit 2aace6b51a
17 changed files with 452 additions and 78 deletions

View File

@ -18,8 +18,8 @@ type Block interface {
//go:embed block_states.nbt
var blockStates []byte
var toStateID map[Block]int
var fromStateID []Block
var ToStateID map[Block]int
var StateList []Block
// BitsPerBlock indicates how many bits are needed to represent all possible
// block states. This value is used to determine the size of the global palette.
@ -41,8 +41,8 @@ func init() {
if _, err = nbt.NewDecoder(z).Decode(&states); err != nil {
panic(err)
}
toStateID = make(map[Block]int, len(states))
fromStateID = make([]Block, 0, len(states))
ToStateID = make(map[Block]int, len(states))
StateList = make([]Block, 0, len(states))
for _, state := range states {
block := fromID[state.Name]
if state.Properties.Type != nbt.TagEnd {
@ -51,29 +51,16 @@ func init() {
panic(err)
}
}
if _, ok := toStateID[block]; ok {
if _, ok := ToStateID[block]; ok {
panic(fmt.Errorf("state %#v already exist", block))
}
toStateID[block] = len(fromStateID)
fromStateID = append(fromStateID, block)
ToStateID[block] = len(StateList)
StateList = append(StateList, block)
}
BitsPerBlock = bits.Len(uint(len(fromStateID)))
}
func FromStateID(stateID int) (b Block, ok bool) {
if stateID >= 0 && stateID < len(fromStateID) {
b = fromStateID[stateID]
ok = true
}
return
BitsPerBlock = bits.Len(uint(len(StateList)))
}
func DefaultBlock(id string) (b Block, ok bool) {
b, ok = fromID[id]
return
}
func ToStateID(b Block) (i int, ok bool) {
i, ok = toStateID[b]
return
}

View File

@ -12,6 +12,6 @@ type (
{{- range .}}
func ({{.Name | ToGoTypeName}}) ID() string { return {{.Name | printf "%q"}} }
{{- end}}
var fromID = map[string]Block { {{- range .}}
var FromID = map[string]Block { {{- range .}}
{{.Name | printf "%#v"}}: {{.Name | ToGoTypeName}}{},{{end}}
}