Palette data structures now use generics for type checking
This commit is contained in:
@ -18,13 +18,14 @@ type Block interface {
|
||||
//go:embed block_states.nbt
|
||||
var blockStates []byte
|
||||
|
||||
var ToStateID map[Block]int
|
||||
var ToStateID map[Block]StateID
|
||||
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.
|
||||
var BitsPerBlock int
|
||||
|
||||
type StateID int
|
||||
type State struct {
|
||||
Name string
|
||||
Properties nbt.RawMessage
|
||||
@ -41,7 +42,7 @@ func init() {
|
||||
if _, err = nbt.NewDecoder(z).Decode(&states); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ToStateID = make(map[Block]int, len(states))
|
||||
ToStateID = make(map[Block]StateID, len(states))
|
||||
StateList = make([]Block, 0, len(states))
|
||||
for _, state := range states {
|
||||
block := FromID[state.Name]
|
||||
@ -54,7 +55,7 @@ func init() {
|
||||
if _, ok := ToStateID[block]; ok {
|
||||
panic(fmt.Errorf("state %#v already exist", block))
|
||||
}
|
||||
ToStateID[block] = len(StateList)
|
||||
ToStateID[block] = StateID(len(StateList))
|
||||
StateList = append(StateList, block)
|
||||
}
|
||||
BitsPerBlock = bits.Len(uint(len(StateList)))
|
||||
|
Reference in New Issue
Block a user