inv size
This commit is contained in:
1 parent
e6158c1aab
commit
b79b942819
3 files changed
+20
-6
No files matched your search
@@ -873,6 +873,15 @@ public class CarpetExpression
|
||||
|
||||
public void API_InventoryManipulation()
|
||||
{
|
||||
this.expr.addLazyFunction("inventory_size", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
|
||||
if (inventoryLocator == null)
|
||||
return (_c, _t) -> Value.NULL;
|
||||
Value res = new NumericValue(inventoryLocator.inventory.getInvSize());
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
|
||||
//inventory_get(<b, e>, <n>) -> item_triple
|
||||
this.expr.addLazyFunction("inventory_get", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
@@ -890,8 +899,9 @@ public class CarpetExpression
|
||||
return (_c, _t) -> res;
|
||||
}
|
||||
int slot = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset).evalValue(c)).getLong();
|
||||
if (slot < 0 || slot > inventoryLocator.inventory.getInvSize())
|
||||
throw new InternalExpressionException("Inventory has "+inventoryLocator.inventory.getInvSize()+" slots available");
|
||||
slot = NBTSerializableValue.validateSlot(slot, inventoryLocator.inventory);
|
||||
if (slot == inventoryLocator.inventory.getInvSize())
|
||||
return (_c, _t) -> Value.NULL;
|
||||
Value res = ListValue.fromItemStack(inventoryLocator.inventory.getInvStack(slot));
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
@@ -905,8 +915,9 @@ public class CarpetExpression
|
||||
if (lv.size() == inventoryLocator.offset)
|
||||
throw new InternalExpressionException("slot number is required for inventory_drop");
|
||||
int slot = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset).evalValue(c)).getLong();
|
||||
if (slot < 0 || slot > inventoryLocator.inventory.getInvSize())
|
||||
throw new InternalExpressionException("Inventory has "+inventoryLocator.inventory.getInvSize()+" slots available");
|
||||
slot = NBTSerializableValue.validateSlot(slot, inventoryLocator.inventory);
|
||||
if (slot == inventoryLocator.inventory.getInvSize())
|
||||
return (_c, _t) -> Value.NULL;
|
||||
int amount = 0;
|
||||
if (lv.size() > inventoryLocator.offset+1)
|
||||
amount = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset+1).evalValue(c)).getLong();
|
||||
@@ -989,6 +1000,8 @@ public class CarpetExpression
|
||||
throw new InternalExpressionException("inventory_set requires at least slot number and new stack size, and optional new item");
|
||||
int slot = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset+0).evalValue(c)).getLong();
|
||||
slot = NBTSerializableValue.validateSlot(slot, inventoryLocator.inventory);
|
||||
if (slot == inventoryLocator.inventory.getInvSize())
|
||||
return (_c, _t) -> Value.NULL;
|
||||
int count = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset+1).evalValue(c)).getLong();
|
||||
if (count == 0)
|
||||
{
|
||||
|
||||
@@ -2242,7 +2242,7 @@ public class Expression implements Cloneable
|
||||
* number('2')+number('2') => 4
|
||||
* </pre>
|
||||
*
|
||||
* <h3><code>str(expr, params? ... )</code></h3>
|
||||
* <h3><code>str(expr, params? ... ), str(expr, param_list)</code></h3>
|
||||
*
|
||||
* <p>Returns a formatted string representing expression.
|
||||
* Accepts formatting style accepted by <code>String.format</code>.
|
||||
@@ -2265,6 +2265,7 @@ public class Expression implements Cloneable
|
||||
* str('3bar') => null
|
||||
* str(2)+str(2) => 22
|
||||
* str('pi: %.2f',pi) => 'pi: 3.14'
|
||||
* str('player at: %d %d %d',pos(player())) => 'player at: 567, -2423, 124'
|
||||
* </pre>
|
||||
*
|
||||
* <hr>
|
||||
|
||||
@@ -119,7 +119,7 @@ public class NBTSerializableValue extends Value
|
||||
if (slot < 0)
|
||||
slot = invSize + slot;
|
||||
if (slot < 0 || slot >= invSize)
|
||||
throw new InternalExpressionException("Slot for inventory should be between 0 and "+(invSize-1));
|
||||
return inv.getInvSize(); // outside of inventory
|
||||
return slot;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user