diff --git a/inventory.go b/inventory.go deleted file mode 100644 index c0a6258..0000000 --- a/inventory.go +++ /dev/null @@ -1,20 +0,0 @@ -package types - -type Inventory struct { - Size int `json:"size"` - Items []*Item `json:"items"` -} - -func (inv *Inventory) IsEmpty() bool { - if len(inv.Items) == 0 { - return true - } - - for _, item := range inv.Items { - if item.Name != "" && item.Count > 0 { - return false - } - } - - return true -} diff --git a/item.go b/item.go deleted file mode 100644 index 2c92f59..0000000 --- a/item.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -type Item struct { - Name string `json:"name"` - Count int `json:"count"` - Wear int `json:"wear"` - //TODO: metadata -} - -func (i *Item) IsEmpty() bool { - return i.Name == "" && i.Count == 0 -} diff --git a/mapblock.go b/mapblock.go index 18424f0..7444b68 100644 --- a/mapblock.go +++ b/mapblock.go @@ -3,19 +3,26 @@ package types import "fmt" type MapBlock struct { - Size int `json:"size"` - Version byte `json:"version"` - Underground bool `json:"underground"` - AirOnly bool `json:"air_only"` - Timestamp uint32 `json:"timestamp"` - Mapdata *MapData `json:"mapdata"` - Metadata *Metadata `json:"metadata"` + Size int `json:"size"` + Version byte `json:"version"` + Underground bool `json:"underground"` + AirOnly bool `json:"air_only"` + Timestamp uint32 `json:"timestamp"` + ContentId []int `json:"contentid"` + Param1 []int `json:"param1"` + Param2 []int `json:"param2"` + // index -> inventory-map + Inventory map[int]map[string][]string `json:"inventory"` + // index -> fields + Fields map[int]map[string]string `json:"fields"` + // nodeid -> nodename BlockMapping map[int]string `json:"blockmapping"` } func NewMapblock() *MapBlock { mb := MapBlock{} - mb.Metadata = NewMetadata() + mb.Inventory = make(map[int]map[string][]string) + mb.Fields = make(map[int]map[string]string) mb.BlockMapping = make(map[int]string) return &mb } @@ -26,11 +33,11 @@ func (mb *MapBlock) IsEmpty() bool { } func (mb *MapBlock) GetNodeId(p *Pos) int { - return mb.Mapdata.ContentId[p.Index()] + return mb.ContentId[p.Index()] } func (mb *MapBlock) GetParam2(p *Pos) int { - return mb.Mapdata.Param2[p.Index()] + return mb.Param2[p.Index()] } func (mb *MapBlock) GetNodeName(p *Pos) string { @@ -41,14 +48,14 @@ func (mb *MapBlock) GetNodeName(p *Pos) string { func (mb *MapBlock) GetNode(p *Pos) (*Node, error) { i := p.Index() - if i > len(mb.Mapdata.ContentId) { - return nil, fmt.Errorf("unexpected index, got %d, len: %d, pos: %s", i, len(mb.Mapdata.ContentId), p) + if i > len(mb.ContentId) { + return nil, fmt.Errorf("unexpected index, got %d, len: %d, pos: %s", i, len(mb.ContentId), p) } return &Node{ Pos: p, - Name: mb.BlockMapping[mb.Mapdata.ContentId[i]], - Param1: mb.Mapdata.Param1[i], - Param2: mb.Mapdata.Param2[i], + Name: mb.BlockMapping[mb.ContentId[i]], + Param1: mb.Param1[i], + Param2: mb.Param2[i], }, nil } diff --git a/mapdata.go b/mapdata.go deleted file mode 100644 index c0e902a..0000000 --- a/mapdata.go +++ /dev/null @@ -1,7 +0,0 @@ -package types - -type MapData struct { - ContentId []int `json:"contentid"` - Param1 []int `json:"param1"` - Param2 []int `json:"param2"` -} diff --git a/metadata.go b/metadata.go deleted file mode 100644 index cc88120..0000000 --- a/metadata.go +++ /dev/null @@ -1,52 +0,0 @@ -package types - -type Metadata struct { - Inventories map[int]map[string]*Inventory `json:"inventories"` - Pairs map[int]map[string]string `json:"pairs"` -} - -func NewMetadata() *Metadata { - md := Metadata{} - md.Inventories = make(map[int]map[string]*Inventory) - md.Pairs = make(map[int]map[string]string) - return &md -} - -func (md *Metadata) GetMetadata(p *Pos) map[string]string { - return md.GetPairsMap(p.Index()) -} - -func (md *Metadata) GetPairsMap(pos int) map[string]string { - pairsMap := md.Pairs[pos] - if pairsMap == nil { - pairsMap = make(map[string]string) - md.Pairs[pos] = pairsMap - } - - return pairsMap -} - -func (md *Metadata) GetInventoryMap(index int) map[string]*Inventory { - invMap := md.Inventories[index] - if invMap == nil { - invMap = make(map[string]*Inventory) - md.Inventories[index] = invMap - } - - return invMap -} - -func (md *Metadata) GetInventoryMapAtPos(p *Pos) map[string]*Inventory { - return md.GetInventoryMap(p.Index()) -} - -func (md *Metadata) GetInventory(index int, name string) *Inventory { - m := md.GetInventoryMap(index) - inv := m[name] - if inv == nil { - inv = &Inventory{} - m[name] = inv - } - - return inv -}