This commit is contained in:
gnembon committed 2019-06-29 20:39:41 -03:00
1 parent 83a8f35094
commit 5bb813be76
7 files changed
+41 -37

No files matched your search

@@ -866,7 +866,6 @@ public class CarpetExpression
BlockSoundGroup blockSoundGroup = placementState.getSoundGroup();
cc.s.getWorld().playSound(null, where, blockSoundGroup.getPlaceSound(), SoundCategory.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
return (_c, _t) -> Value.TRUE;
}
}
}
@@ -907,13 +906,15 @@ public class CarpetExpression
public void API_InventoryManipulation()
{
this.expr.addLazyFunction("stack_limit", 1, (c, t, lv) -> {
this.expr.addLazyFunction("stack_limit", 1, (c, t, lv) ->
{
ItemStackArgument item = NBTSerializableValue.parseItem(lv.get(0).evalValue(c).getString());
Value res = new NumericValue(item.getItem().getMaxCount());
return (_c, _t) -> res;
});
this.expr.addLazyFunction("inventory_size", -1, (c, t, lv) -> {
this.expr.addLazyFunction("inventory_size", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
@@ -923,7 +924,8 @@ public class CarpetExpression
});
//inventory_get(<b, e>, <n>) -> item_triple
this.expr.addLazyFunction("inventory_get", -1, (c, t, lv) -> {
this.expr.addLazyFunction("inventory_get", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
@@ -947,7 +949,8 @@ public class CarpetExpression
});
//inventory_drop(<b, e>, <n>, <amount=1, 0-whatever's there>) -> entity_item (and sets slot) or null if cannot
this.expr.addLazyFunction("inventory_drop", -1, (c, t, lv) -> {
this.expr.addLazyFunction("inventory_drop", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
@@ -1000,7 +1003,8 @@ public class CarpetExpression
});
//inventory_find(<b, e>, <item> or null (first empty slot), <start_from=0> ) -> <N> or null
this.expr.addLazyFunction("inventory_find", -1, (c, t, lv) -> {
this.expr.addLazyFunction("inventory_find", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
@@ -1031,7 +1035,8 @@ public class CarpetExpression
});
//inventory_set(<b,e>, <n>, <count>, <item>, <nbt>)
this.expr.addLazyFunction("inventory_set", -1, (c, t, lv) -> {
this.expr.addLazyFunction("inventory_set", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null)
+10 -11
View File
@@ -1840,11 +1840,10 @@ public class Expression implements Cloneable
return LazyListValue.range(from, to, step);
});
addBinaryFunction("get", (v1, v2) -> {
addBinaryFunction("get", (v1, v2) ->
{
if (v1 instanceof LazyListValue || !(v1 instanceof ListValue))
{
throw new InternalExpressionException("First argument of element should be a list");
}
List<Value> items = ((ListValue)v1).getItems();
long index = NumericValue.asNumber(v2).getLong();
int numitems = items.size();
@@ -1854,12 +1853,11 @@ public class Expression implements Cloneable
return items.get((int)index);
});
//Deprecated
addBinaryFunction("element", (v1, v2) -> {
//Deprecated, use "get" instead
addBinaryFunction("element", (v1, v2) ->
{
if (v1 instanceof LazyListValue || !(v1 instanceof ListValue))
{
throw new InternalExpressionException("First argument of element should be a list");
}
List<Value> items = ((ListValue)v1).getItems();
long index = NumericValue.asNumber(v2).getLong();
int numitems = items.size();
@@ -1868,6 +1866,7 @@ public class Expression implements Cloneable
index = index % numitems;
return items.get((int)index);
});
addFunction("put", (lv) ->
{
if(lv.size()<3)
@@ -2777,10 +2776,10 @@ public class Expression implements Cloneable
{
return exit.retval;
}
//catch (StackOverflowError ignored)
//{
// throw new ExpressionException("Your thoughts are too deep");
//}
catch (StackOverflowError ignored)
{
throw new ExpressionException("Your thoughts are too deep");
}
catch (InternalExpressionException exc)
{
throw new ExpressionException("Your expression result is incorrect:"+exc.getMessage());
@@ -34,7 +34,7 @@ public class ExpressionInspector
APIFunctions = new TreeSet<>(allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toSet()));
}
public static List<String> suggestFunctions(String previous, String prefix)
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
{
previous = previous.replace("\\'", "");
int quoteCount = StringUtils.countMatches(previous,'\'');
@@ -45,7 +45,12 @@ public class ExpressionInspector
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList());
scarpetMatches.addAll(APIFunctions.stream().
filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(CarpetServer.scriptServer.globalHost.globalVariables.keySet().stream().
// not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globalFunctions.keySet().stream().
filter(s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globalVariables.keySet().stream().
filter(s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches;
}
@@ -163,13 +163,10 @@ public class NBTSerializableValue extends Value
public boolean equals(final Value o)
{
if (o instanceof NBTSerializableValue)
{
return getTag().equals(((NBTSerializableValue) o).getTag());
}
return super.equals(o);
}
@Override
public String getString()
{