Initial commit: RegionIO Minecraft server core (26.1.2/protocol 775)
Vanilla-faithful overworld generator (final_density + multi-noise biomes), full connection lifecycle (status/login/configuration/play), chunk streaming, creative block editing, and the protocol/nbt/registry infrastructure.
This commit is contained in:
commit
a7bb9496ae
146 changed files with 217621 additions and 0 deletions
38
internal/world/items.go
Normal file
38
internal/world/items.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package world
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//go:embed item_blocks.json
|
||||
var itemBlocksJSON []byte
|
||||
|
||||
// itemToBlock maps an item's network ID to the default block state placed when
|
||||
// that item is used. Built from the item registry crossed with block defaults
|
||||
// (items whose name is a block). Items with no block (tools, food) are absent.
|
||||
var itemToBlock map[int32]uint16
|
||||
|
||||
func init() {
|
||||
raw := make(map[string]int)
|
||||
if err := json.Unmarshal(itemBlocksJSON, &raw); err != nil {
|
||||
panic(fmt.Sprintf("world: parsing item_blocks.json: %v", err))
|
||||
}
|
||||
itemToBlock = make(map[int32]uint16, len(raw))
|
||||
for k, v := range raw {
|
||||
id, err := strconv.Atoi(k)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("world: bad item id %q: %v", k, err))
|
||||
}
|
||||
itemToBlock[int32(id)] = uint16(v)
|
||||
}
|
||||
}
|
||||
|
||||
// ItemToBlock returns the block state placed by an item, and whether the item
|
||||
// is a placeable block.
|
||||
func ItemToBlock(itemID int32) (uint16, bool) {
|
||||
s, ok := itemToBlock[itemID]
|
||||
return s, ok
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue