Remove SetItemRuntimeID method and update item mapping initialization
This commit is contained in:
74
cmd/dfmapping/main.go
Normal file
74
cmd/dfmapping/main.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/samber/lo"
|
||||||
|
"github.com/sandertv/gophertunnel/minecraft/nbt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Downloading vanilla items NBT file...")
|
||||||
|
resp, err := http.Get("https://github.com/df-mc/dragonfly/raw/refs/heads/master/server/world/vanilla_items.nbt")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
panic(fmt.Errorf("failed to download vanilla items NBT file: %s", resp.Status))
|
||||||
|
}
|
||||||
|
bytes, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to read vanilla items NBT file: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
var m map[string]struct {
|
||||||
|
RuntimeID int32 `nbt:"runtime_id"`
|
||||||
|
ComponentBased bool `nbt:"component_based"`
|
||||||
|
Version int32 `nbt:"version"`
|
||||||
|
Data map[string]any `nbt:"data,omitempty"`
|
||||||
|
}
|
||||||
|
if err := nbt.Unmarshal(bytes, &m); err != nil {
|
||||||
|
panic(fmt.Errorf("failed to unmarshal vanilla items NBT file: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
type itemEntry struct {
|
||||||
|
RuntimeID int16 `json:"runtime_id"`
|
||||||
|
ComponentBased bool `json:"component_based"`
|
||||||
|
Version *uint8 `json:"version"`
|
||||||
|
Data string `json:"component_nbt,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
m2 := make(map[string]itemEntry)
|
||||||
|
defData := make(map[string]any)
|
||||||
|
for k, v := range m {
|
||||||
|
var data string
|
||||||
|
if v.Data == nil {
|
||||||
|
v.Data = defData
|
||||||
|
}
|
||||||
|
dataBytes, err := nbt.Marshal(v.Data)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to marshal component NBT for item %s: %w", k, err))
|
||||||
|
}
|
||||||
|
data = base64.StdEncoding.EncodeToString(dataBytes)
|
||||||
|
m2[k] = itemEntry{
|
||||||
|
RuntimeID: int16(v.RuntimeID),
|
||||||
|
ComponentBased: v.ComponentBased,
|
||||||
|
Version: lo.ToPtr(uint8(v.Version)),
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonData, err := json.MarshalIndent(m2, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to marshal item data to JSON: %w", err))
|
||||||
|
}
|
||||||
|
fmt.Println("Writing item data to dragonfly_items.json...")
|
||||||
|
if err := os.WriteFile("dragonfly_items.json", jsonData, 0644); err != nil {
|
||||||
|
panic(fmt.Errorf("failed to write item data to dragonfly_items.json: %w", err))
|
||||||
|
}
|
||||||
|
fmt.Println("Item data written to dragonfly_items.json successfully.")
|
||||||
|
}
|
||||||
10898
legacyver/data/dragonfly_items.json
Normal file
10898
legacyver/data/dragonfly_items.json
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -3,7 +3,6 @@ package legacyver
|
|||||||
import (
|
import (
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"github.com/akmalfairuz/legacy-version/mapping"
|
"github.com/akmalfairuz/legacy-version/mapping"
|
||||||
"github.com/sandertv/gophertunnel/minecraft/nbt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -18,30 +17,14 @@ var (
|
|||||||
requiredItemList818 []byte
|
requiredItemList818 []byte
|
||||||
//go:embed data/block_states_818.nbt
|
//go:embed data/block_states_818.nbt
|
||||||
blockStateData818 []byte
|
blockStateData818 []byte
|
||||||
//go:embed data/dragonfly_latest_vanilla_items.nbt
|
|
||||||
dragonflyLatestVanillaItemsRaw []byte
|
dragonflyLatestItemList []byte = requiredItemList818
|
||||||
|
|
||||||
itemMappingLatestPocketMine = mapping.NewItemMapping(requiredItemList818, ItemVersion818)
|
itemMappingLatestPocketMine = mapping.NewItemMapping(requiredItemList818, ItemVersion818)
|
||||||
itemMappingLatestDragonfly = mapping.NewItemMapping(requiredItemList818, ItemVersion818)
|
itemMappingLatestDragonfly = mapping.NewItemMapping(dragonflyLatestItemList, ItemVersion818)
|
||||||
blockMappingLatest = mapping.NewBlockMapping(blockStateData818)
|
blockMappingLatest = mapping.NewBlockMapping(blockStateData818)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
var m map[string]struct {
|
|
||||||
RuntimeID int32 `nbt:"runtime_id"`
|
|
||||||
ComponentBased bool `nbt:"component_based"`
|
|
||||||
Version int32 `nbt:"version"`
|
|
||||||
Data map[string]any `nbt:"data,omitempty"`
|
|
||||||
}
|
|
||||||
if err := nbt.Unmarshal(dragonflyLatestVanillaItemsRaw, &m); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for identifier, v := range m {
|
|
||||||
itemMappingLatestDragonfly.SetItemRuntimeID(identifier, v.RuntimeID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func itemMappingLatest(dragonflyMapping bool) mapping.Item {
|
func itemMappingLatest(dragonflyMapping bool) mapping.Item {
|
||||||
if dragonflyMapping {
|
if dragonflyMapping {
|
||||||
return itemMappingLatestDragonfly
|
return itemMappingLatestDragonfly
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type Item interface {
|
|||||||
Air() int32
|
Air() int32
|
||||||
ItemVersion() uint16
|
ItemVersion() uint16
|
||||||
ItemEntries() []ItemEntry
|
ItemEntries() []ItemEntry
|
||||||
SetItemRuntimeID(string, int32)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemEntry struct {
|
type ItemEntry struct {
|
||||||
@@ -106,13 +105,6 @@ func NewItemMapping(requiredItemList []byte, itemVersion uint16) *DefaultItemMap
|
|||||||
return &DefaultItemMapping{itemRuntimeIDsToNames: itemRuntimeIDsToNames, itemNamesToRuntimeIDs: itemNamesToRuntimeIDs, itemRuntimeIDToVersion: itemRuntimeIDToVersion, airRID: *airRID, itemVersion: itemVersion, itemRuntimeIDToData: itemRuntimeIDToData, itemEntries: itemEntries}
|
return &DefaultItemMapping{itemRuntimeIDsToNames: itemRuntimeIDsToNames, itemNamesToRuntimeIDs: itemNamesToRuntimeIDs, itemRuntimeIDToVersion: itemRuntimeIDToVersion, airRID: *airRID, itemVersion: itemVersion, itemRuntimeIDToData: itemRuntimeIDToData, itemEntries: itemEntries}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DefaultItemMapping) SetItemRuntimeID(name string, runtimeID int32) {
|
|
||||||
m.mu.Lock()
|
|
||||||
defer m.mu.Unlock()
|
|
||||||
m.itemNamesToRuntimeIDs[name] = runtimeID
|
|
||||||
m.itemRuntimeIDsToNames[runtimeID] = name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *DefaultItemMapping) ItemRuntimeIDToName(runtimeID int32) (name string, found bool) {
|
func (m *DefaultItemMapping) ItemRuntimeIDToName(runtimeID int32) (name string, found bool) {
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user