Merge branch 'master' into 1.16
This commit is contained in:
commit
16033dfa1a
6 files changed
+41
-20
No files matched your search
@@ -210,7 +210,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
switch (tok.type)
|
switch (tok.type)
|
||||||
{
|
{
|
||||||
case VARIABLE:
|
case VARIABLE:
|
||||||
LazyValue var = getGlobalVariable(tok.surface.toLowerCase(Locale.ROOT));
|
LazyValue var = getGlobalVariable(tok.surface);
|
||||||
if (var != null)
|
if (var != null)
|
||||||
{
|
{
|
||||||
argv.add(var);
|
argv.add(var);
|
||||||
|
|||||||
@@ -321,7 +321,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addUnaryFunction(String name, Function<Value, Value> fun)
|
public void addUnaryFunction(String name, Function<Value, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(1)
|
functions.put(name, new AbstractFunction(1)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -334,7 +333,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addBinaryFunction(String name, BiFunction<Value, Value, Value> fun)
|
public void addBinaryFunction(String name, BiFunction<Value, Value, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(2)
|
functions.put(name, new AbstractFunction(2)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -350,7 +348,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addFunction(String name, Function<List<Value>, Value> fun)
|
public void addFunction(String name, Function<List<Value>, Value> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractFunction(-1)
|
functions.put(name, new AbstractFunction(-1)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -377,7 +374,6 @@ public class Expression
|
|||||||
|
|
||||||
public void addLazyFunction(String name, int num_params, TriFunction<Context, Integer, List<LazyValue>, LazyValue> fun)
|
public void addLazyFunction(String name, int num_params, TriFunction<Context, Integer, List<LazyValue>, LazyValue> fun)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
functions.put(name, new AbstractLazyFunction(num_params)
|
functions.put(name, new AbstractLazyFunction(num_params)
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -396,7 +392,6 @@ public class Expression
|
|||||||
}
|
}
|
||||||
public FunctionValue addContextFunction(Context context, String name, Expression expr, Tokenizer.Token token, List<String> arguments, List<String> outers, LazyValue code)
|
public FunctionValue addContextFunction(Context context, String name, Expression expr, Tokenizer.Token token, List<String> arguments, List<String> outers, LazyValue code)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
if (functions.containsKey(name))
|
if (functions.containsKey(name))
|
||||||
throw new ExpressionException(context, expr, token, "Function "+name+" would mask a built-in function");
|
throw new ExpressionException(context, expr, token, "Function "+name+" would mask a built-in function");
|
||||||
Map<String, LazyValue> contextValues = new HashMap<>();
|
Map<String, LazyValue> contextValues = new HashMap<>();
|
||||||
@@ -434,6 +429,7 @@ public class Expression
|
|||||||
if (lv.size() < 1) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import");
|
if (lv.size() < 1) throw new InternalExpressionException("'import' needs at least a module name to import, and list of values to import");
|
||||||
String moduleName = lv.get(0).evalValue(c).getString();
|
String moduleName = lv.get(0).evalValue(c).getString();
|
||||||
c.host.importModule(c, moduleName);
|
c.host.importModule(c, moduleName);
|
||||||
|
moduleName = moduleName.toLowerCase(Locale.ROOT);
|
||||||
if (lv.size() > 1)
|
if (lv.size() > 1)
|
||||||
c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList()));
|
c.host.importNames(c, module, moduleName, lv.subList(1, lv.size()).stream().map((l) -> l.evalValue(c).getString()).collect(Collectors.toList()));
|
||||||
if (t == Context.VOID)
|
if (t == Context.VOID)
|
||||||
@@ -2289,7 +2285,7 @@ public class Expression
|
|||||||
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c));
|
stack.push((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c));
|
||||||
break;
|
break;
|
||||||
case FUNCTION:
|
case FUNCTION:
|
||||||
String name = token.surface.toLowerCase(Locale.ROOT);
|
String name = token.surface;
|
||||||
ILazyFunction f;
|
ILazyFunction f;
|
||||||
ArrayList<LazyValue> p;
|
ArrayList<LazyValue> p;
|
||||||
boolean isKnown = functions.containsKey(name); // globals will be evaluated lazily, not at compile time via .
|
boolean isKnown = functions.containsKey(name); // globals will be evaluated lazily, not at compile time via .
|
||||||
@@ -2376,7 +2372,7 @@ public class Expression
|
|||||||
case OPERATOR:
|
case OPERATOR:
|
||||||
if (stack.peek() < 2)
|
if (stack.peek() < 2)
|
||||||
{
|
{
|
||||||
if (token.surface.equalsIgnoreCase(";"))
|
if (token.surface.equals(";"))
|
||||||
{
|
{
|
||||||
throw new ExpressionException(c, this, token, "Unnecessary semicolon");
|
throw new ExpressionException(c, this, token, "Unnecessary semicolon");
|
||||||
}
|
}
|
||||||
@@ -2386,7 +2382,7 @@ public class Expression
|
|||||||
stack.set(stack.size() - 1, stack.peek() - 2 + 1);
|
stack.set(stack.size() - 1, stack.peek() - 2 + 1);
|
||||||
break;
|
break;
|
||||||
case FUNCTION:
|
case FUNCTION:
|
||||||
ILazyFunction f = functions.get(token.surface.toLowerCase(Locale.ROOT));// don't validate global - userdef functions
|
ILazyFunction f = functions.get(token.surface);// don't validate global - userdef functions
|
||||||
int numParams = stack.pop();
|
int numParams = stack.pop();
|
||||||
if (f != null && !f.numParamsVaries() && numParams != f.getNumParams())
|
if (f != null && !f.numParamsVaries() && numParams != f.getNumParams())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -107,7 +108,7 @@ public abstract class ScriptHost
|
|||||||
|
|
||||||
public void importModule(Context c, String moduleName)
|
public void importModule(Context c, String moduleName)
|
||||||
{
|
{
|
||||||
if (modules.containsKey(moduleName)) return; // aready imported
|
if (modules.containsKey(moduleName.toLowerCase(Locale.ROOT))) return; // aready imported
|
||||||
Module module = getModuleOrLibraryByName(moduleName);
|
Module module = getModuleOrLibraryByName(moduleName);
|
||||||
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
if (modules.containsKey(module.getName())) return; // aready imported, once again, in case some discrepancies in names?
|
||||||
modules.put(module.getName(), module);
|
modules.put(module.getName(), module);
|
||||||
|
|||||||
@@ -370,12 +370,14 @@ public class Tokenizer implements Iterator<Tokenizer.Token>
|
|||||||
token.type == Token.TokenType.HEX_LITERAL ||
|
token.type == Token.TokenType.HEX_LITERAL ||
|
||||||
token.type == Token.TokenType.VARIABLE ||
|
token.type == Token.TokenType.VARIABLE ||
|
||||||
token.type == Token.TokenType.STRINGPARAM ||
|
token.type == Token.TokenType.STRINGPARAM ||
|
||||||
|
( token.type == Token.TokenType.MARKER && ( previousToken.surface.equalsIgnoreCase("{") || previousToken.surface.equalsIgnoreCase("["))) ||
|
||||||
token.type == Token.TokenType.FUNCTION
|
token.type == Token.TokenType.FUNCTION
|
||||||
) &&(
|
) &&(
|
||||||
previousToken.type == Token.TokenType.VARIABLE ||
|
previousToken.type == Token.TokenType.VARIABLE ||
|
||||||
previousToken.type == Token.TokenType.FUNCTION ||
|
previousToken.type == Token.TokenType.FUNCTION ||
|
||||||
previousToken.type == Token.TokenType.LITERAL ||
|
previousToken.type == Token.TokenType.LITERAL ||
|
||||||
previousToken.type == Token.TokenType.CLOSE_PAREN ||
|
previousToken.type == Token.TokenType.CLOSE_PAREN ||
|
||||||
|
( previousToken.type == Token.TokenType.MARKER && ( previousToken.surface.equalsIgnoreCase("}") || previousToken.surface.equalsIgnoreCase("]"))) ||
|
||||||
previousToken.type == Token.TokenType.HEX_LITERAL ||
|
previousToken.type == Token.TokenType.HEX_LITERAL ||
|
||||||
previousToken.type == Token.TokenType.STRINGPARAM
|
previousToken.type == Token.TokenType.STRINGPARAM
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -547,14 +547,13 @@ public class ShapeDispatcher
|
|||||||
super.init(options);
|
super.init(options);
|
||||||
from = vecFromValue(options.get("from"));
|
from = vecFromValue(options.get("from"));
|
||||||
to = vecFromValue(options.get("to"));
|
to = vecFromValue(options.get("to"));
|
||||||
if (from.equals(to)) throw new InternalExpressionException("Box dimensions are invalid - cannot draw a zero-size boxes");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Consumer<ServerPlayerEntity> alternative()
|
public Consumer<ServerPlayerEntity> alternative()
|
||||||
{
|
{
|
||||||
ParticleEffect particle = replacementParticle();
|
ParticleEffect particle = replacementParticle();
|
||||||
double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
|
double density = Math.max(2.0, from.distanceTo(to) /50/ (a+0.1)) ;
|
||||||
return p ->
|
return p ->
|
||||||
{
|
{
|
||||||
if (p.world.getRegistryKey() == shapeDimension)
|
if (p.world.getRegistryKey() == shapeDimension)
|
||||||
@@ -630,7 +629,6 @@ public class ShapeDispatcher
|
|||||||
super.init(options);
|
super.init(options);
|
||||||
from = vecFromValue(options.get("from"));
|
from = vecFromValue(options.get("from"));
|
||||||
to = vecFromValue(options.get("to"));
|
to = vecFromValue(options.get("to"));
|
||||||
if (from.equals(to)) throw new InternalExpressionException("Line dimensions are invalid - cannot draw a zero-length lines");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1285,13 +1283,33 @@ public class ShapeDispatcher
|
|||||||
|
|
||||||
public static int drawParticleLine(List<ServerPlayerEntity> players, ParticleEffect particle, Vec3d from, Vec3d to, double density)
|
public static int drawParticleLine(List<ServerPlayerEntity> players, ParticleEffect particle, Vec3d from, Vec3d to, double density)
|
||||||
{
|
{
|
||||||
if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density);
|
double distance = from.squaredDistanceTo(to);
|
||||||
double lineLengthSq = from.squaredDistanceTo(to);
|
if (distance == 0) return 0;
|
||||||
if (lineLengthSq == 0) return 0;
|
|
||||||
Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(lineLengthSq));
|
|
||||||
int pcount = 0;
|
int pcount = 0;
|
||||||
|
if (distance < 100)
|
||||||
|
{
|
||||||
|
Random rand = players.get(0).getServerWorld().random;
|
||||||
|
int particles = (int)(distance/density)+1;
|
||||||
|
Vec3d towards = to.subtract(from);
|
||||||
|
for (int i = 0; i < particles; i++)
|
||||||
|
{
|
||||||
|
Vec3d at = from.add(towards.multiply( rand.nextDouble()));
|
||||||
|
for (ServerPlayerEntity player : players)
|
||||||
|
{
|
||||||
|
player.getServerWorld().spawnParticles(player, particle, true,
|
||||||
|
at.x, at.y, at.z, 1,
|
||||||
|
0.0, 0.0, 0.0, 0.0);
|
||||||
|
pcount ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pcount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density);
|
||||||
|
Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(distance));
|
||||||
|
|
||||||
for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
|
for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
|
||||||
delta.lengthSquared()<lineLengthSq;
|
delta.lengthSquared()<distance;
|
||||||
delta = delta.add(incvec.multiply(Expression.randomizer.nextFloat())))
|
delta = delta.add(incvec.multiply(Expression.randomizer.nextFloat())))
|
||||||
{
|
{
|
||||||
for (ServerPlayerEntity player : players)
|
for (ServerPlayerEntity player : players)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
global_update_interval = 100;
|
||||||
global_chunk_colors = m(
|
global_chunk_colors = m(
|
||||||
// loaded ticking
|
// loaded ticking
|
||||||
l(3, l(0xAAdd0000, 0x66990000)), // lime, green
|
l(3, l(0xAAdd0000, 0x66990000)), // lime, green
|
||||||
@@ -126,6 +127,9 @@ __chunk_visualizer_tick(p) ->
|
|||||||
if (!global_running, return());
|
if (!global_running, return());
|
||||||
show_activity = (p~'holds':0 == 'redstone_torch');
|
show_activity = (p~'holds':0 == 'redstone_torch');
|
||||||
yval = setup:'plot_center':1+16;
|
yval = setup:'plot_center':1+16;
|
||||||
|
base_update = global_update_interval;
|
||||||
|
random_component = ceil(0.4*base_update);
|
||||||
|
duration_max = ceil(1.5*base_update);
|
||||||
in_dimension( setup:'plot_dimension',
|
in_dimension( setup:'plot_dimension',
|
||||||
l(sx, sy, sz) = setup:'source_center';
|
l(sx, sy, sz) = setup:'source_center';
|
||||||
l(px, py, pz) = setup:'plot_center';
|
l(px, py, pz) = setup:'plot_center';
|
||||||
@@ -160,10 +164,10 @@ __chunk_visualizer_tick(p) ->
|
|||||||
l(cached_status, expiry) = global_status_cache:source_pos;
|
l(cached_status, expiry) = global_status_cache:source_pos;
|
||||||
changed = (status != cached_status);
|
changed = (status != cached_status);
|
||||||
if ( changed || (expiry < now),
|
if ( changed || (expiry < now),
|
||||||
global_status_cache:source_pos = l(status, now+100+floor(rand(40)));
|
global_status_cache:source_pos = l(status, now+base_update+floor(rand(random_component)));
|
||||||
bpos = l(dx/2, yval, dz/2);
|
bpos = l(dx/2, yval, dz/2);
|
||||||
bcol = global_chunk_colors:status:((dx+dz)%2);
|
bcol = global_chunk_colors:status:((dx+dz)%2);
|
||||||
shapes += l('box', 150, 'from', bpos, 'to', bpos + l(0.5,0,0.5),
|
shapes += l('box', duration_max, 'from', bpos, 'to', bpos + l(0.5,0,0.5),
|
||||||
'color', 0xffffff00, 'fill', bcol+128, 'follow', p, 'snap', 'xz');
|
'color', 0xffffff00, 'fill', bcol+128, 'follow', p, 'snap', 'xz');
|
||||||
if (changed,
|
if (changed,
|
||||||
pbcol = global_chunk_colors:cached_status:((dx+dz)%2);
|
pbcol = global_chunk_colors:cached_status:((dx+dz)%2);
|
||||||
|
|||||||
Reference in new issue
Block a user