refactor access to context data
This commit is contained in:
1 parent
bc31faca21
commit
8dd08d5cb1
15 files changed
+239
-194
No files matched your search
@@ -3,11 +3,16 @@ package carpet.script;
|
||||
import carpet.script.value.Value;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
public class CarpetContext extends Context
|
||||
{
|
||||
public CommandSourceStack s;
|
||||
public final BlockPos origin;
|
||||
private CommandSourceStack s;
|
||||
private final BlockPos origin;
|
||||
|
||||
public CarpetContext(CarpetScriptHost host, CommandSourceStack source) {
|
||||
this(host, source, BlockPos.ZERO);
|
||||
@@ -34,4 +39,38 @@ public class CarpetContext extends Context
|
||||
variables.put("_y", (c, t) -> Value.ZERO);
|
||||
variables.put("_z", (c, t) -> Value.ZERO);
|
||||
}
|
||||
|
||||
public MinecraftServer server()
|
||||
{
|
||||
return s.getServer();
|
||||
}
|
||||
|
||||
public ServerLevel level()
|
||||
{
|
||||
return s.getLevel();
|
||||
}
|
||||
|
||||
public RegistryAccess registryAccess()
|
||||
{
|
||||
return s.getLevel().registryAccess();
|
||||
}
|
||||
|
||||
public <T> Registry<T> registry(ResourceKey<? extends Registry<? extends T>> resourceKey) {
|
||||
return registryAccess().registryOrThrow(resourceKey);
|
||||
}
|
||||
|
||||
public CommandSourceStack source()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
public BlockPos origin()
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
|
||||
public void swapSource(CommandSourceStack source)
|
||||
{
|
||||
s = source;
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class CarpetEventServer
|
||||
*/
|
||||
public void execute()
|
||||
{
|
||||
CarpetServer.scriptServer.events.runScheduledCall(ctx.origin, ctx.s, host, (CarpetScriptHost) ctx.host, function, parametrizedArgs);
|
||||
CarpetServer.scriptServer.events.runScheduledCall(ctx.origin(), ctx.source(), host, (CarpetScriptHost) ctx.host, function, parametrizedArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1315,7 +1315,7 @@ public class CarpetEventServer
|
||||
{
|
||||
Event ev = Event.getEvent(event, ((CarpetScriptHost)cc.host).scriptServer());
|
||||
if (ev == null) return -1;
|
||||
return ev.handler.signal(cc.s, optionalTarget, callArgs);
|
||||
return ev.handler.signal(cc.source(), optionalTarget, callArgs);
|
||||
}
|
||||
|
||||
private void onEventAddedToHost(Event event, ScriptHost host)
|
||||
|
||||
@@ -579,9 +579,9 @@ public class CarpetScriptHost extends ScriptHost
|
||||
protected void runModuleCode(Context c, Module module)
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
CarpetExpression ex = new CarpetExpression(module, module.code(), cc.s, cc.origin);
|
||||
CarpetExpression ex = new CarpetExpression(module, module.code(), cc.source(), cc.origin());
|
||||
ex.getExpr().asATextSource();
|
||||
ex.scriptRunCommand(this, cc.origin);
|
||||
ex.scriptRunCommand(this, cc.origin());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -167,8 +167,9 @@ public class Auxiliary {
|
||||
Vec3 vec = locator.vec;
|
||||
double d0 = Math.pow(volume > 1.0F ? (double)(volume * 16.0F) : 16.0D, 2.0D);
|
||||
int count = 0;
|
||||
long seed = cc.s.getLevel().getRandom().nextLong();
|
||||
for (ServerPlayer player : cc.s.getLevel().getPlayers( (p) -> p.distanceToSqr(vec) < d0))
|
||||
final ServerLevel level = cc.level();
|
||||
long seed = level.getRandom().nextLong();
|
||||
for (ServerPlayer player : level.getPlayers( (p) -> p.distanceToSqr(vec) < d0))
|
||||
{
|
||||
count++;
|
||||
player.connection.send(new ClientboundSoundPacket(soundHolder, mixer, vec.x, vec.y, vec.z, volume, pitch, seed));
|
||||
@@ -180,8 +181,8 @@ public class Auxiliary {
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (lv.size() == 0) return ListValue.wrap(BuiltInRegistries.PARTICLE_TYPE.keySet().stream().map(ValueConversions::of));
|
||||
MinecraftServer ms = cc.s.getServer();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
MinecraftServer ms = cc.server();
|
||||
ServerLevel world = cc.level();
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
String particleName = lv.get(0).getString();
|
||||
int count = 10;
|
||||
@@ -227,7 +228,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("particle_line", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
String particleName = lv.get(0).getString();
|
||||
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess());
|
||||
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
|
||||
@@ -252,7 +253,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getServer().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
player = cc.server().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,12 +264,12 @@ public class Auxiliary {
|
||||
));
|
||||
});
|
||||
|
||||
expression.addContextFunction("item_display_name", 1, (c, t, lv) -> new FormattedTextValue(ValueConversions.getItemStackFromValue(lv.get(0), false, ((CarpetContext)c).s.registryAccess() ).getHoverName()));
|
||||
expression.addContextFunction("item_display_name", 1, (c, t, lv) -> new FormattedTextValue(ValueConversions.getItemStackFromValue(lv.get(0), false, ((CarpetContext)c).registryAccess()).getHoverName()));
|
||||
|
||||
expression.addContextFunction("particle_box", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
String particleName = lv.get(0).getString();
|
||||
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess() );
|
||||
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
|
||||
@@ -294,7 +295,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getServer().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
player = cc.server().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,7 +316,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("draw_shape", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
MinecraftServer server = world.getServer();
|
||||
Set<ServerPlayer> playerTargets = new HashSet<>();
|
||||
List<ShapeDispatcher.ShapeWithConfig> shapes = new ArrayList<>();
|
||||
@@ -335,7 +336,7 @@ public class Auxiliary {
|
||||
}
|
||||
|
||||
ShapeDispatcher.sendShape(
|
||||
(playerTargets.isEmpty())?cc.s.getLevel().players():playerTargets,
|
||||
(playerTargets.isEmpty())?cc.level().players():playerTargets,
|
||||
shapes
|
||||
);
|
||||
return Value.TRUE;
|
||||
@@ -366,8 +367,8 @@ public class Auxiliary {
|
||||
{
|
||||
throw new InternalExpressionException("'create_marker' requires a name and three coordinates, with optional direction, and optional block on its head");
|
||||
}
|
||||
|
||||
ArmorStand armorstand = new ArmorStand(EntityType.ARMOR_STAND, cc.s.getLevel());
|
||||
Level level = cc.level();
|
||||
ArmorStand armorstand = new ArmorStand(EntityType.ARMOR_STAND, level);
|
||||
double yoffset;
|
||||
if (targetBlock == null && name == null)
|
||||
{
|
||||
@@ -410,7 +411,7 @@ public class Auxiliary {
|
||||
armorstand.setInvisible(true);
|
||||
armorstand.setInvulnerable(true);
|
||||
armorstand.getEntityData().set(ArmorStand.DATA_CLIENT_FLAGS, (byte)(interactable?8 : 16|8));
|
||||
cc.s.getLevel().addFreshEntity(armorstand);
|
||||
level.addFreshEntity(armorstand);
|
||||
return new EntityValue(armorstand);
|
||||
});
|
||||
|
||||
@@ -418,7 +419,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
int total = 0;
|
||||
String markerName = MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName());
|
||||
for (Entity e : cc.s.getLevel().getEntities(EntityType.ARMOR_STAND, (as) -> as.getTags().contains(markerName)))
|
||||
for (Entity e : cc.level().getEntities(EntityType.ARMOR_STAND, (as) -> as.getTags().contains(markerName)))
|
||||
{
|
||||
total ++;
|
||||
e.discard(); // discard // remove();
|
||||
@@ -468,7 +469,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("print", -1, (c, t, lv) ->
|
||||
{
|
||||
if (lv.size() == 0 || lv.size() > 2) throw new InternalExpressionException("'print' takes one or two arguments");
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).source();
|
||||
MinecraftServer server = s.getServer();
|
||||
Value res = lv.get(0);
|
||||
List<ServerPlayer> targets = null;
|
||||
@@ -500,7 +501,7 @@ public class Auxiliary {
|
||||
if (lv.size() < 2) throw new InternalExpressionException("'display_title' needs at least a target, type and message, and optionally times");
|
||||
Value pVal = lv.get(0);
|
||||
if (!(pVal instanceof ListValue)) pVal = ListValue.of(pVal);
|
||||
MinecraftServer server = ((CarpetContext)c).s.getServer();
|
||||
MinecraftServer server = ((CarpetContext)c).server();
|
||||
Stream<ServerPlayer> targets = ((ListValue) pVal).getItems().stream().map(v ->
|
||||
{
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(server, v);
|
||||
@@ -574,7 +575,7 @@ public class Auxiliary {
|
||||
map.put(target.getScoreboardName(), (MutableComponent) title);
|
||||
total.getAndIncrement();
|
||||
});
|
||||
HUDController.update_hud(((CarpetContext)c).s.getServer(), targetList);
|
||||
HUDController.update_hud(((CarpetContext)c).server(), targetList);
|
||||
return NumericValue.of(total.get());
|
||||
}
|
||||
ClientboundSetTitlesAnimationPacket timesPacket; // TimesPacket
|
||||
@@ -609,7 +610,7 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("run", 1, (c, t, lv) ->
|
||||
{
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).source();
|
||||
try
|
||||
{
|
||||
Component[] error = {null};
|
||||
@@ -632,7 +633,7 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("save", 0, (c, t, lv) ->
|
||||
{
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).source();
|
||||
s.getServer().getPlayerList().saveAll();
|
||||
s.getServer().saveAllChunks(true,true,true);
|
||||
for (ServerLevel world : s.getServer().getAllLevels())
|
||||
@@ -644,21 +645,21 @@ public class Auxiliary {
|
||||
});
|
||||
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTickCount()));
|
||||
new NumericValue(((CarpetContext) c).server().getTickCount()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("world_time()");
|
||||
return new NumericValue(((CarpetContext) c).s.getLevel().getGameTime());
|
||||
return new NumericValue(((CarpetContext) c).level().getGameTime());
|
||||
});
|
||||
|
||||
expression.addContextFunction("day_time", -1, (c, t, lv) ->
|
||||
{
|
||||
Value time = new NumericValue(((CarpetContext) c).s.getLevel().getDayTime());
|
||||
Value time = new NumericValue(((CarpetContext) c).level().getDayTime());
|
||||
if (lv.size() > 0)
|
||||
{
|
||||
long newTime = NumericValue.asNumber(lv.get(0)).getLong();
|
||||
if (newTime < 0) newTime = 0;
|
||||
((CarpetContext) c).s.getLevel().setDayTime(newTime);// setTimeOfDay(newTime);
|
||||
((CarpetContext) c).level().setDayTime(newTime);
|
||||
}
|
||||
return time;
|
||||
});
|
||||
@@ -672,14 +673,15 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("game_tick", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
CommandSourceStack s = cc.s;
|
||||
//CommandSourceStack s = cc.source();
|
||||
MinecraftServer server = cc.server();
|
||||
if (CarpetServer.scriptServer == null) return Value.NULL;
|
||||
if (!s.getServer().isSameThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (!server.isSameThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (CarpetServer.scriptServer.tickDepth > 16) throw new InternalExpressionException("'game_tick' function caused other 'game_tick' functions to run. You should not allow that.");
|
||||
try
|
||||
{
|
||||
CarpetServer.scriptServer.tickDepth ++;
|
||||
((MinecraftServerInterface) s.getServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
((MinecraftServerInterface) server).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
if (lv.size() > 0)
|
||||
{
|
||||
long ms_total = NumericValue.asNumber(lv.get(0)).getLong();
|
||||
@@ -710,7 +712,7 @@ public class Auxiliary {
|
||||
});
|
||||
|
||||
expression.addContextFunction("seed", -1, (c, t, lv) -> {
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).source();
|
||||
c.host.issueDeprecation("seed()");
|
||||
return new NumericValue(s.getLevel().getSeed());
|
||||
});
|
||||
@@ -720,7 +722,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
BlockPos pos = locator.block.getPos();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
((ThreadedAnvilChunkStorageInterface) world.getChunkSource().chunkMap).relightChunk(new ChunkPos(pos));
|
||||
WorldTools.forceChunkUpdate(pos, world);
|
||||
return Value.TRUE;
|
||||
@@ -728,22 +730,22 @@ public class Auxiliary {
|
||||
|
||||
// Should this be deprecated for system_info('source_dimension')?
|
||||
expression.addContextFunction("current_dimension", 0, (c, t, lv) ->
|
||||
ValueConversions.of( ((CarpetContext)c).s.getLevel()));
|
||||
ValueConversions.of( ((CarpetContext)c).level()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("view_distance()");
|
||||
return new NumericValue(((CarpetContext)c).s.getServer().getPlayerList().getViewDistance());
|
||||
return new NumericValue(((CarpetContext)c).server().getPlayerList().getViewDistance());
|
||||
});
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
CommandSourceStack outerSource = ((CarpetContext)c).s;
|
||||
CommandSourceStack outerSource = ((CarpetContext)c).source();
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
Level world = ValueConversions.dimFromValue(dimensionValue, outerSource.getServer());
|
||||
if (world == outerSource.getLevel()) return lv.get(1);
|
||||
CommandSourceStack innerSource = outerSource.withLevel((ServerLevel)world);
|
||||
Context newCtx = c.recreate();
|
||||
((CarpetContext) newCtx).s = innerSource;
|
||||
((CarpetContext) newCtx).swapSource(innerSource);
|
||||
newCtx.variables = c.variables;
|
||||
Value retval = lv.get(1).evalValue(newCtx);
|
||||
return (cc, tt) -> retval;
|
||||
@@ -754,7 +756,7 @@ public class Auxiliary {
|
||||
{
|
||||
Map<Value, Value> plopData = new HashMap<>();
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
RegistryAccess registryManager = cc.s.getLevel().registryAccess();
|
||||
RegistryAccess registryManager = cc.registryAccess();
|
||||
plopData.put(StringValue.of("scarpet_custom"),
|
||||
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of).collect(Collectors.toList()))
|
||||
);
|
||||
@@ -777,14 +779,14 @@ public class Auxiliary {
|
||||
throw new InternalExpressionException("'plop' needs extra argument indicating what to plop");
|
||||
String what = lv.get(locator.offset).getString();
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
((CarpetContext)c).s.getServer().executeBlocking( () ->
|
||||
((CarpetContext)c).server().executeBlocking( () ->
|
||||
{
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).level(), locator.block.getPos());
|
||||
|
||||
if (res == null)
|
||||
return;
|
||||
if (what.equalsIgnoreCase("forest_rock")) // there might be more of those
|
||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getLevel());
|
||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).level());
|
||||
result[0] = BooleanValue.of(res);
|
||||
});
|
||||
return result[0];
|
||||
@@ -958,7 +960,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("statistic", 3, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(cc.s.getServer(), lv.get(0));
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(cc.server(), lv.get(0));
|
||||
if (player == null) return Value.NULL;
|
||||
ResourceLocation category;
|
||||
ResourceLocation statName;
|
||||
@@ -1012,7 +1014,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("nbt_storage", -1, (c, t, lv) -> {
|
||||
if (lv.size() > 2) throw new InternalExpressionException("'nbt_storage' requires 0, 1 or 2 arguments.");
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
CommandStorage storage = cc.s.getServer().getCommandStorage();
|
||||
CommandStorage storage = cc.server().getCommandStorage();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(storage.keys().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
||||
String key = lv.get(0).getString();
|
||||
@@ -1031,7 +1033,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
String origName = lv.get(0).getString();
|
||||
String name = InputValidator.validateSimpleString(origName, true);
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
MinecraftServer server = cc.server();
|
||||
for (String dpName : server.getPackRepository().getAvailableIds())
|
||||
{
|
||||
if (dpName.equalsIgnoreCase("file/"+name+".zip") ||
|
||||
|
||||
@@ -216,7 +216,7 @@ public class BlockIterators {
|
||||
expression.addContextFunction("neighbours", -1, (c, t, lv)->
|
||||
{
|
||||
BlockPos center = BlockArgument.findIn((CarpetContext) c, lv,0).block.getPos();
|
||||
ServerLevel world = ((CarpetContext) c).s.getLevel();
|
||||
ServerLevel world = ((CarpetContext) c).level();
|
||||
|
||||
List<Value> neighbours = new ArrayList<>();
|
||||
neighbours.add(new BlockValue(null, world, center.above()));
|
||||
|
||||
@@ -42,7 +42,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
public class Entities {
|
||||
private static ListValue getPlayersFromWorldMatching(Context c, Predicate<ServerPlayer> condition) {
|
||||
List<Value> ret = new ArrayList<>();
|
||||
for (ServerPlayer player: ((CarpetContext) c).s.getLevel().players()) {
|
||||
for (ServerPlayer player: ((CarpetContext) c).level().players()) {
|
||||
if (condition.test(player)) {
|
||||
ret.add(new EntityValue(player));
|
||||
}
|
||||
@@ -59,20 +59,20 @@ public class Entities {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (cc.host.user != null)
|
||||
{
|
||||
ServerPlayer player = cc.s.getServer().getPlayerList().getPlayerByName(cc.host.user);
|
||||
ServerPlayer player = cc.server().getPlayerList().getPlayerByName(cc.host.user);
|
||||
return EntityValue.of(player);
|
||||
}
|
||||
Entity callingEntity = cc.s.getEntity();
|
||||
Entity callingEntity = cc.source().getEntity();
|
||||
if (callingEntity instanceof Player) return EntityValue.of(callingEntity);
|
||||
Vec3 pos = ((CarpetContext)c).s.getPosition();
|
||||
Player closestPlayer = ((CarpetContext)c).s.getLevel().getNearestPlayer(pos.x, pos.y, pos.z, -1.0, EntitySelector.ENTITY_STILL_ALIVE);
|
||||
Vec3 pos = ((CarpetContext)c).source().getPosition();
|
||||
Player closestPlayer = ((CarpetContext)c).level().getNearestPlayer(pos.x, pos.y, pos.z, -1.0, EntitySelector.ENTITY_STILL_ALIVE);
|
||||
return EntityValue.of(closestPlayer);
|
||||
}
|
||||
String playerName = lv.get(0).getString();
|
||||
return switch (playerName) {
|
||||
case "all" -> {
|
||||
List<Value> ret = new ArrayList<>();
|
||||
for (ServerPlayer player: ((CarpetContext)c).s.getServer().getPlayerList().getPlayers())
|
||||
for (ServerPlayer player: ((CarpetContext)c).server().getPlayerList().getPlayers())
|
||||
ret.add(new EntityValue(player));
|
||||
yield ListValue.wrap(ret);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class Entities {
|
||||
case "spectating" -> getPlayersFromWorldMatching(c, ServerPlayer::isSpectator);
|
||||
case "!spectating" -> getPlayersFromWorldMatching(c, p -> !p.isSpectator());
|
||||
default -> {
|
||||
ServerPlayer player = ((CarpetContext) c).s.getServer().getPlayerList().getPlayerByName(playerName);
|
||||
ServerPlayer player = ((CarpetContext) c).server().getPlayerList().getPlayerByName(playerName);
|
||||
if (player != null) {
|
||||
yield new EntityValue(player);
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class Entities {
|
||||
tag.putString("id", entityId.toString());
|
||||
Vec3 vec3d = position.vec;
|
||||
|
||||
ServerLevel serverWorld = cc.s.getLevel();
|
||||
ServerLevel serverWorld = cc.level();
|
||||
Entity entity_1 = EntityType.loadEntityRecursive(tag, serverWorld, (entity_1x) -> {
|
||||
entity_1x.moveTo(vec3d.x, vec3d.y, vec3d.z, entity_1x.getYRot(), entity_1x.getXRot());
|
||||
return !serverWorld.addWithUUID(entity_1x) ? null : entity_1x;
|
||||
@@ -146,14 +146,14 @@ public class Entities {
|
||||
{
|
||||
Value who = lv.get(0);
|
||||
if (who instanceof NumericValue)
|
||||
return EntityValue.of(((CarpetContext)c).s.getLevel().getEntity((int)((NumericValue) who).getLong()));
|
||||
return EntityValue.of(((CarpetContext)c).s.getLevel().getEntity(UUID.fromString(who.getString())));
|
||||
return EntityValue.of(((CarpetContext)c).level().getEntity((int)((NumericValue) who).getLong()));
|
||||
return EntityValue.of(((CarpetContext)c).level().getEntity(UUID.fromString(who.getString())));
|
||||
});
|
||||
|
||||
expression.addContextFunction("entity_list", 1, (c, t, lv) ->
|
||||
{
|
||||
String who = lv.get(0).getString();
|
||||
CommandSourceStack source = ((CarpetContext)c).s;
|
||||
CommandSourceStack source = ((CarpetContext)c).source();
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
|
||||
List<? extends Entity> entityList = source.getLevel().getEntities(eDesc.directType, eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
@@ -182,8 +182,8 @@ public class Entities {
|
||||
throw new InternalExpressionException("Range of 'entity_area' cannot come from a block argument");
|
||||
Vec3 range = rangeLocator.vec;
|
||||
AABB area = centerBox.inflate(range.x, range.y, range.z);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.s.getServer());
|
||||
List<? extends Entity> entityList = cc.s.getLevel().getEntities(eDesc.directType, area,eDesc.filteringPredicate);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.server());
|
||||
List<? extends Entity> entityList = cc.level().getEntities(eDesc.directType, area,eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
@@ -191,7 +191,7 @@ public class Entities {
|
||||
{
|
||||
String selector = lv.get(0).getString();
|
||||
List<Value> retlist = new ArrayList<>();
|
||||
for (Entity e: EntityValue.getEntitiesFromSelector(((CarpetContext)c).s, selector))
|
||||
for (Entity e: EntityValue.getEntitiesFromSelector(((CarpetContext)c).source(), selector))
|
||||
{
|
||||
retlist.add(new EntityValue(e));
|
||||
}
|
||||
@@ -244,7 +244,7 @@ public class Entities {
|
||||
{
|
||||
if (lv.size() > 1) throw new InternalExpressionException("'entity_types' requires one or no arguments");
|
||||
String desc = (lv.size() == 1)?lv.get(0).getString():"*";
|
||||
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getServer()).listValue();
|
||||
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).server()).listValue();
|
||||
});
|
||||
|
||||
expression.addContextFunction("entity_load_handler", -1, (c, t, lv) ->
|
||||
@@ -255,7 +255,7 @@ public class Entities {
|
||||
? ((ListValue) entityValue).getItems().stream().map(Value::getString).collect(Collectors.toList())
|
||||
: Collections.singletonList(entityValue.getString());
|
||||
Set<EntityType<? extends Entity>> types = new HashSet<>();
|
||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getServer()).types));
|
||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).server()).types));
|
||||
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
|
||||
CarpetEventServer events = ((CarpetScriptHost)c.host).scriptServer().events;
|
||||
if (funArg.function == null)
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Inventories {
|
||||
public static void apply(Expression expression)
|
||||
{
|
||||
expression.addContextFunction("stack_limit", 1, (c, t, lv) ->
|
||||
new NumericValue(NBTSerializableValue.parseItem(lv.get(0).getString(), ((CarpetContext) c).s.registryAccess() ).getItem().getMaxStackSize()));
|
||||
new NumericValue(NBTSerializableValue.parseItem(lv.get(0).getString(), ((CarpetContext) c).registryAccess() ).getItem().getMaxStackSize()));
|
||||
|
||||
expression.addContextFunction("item_category", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
@@ -69,7 +69,7 @@ public class Inventories {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(BuiltInRegistries.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Registry<Item> items = cc.s.getServer().registryAccess().registryOrThrow(Registries.ITEM);
|
||||
Registry<Item> items = cc.registry(Registries.ITEM);
|
||||
String tag = lv.get(0).getString();
|
||||
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registries.ITEM, InputValidator.identifierOf(tag)));
|
||||
if (itemTag.isEmpty()) return Value.NULL;
|
||||
@@ -87,10 +87,10 @@ public class Inventories {
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
|
||||
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registries.ITEM);
|
||||
Registry<Item> blocks = cc.registry(Registries.ITEM);
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.s.registryAccess()).getItem();
|
||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.registryAccess()).getItem();
|
||||
if (lv.size() == 1)
|
||||
{
|
||||
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
|
||||
@@ -128,7 +128,7 @@ public class Inventories {
|
||||
type = BuiltInRegistries.RECIPE_TYPE.get(InputValidator.identifierOf(recipeType));
|
||||
}
|
||||
List<Recipe<?>> recipes;
|
||||
recipes = ((RecipeManagerInterface) cc.s.getServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
recipes = ((RecipeManagerInterface) cc.server().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
if (recipes.isEmpty())
|
||||
return Value.NULL;
|
||||
List<Value> recipesOutput = new ArrayList<>();
|
||||
@@ -279,7 +279,7 @@ public class Inventories {
|
||||
else
|
||||
nbt = new NBTSerializableValue(nbtValue.getString()).getCompoundTag();
|
||||
}
|
||||
ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()+2).getString(), nbt, cc.s.registryAccess());
|
||||
ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()+2).getString(), nbt, cc.registryAccess());
|
||||
ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
|
||||
try
|
||||
{
|
||||
@@ -304,7 +304,7 @@ public class Inventories {
|
||||
{
|
||||
Value secondArg = lv.get(inventoryLocator.offset()+0);
|
||||
if (!secondArg.isNull())
|
||||
itemArg = NBTSerializableValue.parseItem(secondArg.getString(), cc.s.registryAccess());
|
||||
itemArg = NBTSerializableValue.parseItem(secondArg.getString(), cc.registryAccess());
|
||||
}
|
||||
int startIndex = 0;
|
||||
if (lv.size() > inventoryLocator.offset()+1)
|
||||
@@ -329,7 +329,7 @@ public class Inventories {
|
||||
if (inventoryLocator == null) return Value.NULL;
|
||||
if (lv.size() <= inventoryLocator.offset())
|
||||
throw new InternalExpressionException("'inventory_remove' requires at least an item to be removed");
|
||||
ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString(), cc.s.registryAccess());
|
||||
ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString(), cc.registryAccess());
|
||||
int amount = 1;
|
||||
if (lv.size() > inventoryLocator.offset()+1)
|
||||
amount = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset()+1)).getLong();
|
||||
@@ -398,14 +398,14 @@ public class Inventories {
|
||||
Vec3 vec3d_1 = villager.getViewVector(1.0F).normalize().scale(0.3);// new Vec3d(0, 0.3, 0);
|
||||
item.setDeltaMovement(vec3d_1);
|
||||
item.setDefaultPickUpDelay();
|
||||
cc.s.getLevel().addFreshEntity(item);
|
||||
cc.level().addFreshEntity(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3 point = Vec3.atCenterOf(inventoryLocator.position()); //pos+0.5v
|
||||
item = new ItemEntity(cc.s.getLevel(), point.x, point.y, point.z, droppedStack);
|
||||
item = new ItemEntity(cc.level(), point.x, point.y, point.z, droppedStack);
|
||||
item.setDefaultPickUpDelay();
|
||||
cc.s.getLevel().addFreshEntity(item);
|
||||
cc.level().addFreshEntity(item);
|
||||
}
|
||||
return new NumericValue(item.getItem().getCount());
|
||||
});
|
||||
@@ -414,7 +414,7 @@ public class Inventories {
|
||||
{
|
||||
if(lv.size() < 3) throw new InternalExpressionException("'create_screen' requires at least three arguments");
|
||||
Value playerValue = lv.get(0);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), playerValue);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), playerValue);
|
||||
if(player == null) throw new InternalExpressionException("'create_screen' requires a valid online player as the first argument.");
|
||||
String type = lv.get(1).getString();
|
||||
Component name = FormattedTextValue.getTextByValue(lv.get(2));
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Monitoring {
|
||||
expression.addContextFunction("get_mob_counts", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState();
|
||||
if (info == null) return Value.NULL;
|
||||
Object2IntMap<MobCategory> mobcounts = info.getMobCategoryCounts();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
if (lv.size()==0)
|
||||
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new).collect(Collectors.toList()));
|
||||
String objectiveName = lv.get(0).getString();
|
||||
@@ -98,7 +98,7 @@ public class Scoreboards {
|
||||
{
|
||||
if (lv.size()==0) throw new InternalExpressionException("'scoreboard_remove' requires at least one parameter");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
String objectiveName = lv.get(0).getString();
|
||||
Objective objective = scoreboard.getOrCreateObjective(objectiveName);
|
||||
if (objective == null) return Value.FALSE;
|
||||
@@ -121,7 +121,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_add", -1, (c, t, lv)->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
if (lv.size() == 0 || lv.size()>2) throw new InternalExpressionException("'scoreboard_add' should have one or two parameters");
|
||||
String objectiveName = lv.get(0).getString();
|
||||
ObjectiveCriteria criterion;
|
||||
@@ -159,7 +159,7 @@ public class Scoreboards {
|
||||
{
|
||||
if(lv.size() < 2) throw new InternalExpressionException("'scoreboard_property' requires at least two parameters");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
Objective objective = scoreboard.getOrCreateObjective(lv.get(0).getString());
|
||||
if(objective == null) return Value.NULL;
|
||||
|
||||
@@ -224,7 +224,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_display", 2, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.server().getScoreboard();
|
||||
String location = lv.get(0).getString();
|
||||
int slot = Scoreboard.getDisplaySlotByName(location);
|
||||
if (slot < 0) throw new InternalExpressionException("Invalid objective slot: "+location);
|
||||
@@ -245,7 +245,7 @@ public class Scoreboards {
|
||||
{
|
||||
if(lv.size() > 1) throw new InternalExpressionException("'team_list' requires zero or one parameters");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||
if(lv.size() == 0)
|
||||
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of).collect(Collectors.toList()));
|
||||
if (lv.size() != 1) return Value.NULL;
|
||||
@@ -260,7 +260,7 @@ public class Scoreboards {
|
||||
if(!(lv.size() < 3 && lv.size() > 0)) throw new InternalExpressionException("'team_add' requires one or two parameters");
|
||||
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||
String teamName = lv.get(0).getString();
|
||||
|
||||
if(lv.size() == 1)
|
||||
@@ -283,7 +283,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_remove", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||
Value teamVal = lv.get(0);
|
||||
String team = teamVal.getString();
|
||||
if(scoreboard.getPlayerTeam(team) == null) return Value.NULL;
|
||||
@@ -295,7 +295,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_leave", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||
Value playerVal = lv.get(0);
|
||||
String player = EntityValue.getPlayerNameByValue(playerVal);
|
||||
if(player == null) return Value.NULL;
|
||||
@@ -305,7 +305,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_property", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.server().getScoreboard();
|
||||
|
||||
if(lv.size() < 2 || lv.size() > 3) throw new InternalExpressionException("'team_property' requires two or three arguments");
|
||||
|
||||
@@ -396,7 +396,7 @@ public class Scoreboards {
|
||||
|
||||
expression.addContextFunction("bossbar", -1, (c, t, lv) ->
|
||||
{
|
||||
CustomBossEvents bossBarManager = ((CarpetContext)c).s.getServer().getCustomBossEvents();
|
||||
CustomBossEvents bossBarManager = ((CarpetContext)c).server().getCustomBossEvents();
|
||||
if(lv.size() > 3) throw new InternalExpressionException("'bossbar' accepts max three arguments");
|
||||
|
||||
if(lv.size() == 0) return ListValue.wrap(bossBarManager.getEvents().stream().map(CustomBossEvent::getTextId).map(ResourceLocation::toString).map(StringValue::of).collect(Collectors.toList()));
|
||||
@@ -446,13 +446,13 @@ public class Scoreboards {
|
||||
|
||||
if(propertyValue instanceof ListValue) {
|
||||
((ListValue) propertyValue).getItems().forEach((v)->{
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext)c).s.getServer(),propertyValue);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext)c).server(), propertyValue);
|
||||
if(player != null) bossBar.addPlayer(player);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
|
||||
if(player != null) {
|
||||
bossBar.addPlayer(player);
|
||||
return Value.TRUE;
|
||||
@@ -464,14 +464,14 @@ public class Scoreboards {
|
||||
{
|
||||
bossBar.removeAllPlayers();
|
||||
((ListValue) propertyValue).getItems().forEach((v) -> {
|
||||
ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), v);
|
||||
ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).server(), v);
|
||||
if (p != null) bossBar.addPlayer(p);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
|
||||
ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
ServerPlayer p = EntityValue.getPlayerByValue(((CarpetContext) c).server(), propertyValue);
|
||||
bossBar.removeAllPlayers();
|
||||
if (p != null) {
|
||||
bossBar.addPlayer(p);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Threading
|
||||
{
|
||||
//"overidden" native call to cancel if on main thread
|
||||
expression.addContextFunction("task_join", 1, (c, t, lv) -> {
|
||||
if (((CarpetContext)c).s.getServer().isSameThread())
|
||||
if (((CarpetContext)c).server().isSameThread())
|
||||
throw new InternalExpressionException("'task_join' cannot be called from main thread to avoid deadlocks");
|
||||
Value v = lv.get(0);
|
||||
if (!(v instanceof ThreadValue))
|
||||
@@ -27,13 +27,13 @@ public class Threading
|
||||
// has to be lazy due to deferred execution of the expression
|
||||
expression.addLazyFunctionWithDelegation("task_dock", 1, false,true, (c, t, expr, tok, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
MinecraftServer server = cc.server();
|
||||
if (server.isSameThread()) return lv.get(0); // pass through for on thread tasks
|
||||
Value[] result = new Value[]{Value.NULL};
|
||||
RuntimeException[] internal = new RuntimeException[]{null};
|
||||
try
|
||||
{
|
||||
((CarpetContext) c).s.getServer().executeBlocking(() ->
|
||||
((CarpetContext) c).server().executeBlocking(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -198,7 +198,7 @@ public class WorldAccess {
|
||||
{
|
||||
try
|
||||
{
|
||||
return test.apply(((BlockValue) v0).getBlockState(), ((BlockValue) v0).getPos(), cc.s.getLevel());
|
||||
return test.apply(((BlockValue) v0).getBlockState(), ((BlockValue) v0).getPos(), cc.level());
|
||||
}
|
||||
catch (NullPointerException ignored)
|
||||
{
|
||||
@@ -206,7 +206,7 @@ public class WorldAccess {
|
||||
}
|
||||
}
|
||||
BlockValue block = BlockArgument.findIn(cc, params, 0).block;
|
||||
return test.apply(block.getBlockState(), block.getPos(), cc.s.getLevel());
|
||||
return test.apply(block.getBlockState(), block.getPos(), cc.level());
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> BlockState setProperty(Property<T> property, String name, String value,
|
||||
@@ -278,7 +278,7 @@ public class WorldAccess {
|
||||
if (lv.size() == 0) throw new InternalExpressionException("'poi' requires at least one parameter");
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0, false);
|
||||
BlockPos pos = locator.block.getPos();
|
||||
PoiManager store = cc.s.getLevel().getPoiManager();
|
||||
PoiManager store = cc.level().getPoiManager();
|
||||
if (lv.size() == locator.offset)
|
||||
{
|
||||
Optional<Holder<PoiType>> foo = store.getType(pos);
|
||||
@@ -353,7 +353,7 @@ public class WorldAccess {
|
||||
BlockPos pos = locator.block.getPos();
|
||||
if (lv.size() < locator.offset) throw new InternalExpressionException("'set_poi' requires the new poi type or null, after position argument");
|
||||
Value poi = lv.get(locator.offset+0);
|
||||
PoiManager store = cc.s.getLevel().getPoiManager();
|
||||
PoiManager store = cc.level().getPoiManager();
|
||||
if (poi.isNull())
|
||||
{ // clear poi information
|
||||
if (!store.getType(pos).isPresent()) return Value.FALSE;
|
||||
@@ -389,7 +389,7 @@ public class WorldAccess {
|
||||
|
||||
|
||||
expression.addContextFunction("weather",-1,(c, t, lv) -> {
|
||||
ServerLevel world = ((CarpetContext) c).s.getLevel();
|
||||
ServerLevel world = ((CarpetContext) c).level();
|
||||
|
||||
if(lv.size()==0)//cos it can thunder when raining or when clear.
|
||||
return new StringValue(world.isThundering() ? "thunder" : (world.isRaining() ? "rain" : "clear"));
|
||||
@@ -537,7 +537,7 @@ public class WorldAccess {
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
return BooleanValue.of(WorldgenRandom.seedSlimeChunk(
|
||||
chunkPos.x, chunkPos.z,
|
||||
((CarpetContext)c).s.getLevel().getSeed(),
|
||||
((CarpetContext)c).level().getSeed(),
|
||||
987234911L
|
||||
).nextInt(10) == 0);
|
||||
});
|
||||
@@ -559,24 +559,24 @@ public class WorldAccess {
|
||||
BlockPos pos = locator.block.getPos();
|
||||
int x = pos.getX();
|
||||
int z = pos.getZ();
|
||||
return new NumericValue(((CarpetContext)c).s.getLevel().getChunk(x >> 4, z >> 4).getHeight(htype, x & 15, z & 15) + 1);
|
||||
return new NumericValue(((CarpetContext)c).level().getChunk(x >> 4, z >> 4).getHeight(htype, x & 15, z & 15) + 1);
|
||||
});
|
||||
|
||||
expression.addContextFunction("loaded", -1, (c, t, lv) ->
|
||||
BooleanValue.of((((CarpetContext) c).s.getLevel().hasChunkAt(BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos()))));
|
||||
BooleanValue.of((((CarpetContext) c).level().hasChunkAt(BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos()))));
|
||||
|
||||
// Deprecated, use loaded_status as more indicative
|
||||
expression.addContextFunction("loaded_ep", -1, (c, t, lv) ->
|
||||
{
|
||||
c.host.issueDeprecation("loaded_ep(...)");
|
||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||
return BooleanValue.of(((CarpetContext)c).s.getLevel().isPositionEntityTicking(pos));// 1.17pre1 getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
return BooleanValue.of(((CarpetContext)c).level().isPositionEntityTicking(pos));// 1.17pre1 getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
});
|
||||
|
||||
expression.addContextFunction("loaded_status", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||
LevelChunk chunk = ((CarpetContext)c).s.getLevel().getChunkSource().getChunk(pos.getX()>>4, pos.getZ()>>4, false);
|
||||
LevelChunk chunk = ((CarpetContext)c).level().getChunkSource().getChunk(pos.getX()>>4, pos.getZ()>>4, false);
|
||||
if (chunk == null) return Value.ZERO;
|
||||
return new NumericValue(chunk.getFullStatus().ordinal());
|
||||
});
|
||||
@@ -588,7 +588,7 @@ public class WorldAccess {
|
||||
boolean force = false;
|
||||
if (lv.size() > locator.offset)
|
||||
force = lv.get(locator.offset).getBoolean();
|
||||
return BooleanValue.of(canHasChunk(((CarpetContext)c).s.getLevel(), new ChunkPos(pos), null, force));
|
||||
return BooleanValue.of(canHasChunk(((CarpetContext)c).level(), new ChunkPos(pos), null, force));
|
||||
});
|
||||
|
||||
expression.addContextFunction("generation_status", -1, (c, t, lv) ->
|
||||
@@ -598,14 +598,14 @@ public class WorldAccess {
|
||||
boolean forceLoad = false;
|
||||
if (lv.size() > blockArgument.offset)
|
||||
forceLoad = lv.get(blockArgument.offset).getBoolean();
|
||||
ChunkAccess chunk = ((CarpetContext)c).s.getLevel().getChunk(pos.getX()>>4, pos.getZ()>>4, ChunkStatus.EMPTY, forceLoad);
|
||||
ChunkAccess chunk = ((CarpetContext)c).level().getChunk(pos.getX()>>4, pos.getZ()>>4, ChunkStatus.EMPTY, forceLoad);
|
||||
if (chunk == null) return Value.NULL;
|
||||
return new StringValue(chunk.getStatus().getName());
|
||||
});
|
||||
|
||||
expression.addContextFunction("chunk_tickets", -1, (c, t, lv) ->
|
||||
{
|
||||
ServerLevel world = ((CarpetContext) c).s.getLevel();
|
||||
ServerLevel world = ((CarpetContext) c).level();
|
||||
Long2ObjectOpenHashMap<SortedArraySet<Ticket<?>>> levelTickets = (
|
||||
(ChunkTicketManagerInterface) ((ServerChunkManagerInterface) world.getChunkSource())
|
||||
.getCMTicketManager()
|
||||
@@ -659,14 +659,14 @@ public class WorldAccess {
|
||||
expression.addContextFunction("update", -1, (c, t, lv) ->
|
||||
booleanStateTest(c, "update", lv, (s, p) ->
|
||||
{
|
||||
((CarpetContext) c).s.getLevel().neighborChanged(p, s.getBlock(), p);
|
||||
((CarpetContext) c).level().neighborChanged(p, s.getBlock(), p);
|
||||
return true;
|
||||
}));
|
||||
|
||||
expression.addContextFunction("block_tick", -1, (c, t, lv) ->
|
||||
booleanStateTest(c, "block_tick", lv, (s, p) ->
|
||||
{
|
||||
ServerLevel w = ((CarpetContext)c).s.getLevel();
|
||||
ServerLevel w = ((CarpetContext)c).level();
|
||||
s.randomTick(w, p, w.random);
|
||||
return true;
|
||||
}));
|
||||
@@ -674,7 +674,7 @@ public class WorldAccess {
|
||||
expression.addContextFunction("random_tick", -1, (c, t, lv) ->
|
||||
booleanStateTest(c, "random_tick", lv, (s, p) ->
|
||||
{
|
||||
ServerLevel w = ((CarpetContext)c).s.getLevel();
|
||||
ServerLevel w = ((CarpetContext)c).level();
|
||||
if (s.isRandomlyTicking() || s.getFluidState().isRandomlyTicking())
|
||||
s.randomTick(w, p, w.random);
|
||||
return true;
|
||||
@@ -686,7 +686,7 @@ public class WorldAccess {
|
||||
boolean previous = CarpetSettings.impendingFillSkipUpdates.get();
|
||||
if (previous) return lv.get(0);
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
((CarpetContext)c).s.getServer().executeBlocking( () ->
|
||||
((CarpetContext)c).server().executeBlocking( () ->
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -704,7 +704,7 @@ public class WorldAccess {
|
||||
expression.addContextFunction("set", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockArgument targetLocator = BlockArgument.findIn(cc, lv, 0);
|
||||
BlockArgument sourceLocator = BlockArgument.findIn(cc, lv, targetLocator.offset, true);
|
||||
BlockState sourceBlockState = sourceLocator.block.getBlockState();
|
||||
@@ -775,7 +775,7 @@ public class WorldAccess {
|
||||
BlockState finalSourceBlockState = sourceBlockState;
|
||||
BlockPos targetPos = targetLocator.block.getPos();
|
||||
Boolean[] result = new Boolean[]{true};
|
||||
cc.s.getServer().executeBlocking( () ->
|
||||
cc.server().executeBlocking( () ->
|
||||
{
|
||||
Clearable.tryClear(world.getBlockEntity(targetPos));
|
||||
boolean success = world.setBlock(targetPos, finalSourceBlockState, 2);
|
||||
@@ -802,7 +802,7 @@ public class WorldAccess {
|
||||
expression.addContextFunction("destroy", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
BlockState state = locator.block.getBlockState();
|
||||
if (state.isAir()) return Value.FALSE;
|
||||
@@ -901,7 +901,7 @@ public class WorldAccess {
|
||||
if (lv.size()<2)
|
||||
throw new InternalExpressionException("'harvest' takes at least 2 parameters: entity and block, or position, to harvest");
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Level world = cc.s.getLevel();
|
||||
Level world = cc.level();
|
||||
Value entityValue = lv.get(0);
|
||||
if (!(entityValue instanceof EntityValue))
|
||||
return Value.FALSE;
|
||||
@@ -987,7 +987,7 @@ public class WorldAccess {
|
||||
float thePowah = powah;
|
||||
|
||||
// copy of ServerWorld.createExplosion #TRACK#
|
||||
Explosion explosion = new Explosion(cc.s.getLevel(), source, null, null, pos.x, pos.y, pos.z, powah, createFire, mode){
|
||||
Explosion explosion = new Explosion(cc.level(), source, null, null, pos.x, pos.y, pos.z, powah, createFire, mode){
|
||||
@Override
|
||||
public @Nullable LivingEntity getIndirectSourceEntity() {
|
||||
return theAttacker;
|
||||
@@ -996,7 +996,7 @@ public class WorldAccess {
|
||||
explosion.explode();
|
||||
explosion.finalizeExplosion(false);
|
||||
if (mode == Explosion.BlockInteraction.KEEP) explosion.clearToBlow();
|
||||
cc.s.getLevel().players().forEach(spe -> {
|
||||
cc.level().players().forEach(spe -> {
|
||||
if (spe.distanceToSqr(pos) < 4096.0D)
|
||||
spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe)));
|
||||
});
|
||||
@@ -1011,7 +1011,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
String itemString = lv.get(0).getString();
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
ItemInput stackArg = NBTSerializableValue.parseItem(itemString, cc.s.registryAccess());
|
||||
ItemInput stackArg = NBTSerializableValue.parseItem(itemString, cc.registryAccess());
|
||||
BlockPos where = new BlockPos(locator.vec);
|
||||
String facing;
|
||||
if (lv.size() > locator.offset) {
|
||||
@@ -1027,7 +1027,7 @@ public class WorldAccess {
|
||||
BlockValue.PlacementContext ctx;
|
||||
try
|
||||
{
|
||||
ctx = BlockValue.PlacementContext.from(cc.s.getLevel(), where, facing, sneakPlace, stackArg.createItemStack(1, false));
|
||||
ctx = BlockValue.PlacementContext.from(cc.level(), where, facing, sneakPlace, stackArg.createItemStack(1, false));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -1049,11 +1049,12 @@ public class WorldAccess {
|
||||
BlockState placementState = blockItem.getBlock().getStateForPlacement(ctx);
|
||||
if (placementState != null)
|
||||
{
|
||||
if (placementState.canSurvive(cc.s.getLevel(), where))
|
||||
final Level level = ctx.getLevel();
|
||||
if (placementState.canSurvive(level, where))
|
||||
{
|
||||
cc.s.getLevel().setBlock(where, placementState, 2);
|
||||
level.setBlock(where, placementState, 2);
|
||||
SoundType blockSoundGroup = placementState.getSoundType();
|
||||
cc.s.getLevel().playSound(null, where, blockSoundGroup.getPlaceSound(), SoundSource.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
|
||||
level.playSound(null, where, blockSoundGroup.getPlaceSound(), SoundSource.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
|
||||
return Value.TRUE;
|
||||
}
|
||||
}
|
||||
@@ -1063,7 +1064,7 @@ public class WorldAccess {
|
||||
|
||||
expression.addContextFunction("blocks_movement", -1, (c, t, lv) ->
|
||||
booleanStateTest(c, "blocks_movement", lv, (s, p) ->
|
||||
!s.isPathfindable(((CarpetContext) c).s.getLevel(), p, PathComputationType.LAND)));
|
||||
!s.isPathfindable(((CarpetContext) c).level(), p, PathComputationType.LAND)));
|
||||
|
||||
expression.addContextFunction("block_sound", -1, (c, t, lv) ->
|
||||
stateStringQuery(c, "block_sound", lv, (s, p) ->
|
||||
@@ -1075,7 +1076,7 @@ public class WorldAccess {
|
||||
|
||||
expression.addContextFunction("map_colour", -1, (c, t, lv) ->
|
||||
stateStringQuery(c, "map_colour", lv, (s, p) ->
|
||||
BlockInfo.mapColourName.get(s.getMapColor(((CarpetContext)c).s.getLevel(), p))));
|
||||
BlockInfo.mapColourName.get(s.getMapColor(((CarpetContext)c).level(), p))));
|
||||
|
||||
|
||||
// Deprecated for block_state()
|
||||
@@ -1135,7 +1136,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ResourceLocation tag = InputValidator.identifierOf(lv.get(0).getString());
|
||||
|
||||
Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registries.BLOCK);
|
||||
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
||||
Optional<HolderSet.Named<Block>> tagset = blocks.getTag(TagKey.create(Registries.BLOCK, tag));
|
||||
if (tagset.isEmpty()) return Value.NULL;
|
||||
return ListValue.wrap(tagset.get().stream().map(b -> ValueConversions.of(blocks.getKey(b.value()))).collect(Collectors.toList()));
|
||||
@@ -1144,7 +1145,7 @@ public class WorldAccess {
|
||||
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registries.BLOCK);
|
||||
Registry<Block> blocks = cc.registry(Registries.BLOCK);
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||
@@ -1178,7 +1179,7 @@ public class WorldAccess {
|
||||
|
||||
expression.addContextFunction("biome", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(world.registryAccess().registryOrThrow(Registries.BIOME).keySet().stream().map(ValueConversions::of));
|
||||
|
||||
@@ -1215,7 +1216,7 @@ public class WorldAccess {
|
||||
Climate.quantizeCoord(numberGetOrThrow(weirdness))
|
||||
);
|
||||
biome = mnbs.getNoiseBiome(point).value();
|
||||
ResourceLocation biomeId = cc.s.getServer().registryAccess().registryOrThrow(Registries.BIOME).getKey(biome);
|
||||
ResourceLocation biomeId = cc.registry(Registries.BIOME).getKey(biome);
|
||||
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
}
|
||||
|
||||
@@ -1234,7 +1235,7 @@ public class WorldAccess {
|
||||
// in locatebiome
|
||||
if (locator.offset == lv.size())
|
||||
{
|
||||
ResourceLocation biomeId = cc.s.getServer().registryAccess().registryOrThrow(Registries.BIOME).getKey(biome);
|
||||
ResourceLocation biomeId = cc.registry(Registries.BIOME).getKey(biome);
|
||||
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
}
|
||||
String biomeFeature = lv.get(locator.offset).getString();
|
||||
@@ -1252,7 +1253,7 @@ public class WorldAccess {
|
||||
throw new InternalExpressionException("'set_biome' needs a biome name as an argument");
|
||||
String biomeName = lv.get(locator.offset+0).getString();
|
||||
// from locatebiome command code
|
||||
Holder<Biome> biome = cc.s.getServer().registryAccess().registryOrThrow(Registries.BIOME).getHolder(ResourceKey.create(Registries.BIOME, InputValidator.identifierOf(biomeName)))
|
||||
Holder<Biome> biome = cc.registry(Registries.BIOME).getHolder(ResourceKey.create(Registries.BIOME, InputValidator.identifierOf(biomeName)))
|
||||
.orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
|
||||
|
||||
|
||||
@@ -1261,7 +1262,7 @@ public class WorldAccess {
|
||||
{
|
||||
doImmediateUpdate = lv.get(locator.offset+1).getBoolean();
|
||||
}
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
ChunkAccess chunk = world.getChunk(pos); // getting level chunk instead of protochunk with biomes
|
||||
int biomeX = QuartPos.fromBlock(pos.getX());
|
||||
@@ -1285,18 +1286,18 @@ public class WorldAccess {
|
||||
expression.addContextFunction("reload_chunk", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockPos pos = BlockArgument.findIn(cc, lv, 0).block.getPos();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
cc.s.getServer().executeBlocking( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
ServerLevel world = cc.level();
|
||||
cc.server().executeBlocking( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
expression.addContextFunction("structure_references", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
Map<Structure, LongSet> references = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_REFERENCES).getAllReferences();
|
||||
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registries.STRUCTURE);
|
||||
Registry<Structure> reg = cc.registry(Registries.STRUCTURE);
|
||||
if (lv.size() == locator.offset)
|
||||
return ListValue.wrap(references.entrySet().stream().
|
||||
filter(e -> e.getValue()!= null && !e.getValue().isEmpty()).
|
||||
@@ -1318,7 +1319,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
|
||||
// well, because
|
||||
BooYah(world);
|
||||
@@ -1327,7 +1328,7 @@ public class WorldAccess {
|
||||
final List<Structure> structure = new ArrayList<>();
|
||||
boolean needSize = false;
|
||||
boolean singleOutput = false;
|
||||
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registries.STRUCTURE);
|
||||
Registry<Structure> reg = cc.registry(Registries.STRUCTURE);
|
||||
if (lv.size() > locator.offset)
|
||||
{
|
||||
Value requested = lv.get(locator.offset+0);
|
||||
@@ -1398,10 +1399,10 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
Map<Structure, StructureStart> structures = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4, ChunkStatus.STRUCTURE_STARTS).getAllStarts();
|
||||
Registry<Structure> reg = cc.s.getServer().registryAccess().registryOrThrow(Registries.STRUCTURE);
|
||||
Registry<Structure> reg = cc.registry(Registries.STRUCTURE);
|
||||
if (lv.size() == locator.offset)
|
||||
{
|
||||
Map<Value, Value> structureList = new HashMap<>();
|
||||
@@ -1427,7 +1428,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
|
||||
if (lv.size() == locator.offset)
|
||||
@@ -1438,12 +1439,12 @@ public class WorldAccess {
|
||||
// good 'ol pointer
|
||||
Value[] result = new Value[]{Value.NULL};
|
||||
// technically a world modification. Even if we could let it slide, we will still park it
|
||||
((CarpetContext) c).s.getServer().executeBlocking(() ->
|
||||
((CarpetContext) c).server().executeBlocking(() ->
|
||||
{
|
||||
Map<Structure, StructureStart> structures = world.getChunk(pos).getAllStarts();
|
||||
if (lv.size() == locator.offset + 1)
|
||||
{
|
||||
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
|
||||
Boolean res = FeatureGenerator.plopGrid(configuredStructure, ((CarpetContext) c).level(), locator.block.getPos());
|
||||
if (res == null) return;
|
||||
result[0] = res?Value.TRUE:Value.FALSE;
|
||||
return;
|
||||
@@ -1553,11 +1554,11 @@ public class WorldAccess {
|
||||
}
|
||||
|
||||
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
ServerLevel world = cc.level();
|
||||
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
|
||||
((CarpetContext)c).s.getServer().executeBlocking( () ->
|
||||
((CarpetContext)c).server().executeBlocking( () ->
|
||||
{
|
||||
Map<String, Integer> report = ((ThreadedAnvilChunkStorageInterface) world.getChunkSource().chunkMap).regenerateChunkRegion(requestedChunks);
|
||||
/*for (ChunkPos chpos: requestedChunks) // needed in 1.16 only
|
||||
@@ -1580,7 +1581,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
BlockPos pos = locator.block.getPos();
|
||||
return new NumericValue(cc.s.getLevel().getChunk(pos).getInhabitedTime());
|
||||
return new NumericValue(cc.level().getChunk(pos).getInhabitedTime());
|
||||
});
|
||||
|
||||
expression.addContextFunction("spawn_potential", -1, (c, t, lv) ->
|
||||
@@ -1591,7 +1592,7 @@ public class WorldAccess {
|
||||
double required_charge = 1;
|
||||
if (lv.size() > locator.offset)
|
||||
required_charge = NumericValue.asNumber(lv.get(locator.offset)).getDouble();
|
||||
NaturalSpawner.SpawnState charger = cc.s.getLevel().getChunkSource().getLastSpawnState();
|
||||
NaturalSpawner.SpawnState charger = cc.level().getChunkSource().getLastSpawnState();
|
||||
if (charger == null) return Value.NULL;
|
||||
return new NumericValue(
|
||||
((SpawnHelperInnerInterface)charger).getPotentialCalculator().
|
||||
@@ -1613,11 +1614,11 @@ public class WorldAccess {
|
||||
// due to types we will wing it:
|
||||
ChunkPos target = new ChunkPos(pos);
|
||||
if (ticket == TicketType.PORTAL) // portal
|
||||
cc.s.getLevel().getChunkSource().addRegionTicket(TicketType.PORTAL, target, radius, pos);
|
||||
cc.level().getChunkSource().addRegionTicket(TicketType.PORTAL, target, radius, pos);
|
||||
else if (ticket == TicketType.POST_TELEPORT) // post teleport
|
||||
cc.s.getLevel().getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, target, radius, 1);
|
||||
cc.level().getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, target, radius, 1);
|
||||
else
|
||||
cc.s.getLevel().getChunkSource().addRegionTicket(TicketType.UNKNOWN, target, radius, target);
|
||||
cc.level().getChunkSource().addRegionTicket(TicketType.UNKNOWN, target, radius, target);
|
||||
return new NumericValue(ticket.timeout());
|
||||
});
|
||||
|
||||
|
||||
@@ -60,23 +60,25 @@ public class BlockArgument extends Argument
|
||||
}
|
||||
if (acceptString && v1 instanceof StringValue)
|
||||
{
|
||||
return new BlockArgument(BlockValue.fromString(v1.getString(), c.s.registryAccess()), 1 + offset);
|
||||
return new BlockArgument(BlockValue.fromString(v1.getString(), c.registryAccess()), 1 + offset);
|
||||
}
|
||||
if (v1 instanceof BlockValue)
|
||||
{
|
||||
return new BlockArgument(((BlockValue) v1), 1 + offset);
|
||||
}
|
||||
final BlockPos pos = c.origin();
|
||||
if (v1 instanceof ListValue)
|
||||
{
|
||||
List<Value> args = ((ListValue) v1).getItems();
|
||||
int xpos = (int) NumericValue.asNumber(args.get(0)).getLong();
|
||||
int ypos = (int) NumericValue.asNumber(args.get(1)).getLong();
|
||||
int zpos = (int) NumericValue.asNumber(args.get(2)).getLong();
|
||||
|
||||
return new BlockArgument(
|
||||
new BlockValue(
|
||||
null,
|
||||
c.s.getLevel(),
|
||||
new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos)
|
||||
c.level(),
|
||||
new BlockPos(pos.getX() + xpos, pos.getY() + ypos, pos.getZ() + zpos)
|
||||
),
|
||||
1 + offset);
|
||||
}
|
||||
@@ -86,8 +88,8 @@ public class BlockArgument extends Argument
|
||||
return new BlockArgument(
|
||||
new BlockValue(
|
||||
null,
|
||||
c.s.getLevel(),
|
||||
new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos)
|
||||
c.level(),
|
||||
new BlockPos(pos.getX() + xpos, pos.getY() + ypos, pos.getZ() + zpos)
|
||||
),
|
||||
3 + offset
|
||||
);
|
||||
|
||||
@@ -48,46 +48,46 @@ public class SystemInfo {
|
||||
put("app_scope", c -> StringValue.of((c.host).isPerUser()?"player":"global"));
|
||||
put("app_players", c -> ListValue.wrap(c.host.getUserList().stream().map(StringValue::new).collect(Collectors.toList())));
|
||||
|
||||
put("world_name", c -> new StringValue(c.s.getServer().getWorldData().getLevelName()));
|
||||
put("world_seed", c -> new NumericValue(c.s.getLevel().getSeed()));
|
||||
put("server_motd", c -> StringValue.of(c.s.getServer().getMotd()));
|
||||
put("world_path", c -> StringValue.of(c.s.getServer().getWorldPath(LevelResource.ROOT).toString()));
|
||||
put("world_name", c -> new StringValue(c.server().getWorldData().getLevelName()));
|
||||
put("world_seed", c -> new NumericValue(c.level().getSeed()));
|
||||
put("server_motd", c -> StringValue.of(c.server().getMotd()));
|
||||
put("world_path", c -> StringValue.of(c.server().getWorldPath(LevelResource.ROOT).toString()));
|
||||
put("world_folder", c -> {
|
||||
Path serverPath = c.s.getServer().getWorldPath(LevelResource.ROOT);
|
||||
Path serverPath = c.server().getWorldPath(LevelResource.ROOT);
|
||||
int nodeCount = serverPath.getNameCount();
|
||||
if (nodeCount < 2) return Value.NULL;
|
||||
String tlf = serverPath.getName(nodeCount-2).toString();
|
||||
return StringValue.of(tlf);
|
||||
});
|
||||
put("world_dimensions", c -> ListValue.wrap(c.s.getServer().levelKeys().stream().map(k -> ValueConversions.of(k.location())).collect(Collectors.toList())));
|
||||
put("world_dimensions", c -> ListValue.wrap(c.server().levelKeys().stream().map(k -> ValueConversions.of(k.location())).collect(Collectors.toList())));
|
||||
put("world_spawn_point", c -> {
|
||||
LevelData prop = c.s.getServer().overworld().getLevelData();
|
||||
LevelData prop = c.server().overworld().getLevelData();
|
||||
return ListValue.of(NumericValue.of(prop.getXSpawn()), NumericValue.of(prop.getYSpawn()), NumericValue.of(prop.getZSpawn()));
|
||||
});
|
||||
|
||||
put("world_bottom", c-> new NumericValue(c.s.getLevel().getMinBuildHeight()));
|
||||
put("world_bottom", c-> new NumericValue(c.level().getMinBuildHeight()));
|
||||
|
||||
put("world_top", c-> new NumericValue(c.s.getLevel().getMaxBuildHeight()));
|
||||
put("world_top", c-> new NumericValue(c.level().getMaxBuildHeight()));
|
||||
|
||||
put("world_center", c-> {
|
||||
WorldBorder worldBorder = c.s.getLevel().getWorldBorder();
|
||||
WorldBorder worldBorder = c.level().getWorldBorder();
|
||||
return ListValue.fromTriple(worldBorder.getCenterX(), 0, worldBorder.getCenterZ());
|
||||
});
|
||||
|
||||
put("world_size", c -> new NumericValue(c.s.getLevel().getWorldBorder().getSize() / 2));
|
||||
put("world_size", c -> new NumericValue(c.level().getWorldBorder().getSize() / 2));
|
||||
|
||||
put("world_max_size", c-> new NumericValue( c.s.getLevel().getWorldBorder().getAbsoluteMaxSize()));
|
||||
put("world_max_size", c-> new NumericValue( c.level().getWorldBorder().getAbsoluteMaxSize()));
|
||||
|
||||
put("world_time", c -> new NumericValue(c.s.getLevel().getGameTime()));
|
||||
put("world_time", c -> new NumericValue(c.level().getGameTime()));
|
||||
|
||||
put("game_difficulty", c -> StringValue.of(c.s.getServer().getWorldData().getDifficulty().getKey()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.s.getServer().getWorldData().isHardcore()));
|
||||
put("game_storage_format", c -> StringValue.of(c.s.getServer().getWorldData().getStorageVersionName(c.s.getServer().getWorldData().getVersion())));
|
||||
put("game_default_gamemode", c -> StringValue.of(c.s.getServer().getDefaultGameType().getName()));
|
||||
put("game_max_players", c -> new NumericValue(c.s.getServer().getMaxPlayers()));
|
||||
put("game_view_distance", c -> new NumericValue(c.s.getServer().getPlayerList().getViewDistance()));
|
||||
put("game_mod_name", c -> StringValue.of(c.s.getServer().getServerModName()));
|
||||
put("game_version", c -> StringValue.of(c.s.getServer().getServerVersion()));
|
||||
put("game_difficulty", c -> StringValue.of(c.server().getWorldData().getDifficulty().getKey()));
|
||||
put("game_hardcore", c -> BooleanValue.of(c.server().getWorldData().isHardcore()));
|
||||
put("game_storage_format", c -> StringValue.of(c.server().getWorldData().getStorageVersionName(c.server().getWorldData().getVersion())));
|
||||
put("game_default_gamemode", c -> StringValue.of(c.server().getDefaultGameType().getName()));
|
||||
put("game_max_players", c -> new NumericValue(c.server().getMaxPlayers()));
|
||||
put("game_view_distance", c -> new NumericValue(c.server().getPlayerList().getViewDistance()));
|
||||
put("game_mod_name", c -> StringValue.of(c.server().getServerModName()));
|
||||
put("game_version", c -> StringValue.of(c.server().getServerVersion()));
|
||||
put("game_target", c -> StringValue.of(CarpetSettings.releaseTarget));
|
||||
put("game_protocol", c -> NumericValue.of(SharedConstants.getProtocolVersion()));
|
||||
put("game_major_target", c -> {
|
||||
@@ -102,11 +102,11 @@ public class SystemInfo {
|
||||
put("game_data_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getWorldVersion()));
|
||||
put("game_pack_version", c->NumericValue.of(SharedConstants.getCurrentVersion().getPackVersion(PackType.DATA)));
|
||||
|
||||
put("server_ip", c -> StringValue.of(c.s.getServer().getLocalIp()));
|
||||
put("server_whitelisted", c -> BooleanValue.of(c.s.getServer().isEnforceWhitelist()));
|
||||
put("server_ip", c -> StringValue.of(c.server().getLocalIp()));
|
||||
put("server_whitelisted", c -> BooleanValue.of(c.server().isEnforceWhitelist()));
|
||||
put("server_whitelist", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getServer().getPlayerList().getWhiteListNames())
|
||||
for (String s: c.server().getPlayerList().getWhiteListNames())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class SystemInfo {
|
||||
});
|
||||
put("server_banned_players", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getServer().getPlayerList().getBans().getUserList())
|
||||
for (String s: c.server().getPlayerList().getBans().getUserList())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class SystemInfo {
|
||||
});
|
||||
put("server_banned_ips", c -> {
|
||||
MapValue whitelist = new MapValue(Collections.emptyList());
|
||||
for (String s: c.s.getServer().getPlayerList().getIpBans().getUserList())
|
||||
for (String s: c.server().getPlayerList().getIpBans().getUserList())
|
||||
{
|
||||
whitelist.append(StringValue.of(s));
|
||||
}
|
||||
@@ -138,9 +138,9 @@ public class SystemInfo {
|
||||
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().getTickCount()-1;
|
||||
int currentReportedTick = c.server().getTickCount()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = c.s.getServer().tickTimes;
|
||||
final long[] tickArray = c.server().tickTimes;
|
||||
for (int i=currentReportedTick+100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0));
|
||||
@@ -192,7 +192,7 @@ public class SystemInfo {
|
||||
});
|
||||
put("world_gamerules", c->{
|
||||
Map<Value, Value> rules = new HashMap<>();
|
||||
final GameRules gameRules = c.s.getLevel().getGameRules();
|
||||
final GameRules gameRules = c.level().getGameRules();
|
||||
GameRules.visitGameRuleTypes(new GameRules.GameRuleTypeVisitor() {
|
||||
@Override
|
||||
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
|
||||
@@ -202,11 +202,11 @@ public class SystemInfo {
|
||||
return MapValue.wrap(rules);
|
||||
});
|
||||
|
||||
put("source_entity", c -> EntityValue.of(c.s.getEntity()));
|
||||
put("source_position", c -> ValueConversions.of(c.s.getPosition()));
|
||||
put("source_dimension", c -> ValueConversions.of(c.s.getLevel()));
|
||||
put("source_entity", c -> EntityValue.of(c.source().getEntity()));
|
||||
put("source_position", c -> ValueConversions.of(c.source().getPosition()));
|
||||
put("source_dimension", c -> ValueConversions.of(c.level()));
|
||||
put("source_rotation", c -> {
|
||||
Vec2 rotation = c.s.getRotation();
|
||||
Vec2 rotation = c.source().getRotation();
|
||||
return ListValue.of(new NumericValue(rotation.x), new NumericValue(rotation.y));
|
||||
});
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class BlockValue extends Value
|
||||
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
|
||||
{
|
||||
BlockPos pos = locateBlockPos(c, x,y,z);
|
||||
return new BlockValue(null, c.s.getLevel(), pos);
|
||||
return new BlockValue(null, c.level(), pos);
|
||||
}
|
||||
|
||||
private static final Map<String, BlockValue> bvCache= new HashMap<>();
|
||||
@@ -82,7 +82,8 @@ public class BlockValue extends Value
|
||||
|
||||
public static BlockPos locateBlockPos(CarpetContext c, int xpos, int ypos, int zpos)
|
||||
{
|
||||
return new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos);
|
||||
final BlockPos pos = c.origin();
|
||||
return new BlockPos(pos.getX() + xpos, pos.getY() + ypos, pos.getZ() + zpos);
|
||||
}
|
||||
|
||||
public BlockState getBlockState()
|
||||
|
||||
@@ -208,7 +208,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
if (strVal.equals("enderchest"))
|
||||
{
|
||||
Value v2 = params.get(1 + offset);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(c.s.getServer(), v2);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(c.server(), v2);
|
||||
if (player == null) throw new InternalExpressionException("enderchest inventory requires player argument");
|
||||
return new InventoryLocator(player, player.blockPosition(), player.getEnderChestInventory(), offset + 2, true);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
}
|
||||
boolean isEnder = strVal.startsWith("enderchest_");
|
||||
if (isEnder) strVal = strVal.substring(11); // len("enderchest_")
|
||||
ServerPlayer player = c.s.getServer().getPlayerList().getPlayerByName(strVal);
|
||||
ServerPlayer player = c.server().getPlayerList().getPlayerByName(strVal);
|
||||
if (player == null) throw new InternalExpressionException("String description of an inventory should either denote a player or player's enderchest");
|
||||
return new InventoryLocator(
|
||||
player,
|
||||
@@ -251,7 +251,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
BlockPos pos = ((BlockValue) v1).getPos();
|
||||
if (pos == null)
|
||||
throw new InternalExpressionException("Block to access inventory needs to be positioned in the world");
|
||||
Container inv = getInventoryAt(c.s.getLevel(), pos);
|
||||
Container inv = getInventoryAt(c.level(), pos);
|
||||
if (inv == null)
|
||||
return null;
|
||||
return new InventoryLocator(pos, pos, inv, offset+1);
|
||||
@@ -263,7 +263,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
NumericValue.asNumber(args.get(0)).getDouble(),
|
||||
NumericValue.asNumber(args.get(1)).getDouble(),
|
||||
NumericValue.asNumber(args.get(2)).getDouble());
|
||||
Container inv = getInventoryAt(c.s.getLevel(), pos);
|
||||
Container inv = getInventoryAt(c.level(), pos);
|
||||
if (inv == null)
|
||||
return null;
|
||||
return new InventoryLocator(pos, pos, inv, offset+1);
|
||||
@@ -277,7 +277,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
NumericValue.asNumber(v1).getDouble(),
|
||||
NumericValue.asNumber(params.get(1 + offset)).getDouble(),
|
||||
NumericValue.asNumber(params.get(2 + offset)).getDouble());
|
||||
Container inv = getInventoryAt(c.s.getLevel(), pos);
|
||||
Container inv = getInventoryAt(c.level(), pos);
|
||||
if (inv == null)
|
||||
return null;
|
||||
return new InventoryLocator(pos, pos, inv, offset + 3);
|
||||
|
||||
Reference in new issue
Block a user