Merge branch 'master' into 1.16
This commit is contained in:
commit
583e023eb1
25 files changed
+3886
-99
No files matched your search
@@ -139,10 +139,11 @@ public class CarpetExpression
|
||||
private final ServerCommandSource source;
|
||||
private final BlockPos origin;
|
||||
private final Expression expr;
|
||||
Expression getExpr() {return expr;}
|
||||
public Expression getExpr() {return expr;}
|
||||
private static long tickStart = 0L;
|
||||
// dummy entity for dummy requirements in the loot tables (see snowball)
|
||||
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
|
||||
public static final String MARKER_STRING = "__scarpet_marker";
|
||||
|
||||
private static boolean stopAll = false;
|
||||
|
||||
@@ -2377,8 +2378,8 @@ public class CarpetExpression
|
||||
(float)pointLocator.yaw,
|
||||
(float) pointLocator.pitch
|
||||
);
|
||||
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
||||
armorstand.addScoreboardTag(ExpressionInspector.MARKER_STRING);
|
||||
armorstand.addScoreboardTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
||||
armorstand.addScoreboardTag(MARKER_STRING);
|
||||
if (targetBlock != null)
|
||||
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
|
||||
if (!name.isEmpty())
|
||||
@@ -2399,7 +2400,7 @@ public class CarpetExpression
|
||||
this.expr.addLazyFunction("remove_all_markers", 0, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
int total = 0;
|
||||
String markerName = ExpressionInspector.MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
|
||||
String markerName = MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
|
||||
for (Entity e : cc.s.getWorld().getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
{
|
||||
total ++;
|
||||
|
||||
@@ -346,7 +346,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
});
|
||||
|
||||
String markerName = ExpressionInspector.MARKER_STRING+"_"+((getName()==null)?"":getName());
|
||||
String markerName = CarpetExpression.MARKER_STRING+"_"+((getName()==null)?"":getName());
|
||||
for (ServerWorld world : CarpetServer.minecraft_server.getWorlds())
|
||||
{
|
||||
for (Entity e : world.getEntities(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
|
||||
@@ -99,6 +99,12 @@ public class Expression
|
||||
|
||||
public Module module = null;
|
||||
|
||||
public String getModuleName()
|
||||
{
|
||||
return module == null?null:module.getName();
|
||||
}
|
||||
|
||||
|
||||
void asATextSource()
|
||||
{
|
||||
allowNewlineSubstitutions = false;
|
||||
@@ -119,11 +125,11 @@ public class Expression
|
||||
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
|
||||
|
||||
private final Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
|
||||
Set<String> getFunctionNames() {return functions.keySet();}
|
||||
public Set<String> getFunctionNames() {return functions.keySet();}
|
||||
|
||||
static List<String> getExpressionSnippet(Tokenizer.Token token, Expression expr)
|
||||
public List<String> getExpressionSnippet(Tokenizer.Token token)
|
||||
{
|
||||
String code = expr.getCodeString();
|
||||
String code = this.getCodeString();
|
||||
List<String> output = new ArrayList<>();
|
||||
for (String line: getExpressionSnippetLeftContext(token, code, 1))
|
||||
{
|
||||
@@ -1949,7 +1955,7 @@ public class Expression
|
||||
return var;
|
||||
}
|
||||
|
||||
static final Expression none = new Expression("null");
|
||||
public static final Expression none = new Expression("null");
|
||||
/**
|
||||
* @param expression .
|
||||
*/
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package carpet.script;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* sole purpose of this package is to provide public access to package-private methods of Expression and CarpetExpression
|
||||
* classes so they don't leave garbage in javadocs
|
||||
*/
|
||||
public class ExpressionInspector
|
||||
{
|
||||
public static final String MARKER_STRING = "__scarpet_marker";
|
||||
public static List<String> Expression_getExpressionSnippet(Tokenizer.Token token, Expression expr)
|
||||
{
|
||||
return Expression.getExpressionSnippet(token, expr);
|
||||
}
|
||||
|
||||
public static String Expression_getModuleName(Expression e)
|
||||
{
|
||||
return e.module == null?null:e.module.getName();
|
||||
}
|
||||
|
||||
private static TreeSet<String> scarpetFunctions;
|
||||
private static TreeSet<String> APIFunctions;
|
||||
static
|
||||
{
|
||||
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
|
||||
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
|
||||
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
|
||||
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
|
||||
{
|
||||
previous = previous.replace("\\'", "");
|
||||
int quoteCount = StringUtils.countMatches(previous,'\'');
|
||||
if (quoteCount % 2 == 1)
|
||||
return Collections.emptyList();
|
||||
int maxLen = prefix.length()<3 ? (prefix.length()*2+1) : 1234;
|
||||
List<String> scarpetMatches = scarpetFunctions.stream().
|
||||
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()));
|
||||
// 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.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
|
||||
scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
|
||||
return scarpetMatches;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@ import carpet.script.value.FunctionValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static carpet.script.ExpressionInspector.Expression_getExpressionSnippet;
|
||||
import static carpet.script.ExpressionInspector.Expression_getModuleName;
|
||||
|
||||
/* The expression evaluators exception class. */
|
||||
public class ExpressionException extends RuntimeException implements ResolvedException
|
||||
{
|
||||
@@ -40,10 +37,10 @@ public class ExpressionException extends RuntimeException implements ResolvedExc
|
||||
{
|
||||
|
||||
List<String> errMsg = new ArrayList<>();
|
||||
errmessage += Expression_getModuleName(expr) == null?"":(" in "+Expression_getModuleName(expr));
|
||||
errmessage += expr.getModuleName() == null?"":(" in "+expr.getModuleName());
|
||||
if (token != null)
|
||||
{
|
||||
List<String> snippet = Expression_getExpressionSnippet(token, expr);
|
||||
List<String> snippet = expr.getExpressionSnippet(token);
|
||||
errMsg.addAll(snippet);
|
||||
|
||||
if (snippet.size() != 1)
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
|
||||
throw new InternalExpressionException("Cannot add two lists of uneven sizes");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -178,7 +178,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
|
||||
throw new InternalExpressionException("Cannot multiply two lists of uneven sizes");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -205,7 +205,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalExpressionException("Cannot subtract two lists of uneven sizes");
|
||||
throw new InternalExpressionException("Cannot divide two lists of uneven sizes");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user