1
0
forked from MTSR/mapserver

proper inventory counting and smartshop creative flag

fixes #48
This commit is contained in:
Thomas Rudin 2019-12-01 11:25:37 +01:00
parent 752e25730a
commit 4a7722c8bc
3 changed files with 13 additions and 5 deletions

View File

@ -66,7 +66,7 @@ func getNodePos(x, y, z int) int {
}
func (inv *Inventory) IsEmpty() bool {
if inv.Size == 0 || len(inv.Items) == 0 {
if len(inv.Items) == 0 {
return true
}

View File

@ -155,6 +155,7 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
}
currentInventory.Items = append(currentInventory.Items, &item)
currentInventory.Size += 1
}

View File

@ -15,6 +15,7 @@ func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBl
md := block.Metadata.GetMetadata(x, y, z)
invMap := block.Metadata.GetInventoryMapAtPos(x, y, z)
mainInv := invMap["main"]
isCreative := md["type"] == "0"
if mainInv.IsEmpty() {
return list
@ -27,7 +28,7 @@ func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBl
pay := invMap[payInvName]
give := invMap[giveInvName]
if pay.IsEmpty() || give.IsEmpty() {
if len(pay.Items) == 0 || len(give.Items) == 0 {
continue
}
@ -43,10 +44,16 @@ func (this *SmartShopBlock) onMapObject(x, y, z int, block *mapblockparser.MapBl
stock := 0
for _, item := range mainInv.Items {
if item.Name == out_item {
stock += item.Count
if isCreative {
stock = 999
} else {
for _, item := range mainInv.Items {
if item.Name == out_item {
stock += item.Count
}
}
}
//multiples of out_count