use .call instead of native in Inventory peripheral
This commit is contained in:
parent
2799a0be3d
commit
c665401fd8
@ -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<String>;
|
||||
public final tags:Tags;
|
||||
public final durability:Null<Float>;
|
||||
public final damage:Null<Int>;
|
||||
public final maxDamage:Null<Int>;
|
||||
@ -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<Int, ItemInfo> {
|
||||
var list = Table.toArray(this.native.list());
|
||||
var list:Map<Int, ReducedItemInfo> = Table.toMap(Peripheral.call(this.addr, "list"));
|
||||
var rtn:Map<Int, ItemInfo> = 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user