-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f7858b
commit 9a0245a
Showing
7 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package types | ||
|
||
type MapBlock struct { | ||
Size int `json:"size"` | ||
Version byte `json:"version"` | ||
Underground bool `json:"underground"` | ||
Timestamp uint32 `json:"timestamp"` | ||
Mapdata *MapData `json:"mapdata"` | ||
Metadata *Metadata `json:"metadata"` | ||
BlockMapping map[int]string `json:"blockmapping"` | ||
} | ||
|
||
func NewMapblock() *MapBlock { | ||
mb := MapBlock{} | ||
mb.Metadata = NewMetadata() | ||
mb.BlockMapping = make(map[int]string) | ||
return &mb | ||
} | ||
|
||
// returns true if the mapblock is empty (air-only) | ||
func (mb *MapBlock) IsEmpty() bool { | ||
return len(mb.BlockMapping) == 0 | ||
} | ||
|
||
func (mb *MapBlock) GetNodeId(p *Pos) int { | ||
return mb.Mapdata.ContentId[p.Index()] | ||
} | ||
|
||
func (mb *MapBlock) GetParam2(p *Pos) int { | ||
return mb.Mapdata.Param2[p.Index()] | ||
} | ||
|
||
func (mb *MapBlock) GetNodeName(p *Pos) string { | ||
id := mb.GetNodeId(p) | ||
return mb.BlockMapping[id] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package types | ||
|
||
type MapData struct { | ||
ContentId []int `json:"contentid"` | ||
Param1 []int `json:"param1"` | ||
Param2 []int `json:"param2"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters