Merge branch '1.17'
This commit is contained in:
commit
af368a159d
173 files changed
+2214
-1462
No files matched your search
@@ -50,14 +50,21 @@ import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.decoration.ArmorStandEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.ClearTitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerListHeaderS2CPacket;
|
||||
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
//import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||
import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.resource.DataPackSettings;
|
||||
import net.minecraft.resource.ReloadableResourceManagerImpl;
|
||||
@@ -120,6 +127,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -190,7 +198,7 @@ public class Auxiliary {
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (lv.size() == 0) return ListValue.wrap(Registry.PARTICLE_TYPE.getIds().stream().map(ValueConversions::of));
|
||||
MinecraftServer ms = cc.s.getMinecraftServer();
|
||||
MinecraftServer ms = cc.s.getServer();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
String particleName = lv.get(0).getString();
|
||||
@@ -262,7 +270,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,7 +310,7 @@ public class Auxiliary {
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,14 +437,14 @@ public class Auxiliary {
|
||||
for (Entity e : cc.s.getWorld().getEntitiesByType(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
{
|
||||
total ++;
|
||||
e.remove();
|
||||
e.discard(); // discard // remove();
|
||||
}
|
||||
return new NumericValue(total);
|
||||
});
|
||||
|
||||
expression.addUnaryFunction("nbt", NBTSerializableValue::fromValue);
|
||||
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(StringTag.escape(v.getString())));
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(NbtString.escape(v.getString())));
|
||||
|
||||
expression.addUnaryFunction("parse_nbt", v -> {
|
||||
if (v instanceof NBTSerializableValue) return ((NBTSerializableValue) v).toValue();
|
||||
@@ -450,8 +458,8 @@ public class Auxiliary {
|
||||
if (numParam != 2 && numParam != 3) throw new InternalExpressionException("'tag_matches' requires 2 or 3 arguments");
|
||||
if (lv.get(1).isNull()) return Value.TRUE;
|
||||
if (lv.get(0).isNull()) return Value.FALSE;
|
||||
Tag source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
Tag match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
NbtElement source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
NbtElement match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
return BooleanValue.of(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
||||
});
|
||||
|
||||
@@ -460,7 +468,7 @@ public class Auxiliary {
|
||||
if (argSize==0 || argSize > 2) throw new InternalExpressionException("'encode_nbt' requires 1 or 2 parameters");
|
||||
Value v = lv.get(0);
|
||||
boolean force = (argSize > 1) && lv.get(1).getBoolean();
|
||||
Tag tag;
|
||||
NbtElement tag;
|
||||
try
|
||||
{
|
||||
tag = v.toTag(force);
|
||||
@@ -477,7 +485,7 @@ public class Auxiliary {
|
||||
{
|
||||
if (lv.size() == 0 || lv.size() > 2) throw new InternalExpressionException("'print' takes one or two arguments");
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
MinecraftServer server = s.getMinecraftServer();
|
||||
MinecraftServer server = s.getServer();
|
||||
Value res = lv.get(0);
|
||||
List<ServerPlayerEntity> targets = null;
|
||||
if (lv.size() == 2)
|
||||
@@ -508,38 +516,51 @@ 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.getMinecraftServer();
|
||||
MinecraftServer server = ((CarpetContext)c).s.getServer();
|
||||
Stream<ServerPlayerEntity> targets = ((ListValue) pVal).getItems().stream().map(v ->
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, v);
|
||||
if (player == null) throw new InternalExpressionException("'display_title' requires a valid online player or a list of players as first argument. "+v.getString()+" is not a player.");
|
||||
return player;
|
||||
});
|
||||
TitleS2CPacket.Action action;
|
||||
Function<Text, Packet<?>> packetGetter = null;
|
||||
//TitleS2CPacket.Action action;
|
||||
String actionString = lv.get(1).getString().toLowerCase(Locale.ROOT);
|
||||
switch (actionString)
|
||||
{
|
||||
case "title":
|
||||
action = Action.TITLE;
|
||||
packetGetter = TitleS2CPacket::new;
|
||||
//action = Action.TITLE;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
break;
|
||||
case "subtitle":
|
||||
action = Action.SUBTITLE;
|
||||
packetGetter = SubtitleS2CPacket::new;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
//action = Action.SUBTITLE;
|
||||
break;
|
||||
case "actionbar":
|
||||
action = Action.ACTIONBAR;
|
||||
packetGetter = OverlayMessageS2CPacket::new;
|
||||
if (lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
|
||||
//action = Action.ACTIONBAR;
|
||||
break;
|
||||
case "clear":
|
||||
action = Action.CLEAR;
|
||||
packetGetter = (x) -> new ClearTitleS2CPacket(true); // resetting default fade
|
||||
//action = Action.CLEAR;
|
||||
break;
|
||||
case "player_list_header":
|
||||
case "player_list_footer":
|
||||
action = null;
|
||||
break;
|
||||
default:
|
||||
throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'player_list_header', 'player_list_footer' or 'clear' as second argument");
|
||||
}
|
||||
if (action != Action.CLEAR && lv.size() < 3)
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
//if (action != Action.CLEAR && lv.size() < 3)
|
||||
// throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
Text title;
|
||||
boolean soundsTrue = false;
|
||||
if (lv.size() > 2)
|
||||
@@ -549,14 +570,14 @@ public class Auxiliary {
|
||||
soundsTrue = pVal.getBoolean();
|
||||
}
|
||||
else title = null; // Will never happen, just to make lambda happy
|
||||
if (action == null)
|
||||
if (packetGetter == null)
|
||||
{
|
||||
Map<String, BaseText> map;
|
||||
if (actionString.equals("player_list_header"))
|
||||
map = HUDController.scarpet_headers;
|
||||
else
|
||||
map = HUDController.scarpet_footers;
|
||||
|
||||
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
List<ServerPlayerEntity> targetList = targets.collect(Collectors.toList());
|
||||
if (!soundsTrue) // null or empty string
|
||||
@@ -569,21 +590,23 @@ public class Auxiliary {
|
||||
map.put(target.getEntityName(), (BaseText) title);
|
||||
total.getAndIncrement();
|
||||
});
|
||||
HUDController.update_hud(((CarpetContext)c).s.getMinecraftServer(), targetList);
|
||||
HUDController.update_hud(((CarpetContext)c).s.getServer(), targetList);
|
||||
return NumericValue.of(total.get());
|
||||
}
|
||||
TitleS2CPacket timesPacket;
|
||||
TitleFadeS2CPacket timesPacket; // TimesPacket
|
||||
if (lv.size() > 3)
|
||||
{
|
||||
if (lv.size() != 6) throw new InternalExpressionException("'display_title' needs all fade-in, stay and fade-out times");
|
||||
int in = NumericValue.asNumber(lv.get(3),"fade in for display_title" ).getInt();
|
||||
int stay = NumericValue.asNumber(lv.get(4),"stay for display_title" ).getInt();
|
||||
int out = NumericValue.asNumber(lv.get(5),"fade out for display_title" ).getInt();
|
||||
timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
|
||||
timesPacket = new TitleFadeS2CPacket(in, stay, out);
|
||||
//timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
|
||||
}
|
||||
else timesPacket = null;
|
||||
|
||||
TitleS2CPacket packet = new TitleS2CPacket(action, title);
|
||||
Packet<?> packet = packetGetter.apply(title);
|
||||
//TitleS2CPacket packet = new TitleS2CPacket(action, title);
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
targets.forEach(p -> {
|
||||
if (timesPacket != null) p.networkHandler.sendPacket(timesPacket);
|
||||
@@ -607,7 +630,7 @@ public class Auxiliary {
|
||||
{
|
||||
Text[] error = {null};
|
||||
List<Text> output = new ArrayList<>();
|
||||
Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute(
|
||||
Value retval = new NumericValue(s.getServer().getCommandManager().execute(
|
||||
new SnoopyCommandSource(s, error, output),
|
||||
lv.get(0).getString())
|
||||
);
|
||||
@@ -626,15 +649,15 @@ public class Auxiliary {
|
||||
expression.addContextFunction("save", 0, (c, t, lv) ->
|
||||
{
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
s.getMinecraftServer().getPlayerManager().saveAllPlayerData();
|
||||
s.getMinecraftServer().save(true,true,true);
|
||||
s.getServer().getPlayerManager().saveAllPlayerData();
|
||||
s.getServer().save(true,true,true);
|
||||
s.getWorld().getChunkManager().tick(() -> true);
|
||||
CarpetScriptServer.LOG.warn("Saved chunks");
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getMinecraftServer().getTicks()));
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTicks()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getWorld().getTime()));
|
||||
@@ -655,9 +678,9 @@ public class Auxiliary {
|
||||
{
|
||||
//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.getMinecraftServer().getTicks()-1;
|
||||
int currentReportedTick = ((CarpetContext) c).s.getServer().getTicks()-1;
|
||||
List<Value> ticks = new ArrayList<>(100);
|
||||
final long[] tickArray = ((CarpetContext) c).s.getMinecraftServer().lastTickLengths;
|
||||
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));
|
||||
@@ -669,12 +692,12 @@ public class Auxiliary {
|
||||
expression.addContextFunction("game_tick", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerCommandSource s = cc.s;
|
||||
if (!s.getMinecraftServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (!s.getServer().isOnThread()) 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.getMinecraftServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
((MinecraftServerInterface) s.getServer()).forceTick(() -> System.nanoTime() - CarpetServer.scriptServer.tickStart < 50000000L);
|
||||
if (lv.size() > 0)
|
||||
{
|
||||
long ms_total = NumericValue.asNumber(lv.get(0)).getLong();
|
||||
@@ -724,13 +747,13 @@ public class Auxiliary {
|
||||
ValueConversions.of( ((CarpetContext)c).s.getWorld()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext)c).s.getMinecraftServer().getPlayerManager().getViewDistance()));
|
||||
new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance()));
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
ServerCommandSource outerSource = ((CarpetContext)c).s;
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
World world = ValueConversions.dimFromValue(dimensionValue, outerSource.getMinecraftServer());
|
||||
World world = ValueConversions.dimFromValue(dimensionValue, outerSource.getServer());
|
||||
if (world == outerSource.getWorld()) return lv.get(1);
|
||||
ServerCommandSource innerSource = outerSource.withWorld((ServerWorld)world);
|
||||
Context newCtx = c.recreate();
|
||||
@@ -753,13 +776,13 @@ public class Auxiliary {
|
||||
ListValue.wrap(Registry.FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_features"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("structures"),
|
||||
ListValue.wrap(Registry.STRUCTURE_FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_structures"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_WORLDGEN).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
return MapValue.wrap(plopData);
|
||||
}
|
||||
@@ -768,7 +791,7 @@ 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.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).s.getWorld(), locator.block.getPos());
|
||||
|
||||
@@ -837,7 +860,7 @@ public class Auxiliary {
|
||||
Value retVal;
|
||||
if (fdesc.type == FileArgument.Type.NBT)
|
||||
{
|
||||
Tag state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
NbtElement state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
if (state == null) return Value.NULL;
|
||||
retVal = new NBTSerializableValue(state);
|
||||
}
|
||||
@@ -874,7 +897,7 @@ public class Auxiliary {
|
||||
NBTSerializableValue tagValue = (val instanceof NBTSerializableValue)
|
||||
? (NBTSerializableValue) val
|
||||
: new NBTSerializableValue(val.getString());
|
||||
Tag tag = tagValue.getTag();
|
||||
NbtElement tag = tagValue.getTag();
|
||||
success = ((CarpetScriptHost) c.host).writeTagFile(tag, fdesc);
|
||||
}
|
||||
else if (fdesc.type == FileArgument.Type.JSON)
|
||||
@@ -946,7 +969,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("statistic", 3, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getMinecraftServer(), lv.get(0));
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getServer(), lv.get(0));
|
||||
if (player == null) return Value.NULL;
|
||||
Identifier category;
|
||||
Identifier statName;
|
||||
@@ -1000,11 +1023,11 @@ 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;
|
||||
DataCommandStorage storage = cc.s.getMinecraftServer().getDataCommandStorage();
|
||||
DataCommandStorage storage = cc.s.getServer().getDataCommandStorage();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(storage.getIds().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
||||
String key = lv.get(0).getString();
|
||||
CompoundTag old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
NbtCompound old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
if (lv.size() == 2) {
|
||||
Value nbt = lv.get(1);
|
||||
NBTSerializableValue new_nbt = (nbt instanceof NBTSerializableValue) ? (NBTSerializableValue) nbt
|
||||
@@ -1019,7 +1042,7 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
String origName = lv.get(0).getString();
|
||||
String name = InputValidator.validateSimpleString(origName, true);
|
||||
MinecraftServer server = cc.s.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
for (String dpName : server.getDataPackManager().getNames())
|
||||
{
|
||||
if (dpName.equalsIgnoreCase("file/"+name+".zip") ||
|
||||
@@ -1084,7 +1107,7 @@ public class Auxiliary {
|
||||
expression.addContextFunction("enable_hidden_dimensions", 0, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
// from minecraft.server.Main.main
|
||||
MinecraftServer server = cc.s.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
LevelStorage.Session session = ((MinecraftServerInterface)server).getCMSession();
|
||||
DataPackSettings dataPackSettings = session.getDataPackSettings();
|
||||
ResourcePackManager resourcePackManager = server.getDataPackManager();
|
||||
@@ -1099,7 +1122,7 @@ public class Auxiliary {
|
||||
//not sure its needed, but doesn't seem to have a negative effect and might be used in some custom shtuff
|
||||
serverRM.loadRegistryTags();
|
||||
|
||||
RegistryOps<Tag> registryOps = RegistryOps.of(NbtOps.INSTANCE, serverRM.getResourceManager(), (DynamicRegistryManager.Impl) server.getRegistryManager());
|
||||
RegistryOps<NbtElement> registryOps = RegistryOps.of(NbtOps.INSTANCE, serverRM.getResourceManager(), (DynamicRegistryManager.Impl) server.getRegistryManager());
|
||||
SaveProperties saveProperties = session.readLevelProperties(registryOps, dataPackSettings2);
|
||||
if (saveProperties == null) return Value.NULL;
|
||||
//session.backupLevelDataFile(server.getRegistryManager(), saveProperties); // no need
|
||||
@@ -1117,7 +1140,7 @@ public class Auxiliary {
|
||||
if (!existing_worlds.containsKey(registryKey))
|
||||
{
|
||||
addeds.add(ValueConversions.of(registryKey.getValue()));
|
||||
RegistryKey<World> registryKey2 = RegistryKey.of(Registry.DIMENSION, registryKey.getValue());
|
||||
RegistryKey<World> registryKey2 = RegistryKey.of(Registry.WORLD_KEY, registryKey.getValue());
|
||||
DimensionType dimensionType3 = entry.getValue().getDimensionType();
|
||||
ChunkGenerator chunkGenerator3 = entry.getValue().getChunkGenerator();
|
||||
UnmodifiableLevelProperties unmodifiableLevelProperties = new UnmodifiableLevelProperties(saveProperties, ((ServerWorldInterface) server.getOverworld()).getWorldPropertiesCM());
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -48,7 +48,7 @@ public class Entities {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (cc.host.user != null)
|
||||
{
|
||||
ServerPlayerEntity player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(cc.host.user);
|
||||
ServerPlayerEntity player = cc.s.getServer().getPlayerManager().getPlayer(cc.host.user);
|
||||
return EntityValue.of(player);
|
||||
}
|
||||
Entity callingEntity = cc.s.getEntity();
|
||||
@@ -62,7 +62,7 @@ public class Entities {
|
||||
if ("all".equalsIgnoreCase(playerName))
|
||||
{
|
||||
retval = ListValue.wrap(
|
||||
((CarpetContext)c).s.getMinecraftServer().getPlayerManager().getPlayerList().
|
||||
((CarpetContext)c).s.getServer().getPlayerManager().getPlayerList().
|
||||
stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
}
|
||||
else if ("*".equalsIgnoreCase(playerName))
|
||||
@@ -97,7 +97,7 @@ public class Entities {
|
||||
}
|
||||
else
|
||||
{
|
||||
ServerPlayerEntity player = ((CarpetContext) c).s.getMinecraftServer().getPlayerManager().getPlayer(playerName);
|
||||
ServerPlayerEntity player = ((CarpetContext) c).s.getServer().getPlayerManager().getPlayer(playerName);
|
||||
if (player != null)
|
||||
retval = new EntityValue(player);
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class Entities {
|
||||
Vector3Argument position = Vector3Argument.findIn(lv, 1);
|
||||
if (position.fromBlock)
|
||||
position.vec = position.vec.subtract(0, 0.5, 0);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
NbtCompound tag = new NbtCompound();
|
||||
boolean hasTag = false;
|
||||
if (lv.size() > position.offset)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ public class Entities {
|
||||
|
||||
ServerWorld serverWorld = cc.s.getWorld();
|
||||
Entity entity_1 = EntityType.loadEntityWithPassengers(tag, serverWorld, (entity_1x) -> {
|
||||
entity_1x.refreshPositionAndAngles(vec3d.x, vec3d.y, vec3d.z, entity_1x.yaw, entity_1x.pitch);
|
||||
entity_1x.refreshPositionAndAngles(vec3d.x, vec3d.y, vec3d.z, entity_1x.getYaw(), entity_1x.getPitch());
|
||||
return !serverWorld.tryLoadEntity(entity_1x) ? null : entity_1x;
|
||||
});
|
||||
if (entity_1 == null) {
|
||||
@@ -167,8 +167,8 @@ public class Entities {
|
||||
{
|
||||
String who = lv.get(0).getString();
|
||||
ServerCommandSource source = ((CarpetContext)c).s;
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getMinecraftServer());
|
||||
List<Entity> entityList = source.getWorld().getEntitiesByType(eDesc.directType, eDesc.filteringPredicate);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, source.getServer());
|
||||
List<? extends Entity> entityList = source.getWorld().getEntitiesByType(eDesc.directType, eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
@@ -195,7 +195,7 @@ public class Entities {
|
||||
throw new InternalExpressionException("Range of 'entity_area' cannot come from a block argument");
|
||||
Vec3d range = rangeLocator.vec;
|
||||
Box area = centerBox.expand(range.x, range.y, range.z);
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.s.getMinecraftServer());
|
||||
EntityValue.EntityClassDescriptor eDesc = EntityValue.getEntityDescriptor(who, cc.s.getServer());
|
||||
List<? extends Entity> entityList = cc.s.getWorld().getEntitiesByType(eDesc.directType, area,eDesc.filteringPredicate);
|
||||
return ListValue.wrap(entityList.stream().map(EntityValue::new).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -257,7 +257,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.getMinecraftServer()).listValue;
|
||||
return EntityValue.getEntityDescriptor(desc, ((CarpetContext) c).s.getServer()).listValue;
|
||||
});
|
||||
|
||||
expression.addContextFunction("entity_load_handler", -1, (c, t, lv) ->
|
||||
@@ -269,7 +269,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.getMinecraftServer()).typeList));
|
||||
descriptors.forEach(s -> types.addAll(EntityValue.getEntityDescriptor(s, ((CarpetContext) c).s.getServer()).typeList));
|
||||
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
|
||||
CarpetEventServer events = ((CarpetScriptHost)c.host).getScriptServer().events;
|
||||
if (funArg.function == null)
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
|
||||
import net.minecraft.recipe.AbstractCookingRecipe;
|
||||
import net.minecraft.recipe.CuttingRecipe;
|
||||
@@ -36,6 +36,7 @@ import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.TagManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.InvalidIdentifierException;
|
||||
@@ -65,9 +66,9 @@ public class Inventories {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.ITEM.getIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getItems().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return ListValue.wrap(itemTag.values().stream().map(b -> ValueConversions.of(Registry.ITEM.getId(b))).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -75,16 +76,16 @@ public class Inventories {
|
||||
expression.addContextFunction("item_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getItems().getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
|
||||
if (lv.size() == 1)
|
||||
return ListValue.wrap(tagManager.getItems().getTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTags().entrySet().stream().filter(e -> e.getValue().contains(item)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
String tag = lv.get(1).getString();
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getItems().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (itemTag == null) return Value.NULL;
|
||||
return BooleanValue.of(item.isIn(itemTag));
|
||||
return BooleanValue.of(itemTag.contains(item));
|
||||
});
|
||||
|
||||
expression.addContextFunction("recipe_data", -1, (c, t, lv) ->
|
||||
@@ -99,7 +100,7 @@ public class Inventories {
|
||||
type = Registry.RECIPE_TYPE.get(InputValidator.identifierOf(recipeType));
|
||||
}
|
||||
List<Recipe<?>> recipes;
|
||||
recipes = ((RecipeManagerInterface) cc.s.getMinecraftServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
recipes = ((RecipeManagerInterface) cc.s.getServer().getRecipeManager()).getAllMatching(type, InputValidator.identifierOf(recipeName));
|
||||
if (recipes.isEmpty())
|
||||
return Value.NULL;
|
||||
List<Value> recipesOutput = new ArrayList<>();
|
||||
@@ -107,7 +108,7 @@ public class Inventories {
|
||||
{
|
||||
ItemStack result = recipe.getOutput();
|
||||
List<Value> ingredientValue = new ArrayList<>();
|
||||
recipe.getPreviewInputs().forEach(
|
||||
recipe.getIngredients().forEach(
|
||||
ingredient ->
|
||||
{
|
||||
// I am flattening ingredient lists per slot.
|
||||
@@ -239,7 +240,7 @@ public class Inventories {
|
||||
syncPlayerInventory(inventoryLocator, slot);
|
||||
return ValueConversions.of(previousStack);
|
||||
}
|
||||
CompoundTag nbt = null; // skipping one argument
|
||||
NbtCompound nbt = null; // skipping one argument
|
||||
if (lv.size() > inventoryLocator.offset+3)
|
||||
{
|
||||
Value nbtValue = lv.get(inventoryLocator.offset+3);
|
||||
@@ -389,7 +390,7 @@ public class Inventories {
|
||||
{
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) inventory.owner;
|
||||
player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(
|
||||
-2,
|
||||
-2, 0, // resolve mystery argument
|
||||
int_1,
|
||||
inventory.inventory.getStack(int_1)
|
||||
));
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
if (lv.size()==0)
|
||||
return ListValue.wrap(scoreboard.getObjectiveNames().stream().map(StringValue::new).collect(Collectors.toList()));
|
||||
String objectiveName = lv.get(0).getString();
|
||||
@@ -103,7 +103,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.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String objectiveName = lv.get(0).getString();
|
||||
ScoreboardObjective objective = scoreboard.getObjective(objectiveName);
|
||||
if (objective == null) return Value.FALSE;
|
||||
@@ -126,7 +126,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_add", -1, (c, t, lv)->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().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();
|
||||
ScoreboardCriterion criterion;
|
||||
@@ -137,7 +137,7 @@ public class Scoreboards {
|
||||
else
|
||||
{
|
||||
String critetionName = lv.get(1).getString();
|
||||
criterion = ScoreboardCriterion.createStatCriterion(critetionName).orElse(null);
|
||||
criterion = ScoreboardCriterion.getOrCreateStatCriterion(critetionName).orElse(null);
|
||||
if (criterion==null)
|
||||
{
|
||||
throw new ThrowStatement(critetionName, Throwables.UNKNOWN_CRITERION);
|
||||
@@ -156,7 +156,7 @@ public class Scoreboards {
|
||||
return Value.FALSE;
|
||||
}
|
||||
|
||||
scoreboard.addObjective(objectiveName, criterion, new LiteralText(objectiveName), criterion.getCriterionType());
|
||||
scoreboard.addObjective(objectiveName, criterion, new LiteralText(objectiveName), criterion.getDefaultRenderType());
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
@@ -164,7 +164,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.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
ScoreboardObjective objective = scoreboard.getObjective(lv.get(0).getString());
|
||||
if(objective == null) return Value.NULL;
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Scoreboards {
|
||||
switch (property) {
|
||||
case "criterion":
|
||||
if(modify) {
|
||||
ScoreboardCriterion criterion = ScoreboardCriterion.createStatCriterion(setValue.getString()).orElse(null);
|
||||
ScoreboardCriterion criterion = ScoreboardCriterion.getOrCreateStatCriterion(setValue.getString()).orElse(null);
|
||||
if (criterion==null) throw new InternalExpressionException("Unknown scoreboard criterion: "+ setValue.getString());
|
||||
if(objective.getCriterion().equals(criterion) || lv.size() == 1) return Value.FALSE;
|
||||
((Scoreboard_scarpetMixin)scoreboard).getObjectivesByCriterion().get(objective.getCriterion()).remove(objective);
|
||||
@@ -229,7 +229,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("scoreboard_display", 2, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
Scoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
Scoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String location = lv.get(0).getString();
|
||||
int slot = Scoreboard.getDisplaySlotId(location);
|
||||
if (slot < 0) throw new InternalExpressionException("Invalid objective slot: "+location);
|
||||
@@ -250,7 +250,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.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
if(lv.size() == 0)
|
||||
return ListValue.wrap(scoreboard.getTeamNames().stream().map(StringValue::of).collect(Collectors.toList()));
|
||||
if (lv.size() != 1) return Value.NULL;
|
||||
@@ -265,7 +265,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.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
String teamName = lv.get(0).getString();
|
||||
|
||||
if(lv.size() == 1)
|
||||
@@ -288,7 +288,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_remove", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Value teamVal = lv.get(0);
|
||||
String team = teamVal.getString();
|
||||
if(scoreboard.getTeam(team) == null) return Value.NULL;
|
||||
@@ -300,7 +300,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_leave", 1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
Value playerVal = lv.get(0);
|
||||
String player = EntityValue.getPlayerNameByValue(playerVal);
|
||||
if(player == null) return Value.NULL;
|
||||
@@ -310,7 +310,7 @@ public class Scoreboards {
|
||||
expression.addContextFunction("team_property", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerScoreboard scoreboard = cc.s.getMinecraftServer().getScoreboard();
|
||||
ServerScoreboard scoreboard = cc.s.getServer().getScoreboard();
|
||||
|
||||
if(lv.size() < 2 || lv.size() > 3) throw new InternalExpressionException("'team_property' requires two or three arguments");
|
||||
|
||||
@@ -401,7 +401,7 @@ public class Scoreboards {
|
||||
|
||||
expression.addContextFunction("bossbar", -1, (c, t, lv) ->
|
||||
{
|
||||
BossBarManager bossBarManager = ((CarpetContext)c).s.getMinecraftServer().getBossBarManager();
|
||||
BossBarManager bossBarManager = ((CarpetContext)c).s.getServer().getBossBarManager();
|
||||
if(lv.size() > 3) throw new InternalExpressionException("'bossbar' accepts max three arguments");
|
||||
|
||||
if(lv.size() == 0) return ListValue.wrap(bossBarManager.getAll().stream().map(CommandBossBar::getId).map(Identifier::toString).map(StringValue::of).collect(Collectors.toList()));
|
||||
@@ -451,13 +451,13 @@ public class Scoreboards {
|
||||
|
||||
if(propertyValue instanceof ListValue) {
|
||||
((ListValue) propertyValue).getItems().forEach((v)->{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext)c).s.getMinecraftServer(),propertyValue);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext)c).s.getServer(),propertyValue);
|
||||
if(player != null) bossBar.addPlayer(player);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), propertyValue);
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
if(player != null) {
|
||||
bossBar.addPlayer(player);
|
||||
return Value.TRUE;
|
||||
@@ -469,14 +469,14 @@ public class Scoreboards {
|
||||
{
|
||||
bossBar.clearPlayers();
|
||||
((ListValue) propertyValue).getItems().forEach((v) -> {
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), v);
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), v);
|
||||
if (p != null) bossBar.addPlayer(p);
|
||||
});
|
||||
return Value.TRUE;
|
||||
}
|
||||
|
||||
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getMinecraftServer(), propertyValue);
|
||||
ServerPlayerEntity p = EntityValue.getPlayerByValue(((CarpetContext) c).s.getServer(), propertyValue);
|
||||
bossBar.clearPlayers();
|
||||
if (p != null) {
|
||||
bossBar.addPlayer(p);
|
||||
@@ -484,10 +484,10 @@ public class Scoreboards {
|
||||
}
|
||||
return Value.FALSE;
|
||||
case "style":
|
||||
if(propertyValue == null) return StringValue.of(bossBar.getOverlay().getName());
|
||||
if(propertyValue == null) return StringValue.of(bossBar.getStyle().getName());
|
||||
BossBar.Style style = BossBar.Style.byName(propertyValue.getString());
|
||||
if(style == null) throw new InternalExpressionException("'" + propertyValue.getString() + "' is not a valid value for property " + property);
|
||||
bossBar.setOverlay(style);
|
||||
bossBar.setStyle(style);
|
||||
return Value.TRUE;
|
||||
case "value":
|
||||
if(propertyValue == null) return NumericValue.of(bossBar.getValue());
|
||||
|
||||
@@ -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.getMinecraftServer().isOnThread())
|
||||
if (((CarpetContext)c).s.getServer().isOnThread())
|
||||
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.getMinecraftServer();
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
if (server.isOnThread()) 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.getMinecraftServer().submitAndJoin(() ->
|
||||
((CarpetContext) c).s.getServer().submitAndJoin(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -62,8 +62,8 @@ import net.minecraft.item.MiningToolItem;
|
||||
import net.minecraft.item.ShearsItem;
|
||||
import net.minecraft.item.SwordItem;
|
||||
import net.minecraft.item.TridentItem;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
@@ -74,6 +74,7 @@ import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.tag.TagManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Clearable;
|
||||
@@ -245,7 +246,7 @@ public class WorldAccess {
|
||||
return true;
|
||||
} else {
|
||||
ItemStack itemStack_1 = player.getMainHandStack();
|
||||
boolean boolean_2 = player.isUsingEffectiveTool(blockState_1);
|
||||
boolean boolean_2 = player.canHarvest(blockState_1);
|
||||
itemStack_1.postMine(player.world, blockState_1, blockPos_1, player);
|
||||
if (boolean_1 && boolean_2) {
|
||||
ItemStack itemStack_2 = itemStack_1.isEmpty() ? ItemStack.EMPTY : itemStack_1.copy();
|
||||
@@ -286,7 +287,7 @@ public class WorldAccess {
|
||||
{
|
||||
if (lv.size() == 0)
|
||||
throw new InternalExpressionException("Block requires at least one parameter");
|
||||
CompoundTag tag = BlockArgument.findIn( (CarpetContext) c, lv, 0, true).block.getData();
|
||||
NbtCompound tag = BlockArgument.findIn( (CarpetContext) c, lv, 0, true).block.getData();
|
||||
return NBTSerializableValue.of(tag);
|
||||
});
|
||||
|
||||
@@ -582,7 +583,7 @@ public class WorldAccess {
|
||||
{
|
||||
c.host.issueDeprecation("loaded_ep(...)");
|
||||
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
|
||||
return BooleanValue.of(((CarpetContext)c).s.getWorld().getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
return BooleanValue.of(((CarpetContext)c).s.getWorld().method_37118(pos));// 1.17pre1 getChunkManager().shouldTickChunk(new ChunkPos(pos)));
|
||||
});
|
||||
|
||||
expression.addContextFunction("loaded_status", -1, (c, t, lv) ->
|
||||
@@ -698,7 +699,7 @@ public class WorldAccess {
|
||||
boolean previous = CarpetSettings.impendingFillSkipUpdates.get();
|
||||
if (previous) return lv.get(0);
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -721,7 +722,7 @@ public class WorldAccess {
|
||||
BlockArgument sourceLocator = BlockArgument.findIn(cc, lv, targetLocator.offset, true);
|
||||
BlockState sourceBlockState = sourceLocator.block.getBlockState();
|
||||
BlockState targetBlockState = world.getBlockState(targetLocator.block.getPos());
|
||||
CompoundTag data = null;
|
||||
NbtCompound data = null;
|
||||
if (lv.size() > sourceLocator.offset)
|
||||
{
|
||||
List<Value> args = new ArrayList<>();
|
||||
@@ -780,14 +781,14 @@ public class WorldAccess {
|
||||
}
|
||||
|
||||
if (data == null) data = sourceLocator.block.getData();
|
||||
CompoundTag finalData = data;
|
||||
NbtCompound finalData = data;
|
||||
|
||||
if (sourceBlockState == targetBlockState && data == null)
|
||||
return Value.FALSE;
|
||||
BlockState finalSourceBlockState = sourceBlockState;
|
||||
BlockPos targetPos = targetLocator.block.getPos();
|
||||
Boolean[] result = new Boolean[]{true};
|
||||
cc.s.getMinecraftServer().submitAndJoin( () ->
|
||||
cc.s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Clearable.clear(world.getBlockEntity(targetPos));
|
||||
boolean success = world.setBlockState(targetPos, finalSourceBlockState, 2);
|
||||
@@ -796,11 +797,11 @@ public class WorldAccess {
|
||||
BlockEntity be = world.getBlockEntity(targetPos);
|
||||
if (be != null)
|
||||
{
|
||||
CompoundTag destTag = finalData.copy();
|
||||
NbtCompound destTag = finalData.copy();
|
||||
destTag.putInt("x", targetPos.getX());
|
||||
destTag.putInt("y", targetPos.getY());
|
||||
destTag.putInt("z", targetPos.getZ());
|
||||
be.fromTag(finalSourceBlockState, destTag);
|
||||
be.readNbt(destTag);
|
||||
be.markDirty();
|
||||
success = true;
|
||||
}
|
||||
@@ -838,7 +839,7 @@ public class WorldAccess {
|
||||
.orElseThrow(() -> new ThrowStatement(itemString, Throwables.UNKNOWN_ITEM));
|
||||
}
|
||||
}
|
||||
CompoundTag tag = null;
|
||||
NbtCompound tag = null;
|
||||
if (lv.size() > locator.offset+1)
|
||||
{
|
||||
if (!playerBreak) throw new InternalExpressionException("tag is not necessary with 'destroy' with no item");
|
||||
@@ -866,7 +867,7 @@ public class WorldAccess {
|
||||
boolean dropLoot = true;
|
||||
if (playerBreak)
|
||||
{
|
||||
boolean isUsingEffectiveTool = !state.isToolRequired() || tool.isEffectiveOn(state);
|
||||
boolean isUsingEffectiveTool = !state.isToolRequired() || tool.isSuitableFor(state);
|
||||
//postMine() durability from item classes
|
||||
float hardness = state.getHardness(world, where);
|
||||
int damageAmount = 0;
|
||||
@@ -901,7 +902,7 @@ public class WorldAccess {
|
||||
return Value.TRUE;
|
||||
if (toolBroke)
|
||||
return Value.NULL;
|
||||
Tag outtag = tool.getTag();
|
||||
NbtElement outtag = tool.getTag();
|
||||
if (outtag == null)
|
||||
return Value.TRUE;
|
||||
return new NBTSerializableValue(() -> outtag);
|
||||
@@ -1083,7 +1084,7 @@ public class WorldAccess {
|
||||
|
||||
expression.addContextFunction("map_colour", -1, (c, t, lv) ->
|
||||
stateStringQuery(c, "map_colour", lv, (s, p) ->
|
||||
BlockInfo.mapColourName.get(s.getTopMaterialColor(((CarpetContext)c).s.getWorld(), p))));
|
||||
BlockInfo.mapColourName.get(s.getMapColor(((CarpetContext)c).s.getWorld(), p))));
|
||||
|
||||
|
||||
// Deprecated for block_state()
|
||||
@@ -1141,9 +1142,9 @@ public class WorldAccess {
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(Registry.BLOCK.getIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
String tag = lv.get(0).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(InputValidator.identifierOf(tag));
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return ListValue.wrap(blockTag.values().stream().map(b -> ValueConversions.of(Registry.BLOCK.getId(b))).collect(Collectors.toList()));
|
||||
});
|
||||
@@ -1151,17 +1152,17 @@ public class WorldAccess {
|
||||
expression.addContextFunction("block_tags", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
TagManager tagManager = cc.s.getMinecraftServer().getTagManager();
|
||||
TagManager tagManager = cc.s.getServer().getTagManager();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(tagManager.getBlocks().getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTagIds().stream().map(ValueConversions::of).collect(Collectors.toList()));
|
||||
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
|
||||
if (blockLocator.offset == lv.size())
|
||||
{
|
||||
Block target = blockLocator.block.getBlockState().getBlock();
|
||||
return ListValue.wrap(tagManager.getBlocks().getTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
return ListValue.wrap(tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTags().entrySet().stream().filter(e -> e.getValue().contains(target)).map(e -> ValueConversions.of(e.getKey())).collect(Collectors.toList()));
|
||||
}
|
||||
String tag = lv.get(blockLocator.offset).getString();
|
||||
net.minecraft.tag.Tag<Block> blockTag = tagManager.getBlocks().getTag(InputValidator.identifierOf(tag));
|
||||
Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(InputValidator.identifierOf(tag));
|
||||
if (blockTag == null) return Value.NULL;
|
||||
return BooleanValue.of(blockLocator.block.getBlockState().isIn(blockTag));
|
||||
});
|
||||
@@ -1188,7 +1189,7 @@ public class WorldAccess {
|
||||
// in locatebiome
|
||||
if (locator.offset == lv.size())
|
||||
{
|
||||
Identifier biomeId = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
Identifier biomeId = cc.s.getServer().getRegistryManager().get(Registry.BIOME_KEY).getId(biome);
|
||||
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
|
||||
}
|
||||
String biomeFeature = lv.get(locator.offset).getString();
|
||||
@@ -1205,7 +1206,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
|
||||
Biome biome = cc.s.getMinecraftServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(InputValidator.identifierOf(biomeName))
|
||||
Biome biome = cc.s.getServer().getRegistryManager().get(Registry.BIOME_KEY).getOrEmpty(InputValidator.identifierOf(biomeName))
|
||||
.orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
|
||||
boolean doImmediateUpdate = true;
|
||||
if (lv.size() > locator.offset+1)
|
||||
@@ -1224,7 +1225,7 @@ public class WorldAccess {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockPos pos = BlockArgument.findIn(cc, lv, 0).block.getPos();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
cc.s.getMinecraftServer().submitAndJoin( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
cc.s.getServer().submitAndJoin( () -> WorldTools.forceChunkUpdate(pos, world));
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
@@ -1323,10 +1324,10 @@ public class WorldAccess {
|
||||
StructureStart<?> start = entry.getValue();
|
||||
if (start == StructureStart.DEFAULT)
|
||||
continue;
|
||||
BlockBox box = start.getBoundingBox();
|
||||
BlockBox box = start.setBoundingBoxFromChildren();
|
||||
structureList.put(
|
||||
new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.STRUCTURE_FEATURE.getId(entry.getKey()))),
|
||||
ListValue.of(ListValue.fromTriple(box.minX, box.minY, box.minZ), ListValue.fromTriple(box.maxX, box.maxY, box.maxZ))
|
||||
ListValue.of(ListValue.fromTriple(box.getMinX(), box.getMinY(), box.getMinZ()), ListValue.fromTriple(box.getMaxX(), box.getMaxY(), box.getMaxZ()))
|
||||
);
|
||||
}
|
||||
return MapValue.wrap(structureList);
|
||||
@@ -1351,7 +1352,7 @@ 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.getMinecraftServer().submitAndJoin(() ->
|
||||
((CarpetContext) c).s.getServer().submitAndJoin(() ->
|
||||
{
|
||||
Map<StructureFeature<?>, StructureStart<?>> structures = world.getChunk(pos).getStructureStarts();
|
||||
if (lv.size() == locator.offset + 1)
|
||||
@@ -1371,11 +1372,11 @@ public class WorldAccess {
|
||||
return;
|
||||
}
|
||||
StructureStart<?> start = structures.get(structure);
|
||||
ChunkPos structureChunkPos = new ChunkPos(start.getChunkX(), start.getChunkZ());
|
||||
BlockBox box = start.getBoundingBox();
|
||||
for (int chx = box.minX / 16; chx <= box.maxX / 16; chx++)
|
||||
ChunkPos structureChunkPos = start.getPos(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
|
||||
BlockBox box = start.setBoundingBoxFromChildren();
|
||||
for (int chx = box.getMinX() / 16; chx <= box.getMaxX() / 16; chx++) // minx maxx
|
||||
{
|
||||
for (int chz = box.minZ / 16; chz <= box.maxZ / 16; chz++)
|
||||
for (int chz = box.getMinZ() / 16; chz <= box.getMaxZ() / 16; chz++) //minZ maxZ
|
||||
{
|
||||
ChunkPos chpos = new ChunkPos(chx, chz);
|
||||
// getting a chunk will convert it to full, allowing to modify references
|
||||
@@ -1413,7 +1414,7 @@ public class WorldAccess {
|
||||
}
|
||||
}
|
||||
|
||||
boolean success = WorldTools.createWorld(cc.s.getMinecraftServer(), worldKey, seed);
|
||||
boolean success = WorldTools.createWorld(cc.s.getServer(), worldKey, seed);
|
||||
if (!success) return Value.FALSE;
|
||||
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
||||
return Value.TRUE;
|
||||
@@ -1472,16 +1473,16 @@ public class WorldAccess {
|
||||
|
||||
Value [] result = new Value[]{Value.NULL};
|
||||
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().submitAndJoin( () ->
|
||||
{
|
||||
Map<String, Integer> report = ((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(requestedChunks);
|
||||
for (ChunkPos chpos: requestedChunks)
|
||||
/*for (ChunkPos chpos: requestedChunks) // needed in 1.16 only
|
||||
{
|
||||
if (world.getChunk(chpos.x, chpos.z, ChunkStatus.FULL, false) != null)
|
||||
{
|
||||
WorldTools.forceChunkUpdate(chpos.getStartPos(), world);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
result[0] = MapValue.wrap(report.entrySet().stream().collect(Collectors.toMap(
|
||||
e -> new StringValue((String)((Map.Entry) e).getKey()),
|
||||
e -> new NumericValue((Integer)((Map.Entry) e).getValue())
|
||||
|
||||
Reference in new issue
Block a user