Merge branch 'master' into future
This commit is contained in:
commit
6a03675b4f
16 files changed
+161
-36
No files matched your search
@@ -1174,7 +1174,7 @@ public class CarpetEventServer
|
||||
}
|
||||
catch (NullPointerException | InvalidCallbackException | IntegrityException error)
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Got exception: "+error.getMessage());
|
||||
CarpetScriptServer.LOG.error("Got exception when running event call ", error);
|
||||
return CallbackResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ public class Expression
|
||||
if (exc instanceof ResolvedException)
|
||||
return exc;
|
||||
// unexpected really - should be caught earlier and converted to InternalExpressionException
|
||||
exc.printStackTrace();
|
||||
CarpetSettings.LOG.error("Unexpected exception while running Scarpet code", exc);
|
||||
return new ExpressionException(c, e, token, "Error while evaluating expression: "+exc);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.script.exception.ThrowStatement;
|
||||
import carpet.script.exception.Throwables;
|
||||
import carpet.script.utils.SnoopyCommandSource;
|
||||
import carpet.script.utils.SystemInfo;
|
||||
import carpet.script.utils.InputValidator;
|
||||
import carpet.script.utils.ScarpetJsonDeserializer;
|
||||
import carpet.script.utils.ShapeDispatcher;
|
||||
@@ -655,8 +656,10 @@ public class Auxiliary {
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTicks()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getWorld().getTime()));
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("world_time()");
|
||||
return new NumericValue(((CarpetContext) c).s.getWorld().getTime());
|
||||
});
|
||||
|
||||
expression.addContextFunction("day_time", -1, (c, t, lv) ->
|
||||
{
|
||||
@@ -672,16 +675,8 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("last_tick_times", -1, (c, t, lv) ->
|
||||
{
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
int currentReportedTick = ((CarpetContext) c).s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = ((CarpetContext) c).s.getServer().lastTickLengths;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
}
|
||||
return ListValue.wrap(ticks);
|
||||
c.host.issueDeprecation("last_tick_times()");
|
||||
return SystemInfo.get("last_tick_times", (CarpetContext)c);
|
||||
});
|
||||
|
||||
|
||||
@@ -742,8 +737,10 @@ public class Auxiliary {
|
||||
expression.addContextFunction("current_dimension", 0, (c, t, lv) ->
|
||||
ValueConversions.of( ((CarpetContext)c).s.getWorld()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance()));
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("view_distance()");
|
||||
return new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance());
|
||||
});
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
|
||||
@@ -10,6 +10,7 @@ import carpet.script.utils.SimplexNoiseSampler;
|
||||
import carpet.script.value.BooleanValue;
|
||||
import carpet.script.value.FunctionValue;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.MapValue;
|
||||
import carpet.script.value.NullValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.StringValue;
|
||||
@@ -56,6 +57,10 @@ public class Sys {
|
||||
if (num.isInteger()) return new NumericValue(num.getLong());
|
||||
return new NumericValue(num.getDouble());
|
||||
}
|
||||
if (v instanceof ListValue || v instanceof MapValue)
|
||||
{
|
||||
return new NumericValue(v.length());
|
||||
}
|
||||
try
|
||||
{
|
||||
return new NumericValue(v.getString());
|
||||
|
||||
@@ -23,9 +23,11 @@ import net.minecraft.world.WorldProperties;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
@@ -58,6 +60,7 @@ public class SystemInfo {
|
||||
WorldProperties prop = c.s.getServer().getOverworld().getLevelProperties();
|
||||
return ListValue.of(NumericValue.of(prop.getSpawnX()), NumericValue.of(prop.getSpawnY()), NumericValue.of(prop.getSpawnZ()));
|
||||
});
|
||||
put("world_time", c -> new NumericValue(c.s.getWorld().getTime()));
|
||||
|
||||
put("game_difficulty", c -> StringValue.of(c.s.getServer().getSaveProperties().getDifficulty().getName()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.s.getServer().getSaveProperties().isHardcore()));
|
||||
@@ -114,6 +117,18 @@ public class SystemInfo {
|
||||
ret.put(new StringValue(mod.getMetadata().getName()), new StringValue(mod.getMetadata().getVersion().getFriendlyString()));
|
||||
return MapValue.wrap(ret);
|
||||
});
|
||||
put("server_last_tick_times", c -> {
|
||||
//assuming we are in the tick world section
|
||||
// might be off one tick when run in the off tasks or asynchronously.
|
||||
int currentReportedTick = c.s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = c.s.getServer().lastTickLengths;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
}
|
||||
return ListValue.wrap(ticks);
|
||||
});
|
||||
|
||||
put("java_max_memory", c -> new NumericValue(Runtime.getRuntime().maxMemory()));
|
||||
put("java_allocated_memory", c -> new NumericValue(Runtime.getRuntime().totalMemory()));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
@@ -42,7 +43,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
// should not happen
|
||||
e.printStackTrace();
|
||||
CarpetSettings.LOG.catching(e);
|
||||
throw new InternalExpressionException("Variable of type "+getTypeString()+" is not cloneable. Tell gnembon about it, this shoudn't happen");
|
||||
}
|
||||
copy.boundVariable = var;
|
||||
|
||||
Reference in new issue
Block a user