From c665401fd800b38ce4b85f46d8991c3298367fb8 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Fri, 23 May 2025 15:39:44 +0200 Subject: [PATCH] use .call instead of native in Inventory peripheral --- src/kernel/peripherals/Inventory.hx | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/kernel/peripherals/Inventory.hx b/src/kernel/peripherals/Inventory.hx index d2391f5..0280887 100644 --- a/src/kernel/peripherals/Inventory.hx +++ b/src/kernel/peripherals/Inventory.hx @@ -1,5 +1,9 @@ package kernel.peripherals; +import kernel.log.Log; +import lib.Debug; +import cc.Peripheral; +import lib.Tags; import lib.Item; import cc.periphs.ItemStorage.ReducedItemInfo; import lua.Table; @@ -22,7 +26,7 @@ class ItemInfo { class DetailedItemInfo extends ItemInfo { public final displayName:String; public final maxCount:Int; - public final tags:Array; + public final tags:Tags; public final durability:Null; public final damage:Null; public final maxDamage:Null; @@ -32,10 +36,7 @@ class DetailedItemInfo extends ItemInfo { private function new(from:cc.periphs.ItemStorage.DetailedItemInfo) { super(from); - this.tags = []; - for (k => _ in Table.toMap(from.tags)) { - this.tags.push(k); - } + this.tags = Tags.fromBoolTable(from.tags); this.displayName = from.displayName; this.maxCount = from.maxCount; @@ -55,11 +56,9 @@ class Inventory implements IPeripheral { public static inline final TYPE_NAME:String = "inventory"; private final addr:String; - private final native:cc.periphs.ItemStorage; public function new(addr:String) { this.addr = addr; - this.native = cc.Peripheral.wrap(addr); } public function getAddr():String { @@ -74,18 +73,18 @@ class Inventory implements IPeripheral { Get the size of this inventory. **/ public function size():Int { - return this.native.size(); + return Peripheral.call(this.addr, "size"); } /** List all items in this inventory. **/ public function list():Map { - var list = Table.toArray(this.native.list()); + var list:Map = Table.toMap(Peripheral.call(this.addr, "list")); var rtn:Map = new Map(); for (k => v in list) { - rtn.set(k, new ItemInfo(v)); + rtn.set(k - 1, new ItemInfo(v)); } return rtn; @@ -95,7 +94,7 @@ class Inventory implements IPeripheral { Get detailed information about an item. **/ public function getItemDetail(slot:Int):DetailedItemInfo { - return new DetailedItemInfo(this.native.getItemDetail(slot)); + return new DetailedItemInfo(Peripheral.call(this.addr, "getItemDetail", slot + 1)); } /** @@ -105,20 +104,20 @@ class Inventory implements IPeripheral { Keep in mind that this does not depend on that item stored in this slot. **/ public function getItemLimit(slot:Int):Int { - return this.native.getItemLimit(slot); + return Peripheral.call(this.addr, "getItemLimit", slot + 1); } /** - Push items from one inventory to another connected one. + Push items from one inventory to another connected one. Needs to be on the same wired network. **/ - public function pushItems(toSlot:Int, to:String, ?limit:Int, ?toSlot:Int):Int { - return this.native.pushItems(to, toSlot, limit, toSlot); + public function pushItems(to:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int { + return Peripheral.call(this.addr, "pushItems", to, fromSlot + 1, limit, toSlot); } /** - Pull items from a connected inventory into this one. + Pull items from a connected inventory into this one. Needs to be on the same wired network. **/ public function pullItems(from:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int { - return this.native.pullItems(from, fromSlot, limit, toSlot); + return Peripheral.call(this.addr, "pullItems", from, fromSlot + 1, limit, toSlot); } }