Merge branch 'master' into 1.15
# Conflicts: # src/main/java/carpet/fakes/StructureFeatureInterface.java # src/main/java/carpet/mixins/PistonBlock_movableTEMixin.java
This commit is contained in:
commit
c995716357
41 files changed
+122
-137
No files matched your search
@@ -6,7 +6,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
public class CarpetContext extends Context
|
||||
{
|
||||
public ServerCommandSource s;
|
||||
public BlockPos origin;
|
||||
public final BlockPos origin;
|
||||
public CarpetContext(ScriptHost host, ServerCommandSource source, BlockPos origin)
|
||||
{
|
||||
super(host);
|
||||
|
||||
@@ -43,12 +43,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class CarpetEventServer
|
||||
{
|
||||
public List<ScheduledCall> scheduledCalls = new LinkedList<>();
|
||||
public final List<ScheduledCall> scheduledCalls = new LinkedList<>();
|
||||
|
||||
public static class Callback
|
||||
{
|
||||
public String host;
|
||||
public FunctionValue function;
|
||||
public final String host;
|
||||
public final FunctionValue function;
|
||||
|
||||
public Callback(String host, FunctionValue function)
|
||||
{
|
||||
@@ -65,8 +65,8 @@ public class CarpetEventServer
|
||||
|
||||
public static class ScheduledCall extends Callback
|
||||
{
|
||||
public List<Value> args;
|
||||
private CarpetContext ctx;
|
||||
public final List<Value> args;
|
||||
private final CarpetContext ctx;
|
||||
public long dueTime;
|
||||
|
||||
public ScheduledCall(CarpetContext context, FunctionValue function, List<Value> args, long dueTime)
|
||||
@@ -103,8 +103,8 @@ public class CarpetEventServer
|
||||
public static class CallbackList
|
||||
{
|
||||
|
||||
public List<Callback> callList;
|
||||
public int reqArgs;
|
||||
public final List<Callback> callList;
|
||||
public final int reqArgs;
|
||||
|
||||
public CallbackList(int reqArgs)
|
||||
{
|
||||
@@ -454,7 +454,7 @@ public class CarpetEventServer
|
||||
{
|
||||
return stat.getType().getRegistry().getId(stat.getValue());
|
||||
}
|
||||
private Set<Identifier> skippedStats = new HashSet<Identifier>(){{
|
||||
private final Set<Identifier> skippedStats = new HashSet<Identifier>(){{
|
||||
add(Stats.TIME_SINCE_DEATH);
|
||||
add(Stats.TIME_SINCE_REST);
|
||||
add(Stats.PLAY_ONE_MINUTE);
|
||||
@@ -476,14 +476,14 @@ public class CarpetEventServer
|
||||
|
||||
// on projectile thrown (arrow from bows, crossbows, tridents, snoballs, e-pearls
|
||||
|
||||
public String name;
|
||||
public static Map<String, Event> byName = new HashMap<String, Event>(){{
|
||||
public final String name;
|
||||
public static final Map<String, Event> byName = new HashMap<String, Event>(){{
|
||||
for (Event e: Event.values())
|
||||
{
|
||||
put(e.name, e);
|
||||
}
|
||||
}};
|
||||
public CallbackList handler;
|
||||
public final CallbackList handler;
|
||||
Event(String name, CallbackList eventHandler)
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
@@ -134,9 +134,9 @@ import static java.lang.Math.sqrt;
|
||||
public class CarpetExpression
|
||||
{
|
||||
|
||||
private ServerCommandSource source;
|
||||
private BlockPos origin;
|
||||
private Expression expr;
|
||||
private final ServerCommandSource source;
|
||||
private final BlockPos origin;
|
||||
private final Expression expr;
|
||||
Expression getExpr() {return expr;}
|
||||
private static long tickStart = 0L;
|
||||
|
||||
@@ -275,7 +275,7 @@ public class CarpetExpression
|
||||
return bs;
|
||||
}
|
||||
|
||||
private static Map<String, ParticleEffect> particleCache = new HashMap<>();
|
||||
private static final Map<String, ParticleEffect> particleCache = new HashMap<>();
|
||||
private ParticleEffect getParticleData(String name)
|
||||
{
|
||||
ParticleEffect particle = particleCache.get(name);
|
||||
@@ -2147,7 +2147,7 @@ public class CarpetExpression
|
||||
args = Collections.singletonList(lv.get(3).evalValue(c));
|
||||
else if (lv.size()>4)
|
||||
{
|
||||
args = new ArrayList<>(lv.subList(3, lv.size()).stream().map((vv) -> vv.evalValue(c)).collect(Collectors.toList()));
|
||||
args = lv.subList(3, lv.size()).stream().map((vv) -> vv.evalValue(c)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
((EntityValue) v).setEvent((CarpetContext)c, what, function, args);
|
||||
@@ -2379,12 +2379,12 @@ public class CarpetExpression
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
return (c_, t_) -> new LazyListValue()
|
||||
{
|
||||
int minx = cx-sminx;
|
||||
int miny = cy-sminy;
|
||||
int minz = cz-sminz;
|
||||
int maxx = cx+smaxx;
|
||||
int maxy = cy+smaxy;
|
||||
int maxz = cz+smaxz;
|
||||
final int minx = cx-sminx;
|
||||
final int miny = cy-sminy;
|
||||
final int minz = cz-sminz;
|
||||
final int maxx = cx+smaxx;
|
||||
final int maxy = cy+smaxy;
|
||||
final int maxz = cz+smaxz;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
@@ -3190,7 +3190,7 @@ public class CarpetExpression
|
||||
this.expr.addLazyFunction("schedule", -1, (c, t, lv) -> {
|
||||
if (lv.size()<2)
|
||||
throw new InternalExpressionException("'schedule' should have at least 2 arguments, delay and call name");
|
||||
Long delay = NumericValue.asNumber(lv.get(0).evalValue(c)).getLong();
|
||||
long delay = NumericValue.asNumber(lv.get(0).evalValue(c)).getLong();
|
||||
|
||||
Value functionValue = lv.get(1).evalValue(c);
|
||||
if (!(functionValue instanceof FunctionValue))
|
||||
|
||||
@@ -31,7 +31,7 @@ import static java.lang.Math.max;
|
||||
|
||||
public class CarpetScriptHost extends ScriptHost
|
||||
{
|
||||
private CarpetScriptServer scriptServer;
|
||||
private final CarpetScriptServer scriptServer;
|
||||
|
||||
private Tag globalState;
|
||||
private int saveTimeout;
|
||||
|
||||
@@ -33,14 +33,14 @@ import static net.minecraft.server.command.CommandManager.literal;
|
||||
public class CarpetScriptServer
|
||||
{
|
||||
//make static for now, but will change that later:
|
||||
public CarpetScriptHost globalHost;
|
||||
public Map<String, CarpetScriptHost> modules;
|
||||
public final CarpetScriptHost globalHost;
|
||||
public final Map<String, CarpetScriptHost> modules;
|
||||
public long tickStart;
|
||||
public boolean stopAll;
|
||||
private Set<String> holyMoly;
|
||||
public CarpetEventServer events;
|
||||
private final Set<String> holyMoly;
|
||||
public final CarpetEventServer events;
|
||||
|
||||
private static List<ModuleInterface> bundledModuleData = new ArrayList<ModuleInterface>(){{
|
||||
private static final List<ModuleInterface> bundledModuleData = new ArrayList<ModuleInterface>(){{
|
||||
add(new BundledModule("camera"));
|
||||
add(new BundledModule("event_test"));
|
||||
add(new BundledModule("stats_test"));
|
||||
|
||||
@@ -17,9 +17,9 @@ public class Context
|
||||
public static final int LOCALIZATION = 8;
|
||||
public static final int LVALUE = 9;
|
||||
|
||||
public Map<String, LazyValue> variables = new HashMap<>();
|
||||
public final Map<String, LazyValue> variables = new HashMap<>();
|
||||
|
||||
public ScriptHost host;
|
||||
public final ScriptHost host;
|
||||
|
||||
Context(ScriptHost host)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class EntityEventsGroup
|
||||
{
|
||||
private Map<EntityEventType, Map<String, CarpetEventServer.ScheduledCall>> actions;
|
||||
private final Map<EntityEventType, Map<String, CarpetEventServer.ScheduledCall>> actions;
|
||||
public EntityEventsGroup()
|
||||
{
|
||||
actions = new EnumMap<>(EntityEventType.class);
|
||||
@@ -96,10 +96,10 @@ public class EntityEventsGroup
|
||||
}
|
||||
};
|
||||
|
||||
public static Map<String, EntityEventType> byName = Arrays.stream(EntityEventType.values()).collect(Collectors.toMap(ev -> ev.id, ev -> ev));
|
||||
public static final Map<String, EntityEventType> byName = Arrays.stream(EntityEventType.values()).collect(Collectors.toMap(ev -> ev.id, ev -> ev));
|
||||
|
||||
public int argcount;
|
||||
public String id;
|
||||
public final int argcount;
|
||||
public final String id;
|
||||
EntityEventType(String identifier, int args)
|
||||
{
|
||||
id = identifier;
|
||||
@@ -121,6 +121,6 @@ public class EntityEventsGroup
|
||||
protected List<Value> makeArgs(Entity entity, Object ... args)
|
||||
{
|
||||
return Collections.singletonList(new EntityValue(entity));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,7 @@ public class Expression implements Cloneable
|
||||
"2.71828182845904523536028747135266249775724709369995957496696762772407663");
|
||||
|
||||
// %[argument_index$][flags][width][.precision][t]conversion
|
||||
private static Pattern formatPattern = Pattern.compile("%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])");
|
||||
private static final Pattern formatPattern = Pattern.compile("%(\\d+\\$)?([-#+ 0,(<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])");
|
||||
|
||||
/** The current infix expression */
|
||||
private String expression;
|
||||
@@ -387,10 +387,10 @@ public class Expression implements Cloneable
|
||||
private LazyValue ast = null;
|
||||
|
||||
/** script specific operatos and built-in functions */
|
||||
private Map<String, ILazyOperator> operators = new Object2ObjectOpenHashMap<>();
|
||||
private final Map<String, ILazyOperator> operators = new Object2ObjectOpenHashMap<>();
|
||||
boolean isAnOperator(String opname) { return operators.containsKey(opname) || operators.containsKey(opname+"u");}
|
||||
|
||||
private Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
|
||||
private final Map<String, ILazyFunction> functions = new Object2ObjectOpenHashMap<>();
|
||||
Set<String> getFunctionNames() {return functions.keySet();}
|
||||
|
||||
@Override
|
||||
@@ -2878,7 +2878,6 @@ public class Expression implements Cloneable
|
||||
else if (fmt == '%')
|
||||
{
|
||||
//skip /%%
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3128,7 +3127,7 @@ public class Expression implements Cloneable
|
||||
|
||||
}
|
||||
|
||||
static Expression none = new Expression("null");
|
||||
static final Expression none = new Expression("null");
|
||||
/**
|
||||
* @param expression .
|
||||
*/
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ExpressionInspector
|
||||
{
|
||||
Set<String> allFunctions = (new CarpetExpression("null", null, null)).getExpr().getFunctionNames();
|
||||
scarpetFunctions = new TreeSet<>(new Expression("null").getFunctionNames());
|
||||
APIFunctions = new TreeSet<>(allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toSet()));
|
||||
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
|
||||
public static List<String> suggestFunctions(ScriptHost host, String previous, String prefix)
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public class CarpetExpressionException extends RuntimeException
|
||||
{
|
||||
public List<FunctionValue> stack;
|
||||
public final List<FunctionValue> stack;
|
||||
|
||||
public CarpetExpressionException(String message, List<FunctionValue> stack)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ import carpet.script.value.Value;
|
||||
/* Exception thrown to terminate execution mid expression (aka return statement) */
|
||||
public class ExitStatement extends RuntimeException
|
||||
{
|
||||
public Value retval;
|
||||
public final Value retval;
|
||||
public ExitStatement(Value value)
|
||||
{
|
||||
retval = value;
|
||||
|
||||
@@ -15,8 +15,8 @@ import static carpet.script.ExpressionInspector.Expression_getName;
|
||||
/* The expression evaluators exception class. */
|
||||
public class ExpressionException extends RuntimeException
|
||||
{
|
||||
public Context context;
|
||||
public List<FunctionValue> stack = new ArrayList<>();
|
||||
public final Context context;
|
||||
public final List<FunctionValue> stack = new ArrayList<>();
|
||||
public ExpressionException(Context c, String message)
|
||||
{
|
||||
super(makeMessage(c, null, null, message));
|
||||
@@ -35,7 +35,7 @@ public class ExpressionException extends RuntimeException
|
||||
context = c;
|
||||
}
|
||||
|
||||
private static Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorMaker = (expr, token, errmessage) ->
|
||||
private static final Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorMaker = (expr, token, errmessage) ->
|
||||
{
|
||||
|
||||
List<String> errMsg = new ArrayList<>();
|
||||
|
||||
@@ -36,8 +36,8 @@ public class BlockValue extends Value
|
||||
public static final BlockValue AIR = new BlockValue(Blocks.AIR.getDefaultState(), null, BlockPos.ORIGIN);
|
||||
public static final BlockValue NULL = new BlockValue(null, null, null);
|
||||
private BlockState blockState;
|
||||
private BlockPos pos;
|
||||
private ServerWorld world;
|
||||
private final BlockPos pos;
|
||||
private final ServerWorld world;
|
||||
private CompoundTag data;
|
||||
|
||||
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
|
||||
@@ -46,7 +46,7 @@ public class BlockValue extends Value
|
||||
return new BlockValue(null, c.s.getWorld(), pos);
|
||||
}
|
||||
|
||||
private static Map<String, BlockValue> bvCache= new HashMap<>();
|
||||
private static final Map<String, BlockValue> bvCache= new HashMap<>();
|
||||
public static BlockValue fromString(String str)
|
||||
{
|
||||
try
|
||||
@@ -294,8 +294,8 @@ public class BlockValue extends Value
|
||||
|
||||
public static class LocatorResult
|
||||
{
|
||||
public BlockValue block;
|
||||
public int offset;
|
||||
public final BlockValue block;
|
||||
public final int offset;
|
||||
LocatorResult(BlockValue b, int o)
|
||||
{
|
||||
block = b;
|
||||
@@ -306,9 +306,9 @@ public class BlockValue extends Value
|
||||
public static class VectorLocator
|
||||
{
|
||||
public Vec3d vec;
|
||||
public int offset;
|
||||
public double yaw;
|
||||
public double pitch;
|
||||
public final int offset;
|
||||
public final double yaw;
|
||||
public final double pitch;
|
||||
public boolean fromBlock;
|
||||
VectorLocator(Vec3d v, int o)
|
||||
{
|
||||
@@ -358,9 +358,9 @@ public class BlockValue extends Value
|
||||
EASTUP("east-up", 0.0, 0.6, 0.5, Direction.EAST),
|
||||
WESTUP("west-up", 1.0, 0.6, 0.5, Direction.WEST);
|
||||
|
||||
public String name;
|
||||
public Vec3d hitOffset;
|
||||
public Direction facing;
|
||||
public final String name;
|
||||
public final Vec3d hitOffset;
|
||||
public final Direction facing;
|
||||
|
||||
private static final Map<String, SpecificDirection> DIRECTION_MAP = Arrays.stream(values()).collect(Collectors.toMap(SpecificDirection::getName, d -> d));
|
||||
|
||||
|
||||
@@ -62,14 +62,14 @@ import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||
// TODO: decide whether copy(entity) should duplicate entity in the world.
|
||||
public class EntityValue extends Value
|
||||
{
|
||||
private Entity entity;
|
||||
private final Entity entity;
|
||||
|
||||
public EntityValue(Entity e)
|
||||
{
|
||||
entity = e;
|
||||
}
|
||||
|
||||
private static Map<String, EntitySelector> selectorCache = new HashMap<>();
|
||||
private static final Map<String, EntitySelector> selectorCache = new HashMap<>();
|
||||
public static Collection<? extends Entity > getEntitiesFromSelector(ServerCommandSource source, String selector)
|
||||
{
|
||||
try
|
||||
@@ -177,7 +177,7 @@ public class EntityValue extends Value
|
||||
return res; //TODO add more here like search by tags, or type
|
||||
//if (who.startsWith('tag:'))
|
||||
}
|
||||
private static Map<String, Pair<EntityType<?>, Predicate<? super Entity>>> entityPredicates =
|
||||
private static final Map<String, Pair<EntityType<?>, Predicate<? super Entity>>> entityPredicates =
|
||||
new HashMap<String, Pair<EntityType<?>, Predicate<? super Entity>>>()
|
||||
{{
|
||||
put("*", Pair.of(null, EntityPredicates.VALID_ENTITY));
|
||||
@@ -192,7 +192,7 @@ public class EntityValue extends Value
|
||||
throw new InternalExpressionException("Unknown entity feature: "+what);
|
||||
return featureAccessors.get(what).apply(entity, arg);
|
||||
}
|
||||
private static Map<String, EquipmentSlot> inventorySlots = new HashMap<String, EquipmentSlot>(){{
|
||||
private static final Map<String, EquipmentSlot> inventorySlots = new HashMap<String, EquipmentSlot>(){{
|
||||
put("mainhand", EquipmentSlot.MAINHAND);
|
||||
put("offhand", EquipmentSlot.OFFHAND);
|
||||
put("head", EquipmentSlot.HEAD);
|
||||
@@ -200,7 +200,7 @@ public class EntityValue extends Value
|
||||
put("legs", EquipmentSlot.LEGS);
|
||||
put("feet", EquipmentSlot.FEET);
|
||||
}};
|
||||
private static Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
||||
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>() {{
|
||||
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
||||
put("removed", (entity, arg) -> new NumericValue(entity.removed));
|
||||
put("uuid",(e, a) -> new StringValue(e.getUuidAsString()));
|
||||
@@ -440,20 +440,6 @@ public class EntityValue extends Value
|
||||
});
|
||||
}};
|
||||
|
||||
private static <Req extends Entity> Req assertEntityArgType(Class<Req> klass, Value arg)
|
||||
{
|
||||
if (!(arg instanceof EntityValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Entity e = ((EntityValue) arg).getEntity();
|
||||
if (!(klass.isAssignableFrom(e.getClass())))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (Req)e;
|
||||
}
|
||||
|
||||
public void set(String what, Value toWhat)
|
||||
{
|
||||
if (!(featureModifiers.containsKey(what)))
|
||||
@@ -502,7 +488,7 @@ public class EntityValue extends Value
|
||||
|
||||
|
||||
|
||||
private static Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
||||
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
||||
put("remove", (entity, value) -> entity.remove());
|
||||
put("health", (e, v) -> { if (e instanceof LivingEntity) ((LivingEntity) e).setHealth((float) NumericValue.asNumber(v).getDouble()); });
|
||||
put("kill", (e, v) -> e.kill());
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
}
|
||||
public Value reboundedTo(String var)
|
||||
{
|
||||
Value copy = null;
|
||||
Value copy;
|
||||
try
|
||||
{
|
||||
copy = (Value)clone();
|
||||
@@ -202,5 +202,5 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
// should never happen
|
||||
throw new InternalExpressionException("Cannot make a copy of value: "+this);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user