Implement multiplayer persistence and vanilla lighting
This commit is contained in:
parent
8f7cacf9d9
commit
cae06eb97e
47 changed files with 3784 additions and 465 deletions
25
internal/registry/entity_test.go
Normal file
25
internal/registry/entity_test.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package registry
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestEntityTypeIndex(t *testing.T) {
|
||||
tests := map[string]int{
|
||||
"minecraft:pig": 100,
|
||||
"minecraft:player": 155,
|
||||
"minecraft:zombie": 150,
|
||||
}
|
||||
for name, want := range tests {
|
||||
if got := EntityTypeIndex(name); got != want {
|
||||
t.Fatalf("EntityTypeIndex(%q) = %d, want %d", name, got, want)
|
||||
}
|
||||
}
|
||||
if got := EntityTypeIndex("minecraft:not_a_real_entity"); got != -1 {
|
||||
t.Fatalf("unknown entity type = %d, want -1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEntityTypeIsNotSyncedRegistry(t *testing.T) {
|
||||
if got := Index("minecraft:entity_type", "minecraft:pig"); got != -1 {
|
||||
t.Fatalf("synced registry unexpectedly has entity_type pig = %d", got)
|
||||
}
|
||||
}
|
||||
|
|
@ -39,11 +39,19 @@ type Registry struct {
|
|||
|
||||
// synced is the parsed, ordered list loaded once at init.
|
||||
var synced []Registry
|
||||
var syncedLookup map[string]map[string]int
|
||||
|
||||
func init() {
|
||||
if err := json.Unmarshal(syncedJSON, &synced); err != nil {
|
||||
panic(fmt.Sprintf("registry: parsing embedded synced_registries.json: %v", err))
|
||||
}
|
||||
syncedLookup = make(map[string]map[string]int)
|
||||
for _, reg := range synced {
|
||||
syncedLookup[reg.Name] = make(map[string]int)
|
||||
for i, e := range reg.Entries {
|
||||
syncedLookup[reg.Name][e] = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Synced returns the ordered synchronized registries. The slice is shared and
|
||||
|
|
@ -54,14 +62,9 @@ func Synced() []Registry { return synced }
|
|||
// which is the numeric (network) ID the client assigns it. It returns -1 if
|
||||
// the registry or entry is unknown.
|
||||
func Index(registryName, entry string) int {
|
||||
for _, reg := range synced {
|
||||
if reg.Name != registryName {
|
||||
continue
|
||||
}
|
||||
for i, e := range reg.Entries {
|
||||
if e == entry {
|
||||
return i
|
||||
}
|
||||
if regMap, ok := syncedLookup[registryName]; ok {
|
||||
if idx, ok := regMap[entry]; ok {
|
||||
return idx
|
||||
}
|
||||
}
|
||||
return -1
|
||||
|
|
@ -77,3 +80,23 @@ type KnownPack struct {
|
|||
// CorePack is the vanilla built-in pack. Advertising it lets a matching client
|
||||
// supply registry contents from its own copy.
|
||||
var CorePack = KnownPack{Namespace: "minecraft", ID: "core", Version: "26.1.2"}
|
||||
|
||||
// builtinEntityTypes contains the vanilla 26.1.2 BuiltInRegistries.ENTITY_TYPE
|
||||
// network IDs needed by gameplay packets. This is intentionally separate from
|
||||
// the synchronized registries above: minecraft:entity_type is a built-in
|
||||
// registry in this protocol data set and is not sent in registry_data during
|
||||
// configuration.
|
||||
var builtinEntityTypes = map[string]int{
|
||||
"minecraft:pig": 100,
|
||||
"minecraft:player": 155,
|
||||
"minecraft:zombie": 150,
|
||||
}
|
||||
|
||||
// EntityTypeIndex returns the vanilla numeric ID for a built-in entity type, or
|
||||
// -1 if it is not in the embedded table.
|
||||
func EntityTypeIndex(name string) int {
|
||||
if idx, ok := builtinEntityTypes[name]; ok {
|
||||
return idx
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue