Migrate the Carpet codebase to Mojang Mappings
This commit is contained in:
346 files changed
+8353
-8492
No files matched your search
@@ -41,68 +41,64 @@ import carpet.script.value.ValueConversions;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.DataCommandStorage;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
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.NbtCompound;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.Rotations;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
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.particle.ParticleEffect;
|
||||
import net.minecraft.resource.DataPackSettings;
|
||||
import net.minecraft.resource.ReloadableResourceManagerImpl;
|
||||
import net.minecraft.resource.ResourcePackManager;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import net.minecraft.resource.ServerResourceManager;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomSoundPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
|
||||
import net.minecraft.resources.RegistryReadOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.stat.Stat;
|
||||
import net.minecraft.stat.StatType;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.InvalidIdentifierException;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.util.dynamic.RegistryOps;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.EulerAngle;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.SaveProperties;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.source.BiomeAccess;
|
||||
import net.minecraft.world.border.WorldBorderListener;
|
||||
import net.minecraft.world.dimension.DimensionOptions;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraft.world.gen.GeneratorOptions;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.UnmodifiableLevelProperties;
|
||||
import net.minecraft.world.level.storage.LevelStorage;
|
||||
import net.minecraft.server.ServerResources;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.stats.StatType;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.border.BorderChangeListener;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraft.world.level.storage.CommandStorage;
|
||||
import net.minecraft.world.level.storage.DerivedLevelData;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -136,7 +132,7 @@ import static java.lang.Math.min;
|
||||
|
||||
public class Auxiliary {
|
||||
public static final String MARKER_STRING = "__scarpet_marker";
|
||||
private static final Map<String, SoundCategory> mixerMap = Arrays.stream(SoundCategory.values()).collect(Collectors.toMap(SoundCategory::getName, k -> k));
|
||||
private static final Map<String, SoundSource> mixerMap = Arrays.stream(SoundSource.values()).collect(Collectors.toMap(SoundSource::getName, k -> k));
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().registerTypeAdapter(Value.class, new ScarpetJsonDeserializer()).create();
|
||||
|
||||
@Deprecated
|
||||
@@ -158,16 +154,16 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
return ListValue.wrap(Registry.SOUND_EVENT.getIds().stream().map(ValueConversions::of));
|
||||
return ListValue.wrap(Registry.SOUND_EVENT.keySet().stream().map(ValueConversions::of));
|
||||
}
|
||||
String rawString = lv.get(0).getString();
|
||||
Identifier soundName = InputValidator.identifierOf(rawString);
|
||||
ResourceLocation soundName = InputValidator.identifierOf(rawString);
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
if (Registry.SOUND_EVENT.get(soundName) == null)
|
||||
throw new ThrowStatement(rawString, Throwables.UNKNOWN_SOUND);
|
||||
float volume = 1.0F;
|
||||
float pitch = 1.0F;
|
||||
SoundCategory mixer = SoundCategory.MASTER;
|
||||
SoundSource mixer = SoundSource.MASTER;
|
||||
if (lv.size() > 0+locator.offset)
|
||||
{
|
||||
volume = (float) NumericValue.asNumber(lv.get(0+locator.offset)).getDouble();
|
||||
@@ -182,13 +178,13 @@ public class Auxiliary {
|
||||
}
|
||||
}
|
||||
}
|
||||
Vec3d vec = locator.vec;
|
||||
Vec3 vec = locator.vec;
|
||||
double d0 = Math.pow(volume > 1.0F ? (double)(volume * 16.0F) : 16.0D, 2.0D);
|
||||
int count = 0;
|
||||
for (ServerPlayerEntity player : cc.s.getWorld().getPlayers( (p) -> p.squaredDistanceTo(vec) < d0))
|
||||
for (ServerPlayer player : cc.s.getLevel().getPlayers( (p) -> p.distanceToSqr(vec) < d0))
|
||||
{
|
||||
count++;
|
||||
player.networkHandler.sendPacket(new PlaySoundIdS2CPacket(soundName, mixer, vec, volume, pitch));
|
||||
player.connection.send(new ClientboundCustomSoundPacket(soundName, mixer, vec, volume, pitch));
|
||||
}
|
||||
return new NumericValue(count);
|
||||
});
|
||||
@@ -196,15 +192,15 @@ public class Auxiliary {
|
||||
expression.addContextFunction("particle", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
if (lv.size() == 0) return ListValue.wrap(Registry.PARTICLE_TYPE.getIds().stream().map(ValueConversions::of));
|
||||
if (lv.size() == 0) return ListValue.wrap(Registry.PARTICLE_TYPE.keySet().stream().map(ValueConversions::of));
|
||||
MinecraftServer ms = cc.s.getServer();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
Vector3Argument locator = Vector3Argument.findIn(lv, 1);
|
||||
String particleName = lv.get(0).getString();
|
||||
int count = 10;
|
||||
double speed = 0;
|
||||
float spread = 0.5f;
|
||||
ServerPlayerEntity player = null;
|
||||
ServerPlayer player = null;
|
||||
if (lv.size() > locator.offset)
|
||||
{
|
||||
count = (int) NumericValue.asNumber(lv.get(locator.offset)).getLong();
|
||||
@@ -216,24 +212,24 @@ public class Auxiliary {
|
||||
speed = NumericValue.asNumber(lv.get(2 + locator.offset)).getDouble();
|
||||
if (lv.size() > 3 + locator.offset) // should accept entity as well as long as it is player
|
||||
{
|
||||
player = ms.getPlayerManager().getPlayer(lv.get(3 + locator.offset).getString());
|
||||
player = ms.getPlayerList().getPlayerByName(lv.get(3 + locator.offset).getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ParticleEffect particle = ShapeDispatcher.getParticleData(particleName);
|
||||
Vec3d vec = locator.vec;
|
||||
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName);
|
||||
Vec3 vec = locator.vec;
|
||||
if (player == null)
|
||||
{
|
||||
for (PlayerEntity p : (world.getPlayers()))
|
||||
for (Player p : (world.players()))
|
||||
{
|
||||
world.spawnParticles((ServerPlayerEntity)p, particle, true, vec.x, vec.y, vec.z, count,
|
||||
world.sendParticles((ServerPlayer)p, particle, true, vec.x, vec.y, vec.z, count,
|
||||
spread, spread, spread, speed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
world.spawnParticles(player,
|
||||
world.sendParticles(player,
|
||||
particle, true, vec.x, vec.y, vec.z, count,
|
||||
spread, spread, spread, speed);
|
||||
}
|
||||
@@ -244,13 +240,13 @@ public class Auxiliary {
|
||||
expression.addContextFunction("particle_line", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
String particleName = lv.get(0).getString();
|
||||
ParticleEffect particle = ShapeDispatcher.getParticleData(particleName);
|
||||
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName);
|
||||
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
|
||||
Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset);
|
||||
double density = 1.0;
|
||||
ServerPlayerEntity player = null;
|
||||
ServerPlayer player = null;
|
||||
if (lv.size() > pos2.offset+0 )
|
||||
{
|
||||
density = NumericValue.asNumber(lv.get(pos2.offset+0)).getDouble();
|
||||
@@ -264,18 +260,18 @@ public class Auxiliary {
|
||||
if (playerValue instanceof EntityValue)
|
||||
{
|
||||
Entity e = ((EntityValue) playerValue).getEntity();
|
||||
if (!(e instanceof ServerPlayerEntity)) throw new InternalExpressionException("'particle_line' player argument has to be a player");
|
||||
player = (ServerPlayerEntity) e;
|
||||
if (!(e instanceof ServerPlayer)) throw new InternalExpressionException("'particle_line' player argument has to be a player");
|
||||
player = (ServerPlayer) e;
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new NumericValue(ShapeDispatcher.drawParticleLine(
|
||||
(player == null)?world.getPlayers(): Collections.singletonList(player),
|
||||
(player == null)?world.players(): Collections.singletonList(player),
|
||||
particle, pos1.vec, pos2.vec, density
|
||||
));
|
||||
});
|
||||
@@ -283,14 +279,14 @@ public class Auxiliary {
|
||||
expression.addContextFunction("particle_box", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
String particleName = lv.get(0).getString();
|
||||
ParticleEffect particle = ShapeDispatcher.getParticleData(particleName);
|
||||
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName);
|
||||
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
|
||||
Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset);
|
||||
|
||||
double density = 1.0;
|
||||
ServerPlayerEntity player = null;
|
||||
ServerPlayer player = null;
|
||||
if (lv.size() > pos2.offset+0 )
|
||||
{
|
||||
density = NumericValue.asNumber(lv.get(pos2.offset+0)).getDouble();
|
||||
@@ -304,21 +300,21 @@ public class Auxiliary {
|
||||
if (playerValue instanceof EntityValue)
|
||||
{
|
||||
Entity e = ((EntityValue) playerValue).getEntity();
|
||||
if (!(e instanceof ServerPlayerEntity)) throw new InternalExpressionException("'particle_box' player argument has to be a player");
|
||||
player = (ServerPlayerEntity) e;
|
||||
if (!(e instanceof ServerPlayer)) throw new InternalExpressionException("'particle_box' player argument has to be a player");
|
||||
player = (ServerPlayer) e;
|
||||
}
|
||||
else
|
||||
{
|
||||
player = cc.s.getServer().getPlayerManager().getPlayer(playerValue.getString());
|
||||
player = cc.s.getServer().getPlayerList().getPlayerByName(playerValue.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Vec3d a = pos1.vec;
|
||||
Vec3d b = pos2.vec;
|
||||
Vec3d from = new Vec3d(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
|
||||
Vec3d to = new Vec3d(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
|
||||
Vec3 a = pos1.vec;
|
||||
Vec3 b = pos2.vec;
|
||||
Vec3 from = new Vec3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
|
||||
Vec3 to = new Vec3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
|
||||
int particleCount = ShapeDispatcher.Box.particleMesh(
|
||||
player==null?world.getPlayers():Collections.singletonList(player),
|
||||
player==null?world.players():Collections.singletonList(player),
|
||||
particle, density, from, to
|
||||
);
|
||||
return new NumericValue(particleCount);
|
||||
@@ -330,9 +326,9 @@ public class Auxiliary {
|
||||
expression.addContextFunction("draw_shape", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
MinecraftServer server = world.getServer();
|
||||
Set<ServerPlayerEntity> playerTargets = new HashSet<>();
|
||||
Set<ServerPlayer> playerTargets = new HashSet<>();
|
||||
List<ShapeDispatcher.ShapeWithConfig> shapes = new ArrayList<>();
|
||||
if (lv.size() == 1) // bulk
|
||||
{
|
||||
@@ -350,7 +346,7 @@ public class Auxiliary {
|
||||
}
|
||||
|
||||
ShapeDispatcher.sendShape(
|
||||
(playerTargets.isEmpty())?cc.s.getWorld().getPlayers():playerTargets,
|
||||
(playerTargets.isEmpty())?cc.s.getLevel().players():playerTargets,
|
||||
shapes
|
||||
);
|
||||
return Value.TRUE;
|
||||
@@ -382,7 +378,7 @@ public class Auxiliary {
|
||||
throw new InternalExpressionException("'create_marker' requires a name and three coordinates, with optional direction, and optional block on its head");
|
||||
}
|
||||
|
||||
ArmorStandEntity armorstand = new ArmorStandEntity(EntityType.ARMOR_STAND, cc.s.getWorld());
|
||||
ArmorStand armorstand = new ArmorStand(EntityType.ARMOR_STAND, cc.s.getLevel());
|
||||
double yoffset;
|
||||
if (targetBlock == null && name.isEmpty())
|
||||
{
|
||||
@@ -396,14 +392,14 @@ public class Auxiliary {
|
||||
{
|
||||
if (targetBlock==null)
|
||||
{
|
||||
yoffset = -armorstand.getHeight()-0.41;
|
||||
yoffset = -armorstand.getBbHeight()-0.41;
|
||||
}
|
||||
else
|
||||
{
|
||||
yoffset = -armorstand.getHeight()+0.3;
|
||||
yoffset = -armorstand.getBbHeight()+0.3;
|
||||
}
|
||||
}
|
||||
armorstand.refreshPositionAndAngles(
|
||||
armorstand.moveTo(
|
||||
pointLocator.vec.x,
|
||||
//pointLocator.vec.y - ((!interactable && targetBlock == null)?0.41f:((targetBlock==null)?(armorstand.getHeight()+0.41):(armorstand.getHeight()-0.3))),
|
||||
pointLocator.vec.y + yoffset,
|
||||
@@ -411,21 +407,21 @@ public class Auxiliary {
|
||||
(float)pointLocator.yaw,
|
||||
(float) pointLocator.pitch
|
||||
);
|
||||
armorstand.addScoreboardTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
||||
armorstand.addScoreboardTag(MARKER_STRING);
|
||||
armorstand.addTag(MARKER_STRING+"_"+((cc.host.getName()==null)?"":cc.host.getName()));
|
||||
armorstand.addTag(MARKER_STRING);
|
||||
if (targetBlock != null)
|
||||
armorstand.equipStack(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
|
||||
armorstand.setItemSlot(EquipmentSlot.HEAD, new ItemStack(targetBlock.getBlock().asItem()));
|
||||
if (!name.isEmpty())
|
||||
{
|
||||
armorstand.setCustomName(new LiteralText(name));
|
||||
armorstand.setCustomName(new TextComponent(name));
|
||||
armorstand.setCustomNameVisible(true);
|
||||
}
|
||||
armorstand.setHeadRotation(new EulerAngle((int)pointLocator.pitch,0,0));
|
||||
armorstand.setHeadPose(new Rotations((int)pointLocator.pitch,0,0));
|
||||
armorstand.setNoGravity(true);
|
||||
armorstand.setInvisible(true);
|
||||
armorstand.setInvulnerable(true);
|
||||
armorstand.getDataTracker().set(ArmorStandEntity.ARMOR_STAND_FLAGS, (byte)(interactable?8 : 16|8));
|
||||
cc.s.getWorld().spawnEntity(armorstand);
|
||||
armorstand.getEntityData().set(ArmorStand.DATA_CLIENT_FLAGS, (byte)(interactable?8 : 16|8));
|
||||
cc.s.getLevel().addFreshEntity(armorstand);
|
||||
return new EntityValue(armorstand);
|
||||
});
|
||||
|
||||
@@ -433,7 +429,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.getWorld().getEntitiesByType(EntityType.ARMOR_STAND, (as) -> as.getScoreboardTags().contains(markerName)))
|
||||
for (Entity e : cc.s.getLevel().getEntities(EntityType.ARMOR_STAND, (as) -> as.getTags().contains(markerName)))
|
||||
{
|
||||
total ++;
|
||||
e.discard(); // discard // remove();
|
||||
@@ -443,7 +439,7 @@ public class Auxiliary {
|
||||
|
||||
expression.addUnaryFunction("nbt", NBTSerializableValue::fromValue);
|
||||
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(NbtString.escape(v.getString())));
|
||||
expression.addUnaryFunction("escape_nbt", v -> new StringValue(StringTag.quoteAndEscape(v.getString())));
|
||||
|
||||
expression.addUnaryFunction("parse_nbt", v -> {
|
||||
if (v instanceof NBTSerializableValue) return ((NBTSerializableValue) v).toValue();
|
||||
@@ -457,9 +453,9 @@ 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;
|
||||
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()));
|
||||
Tag source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
Tag match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
return BooleanValue.of(NbtUtils.compareNbt(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
||||
});
|
||||
|
||||
expression.addFunction("encode_nbt", lv -> {
|
||||
@@ -467,7 +463,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();
|
||||
NbtElement tag;
|
||||
Tag tag;
|
||||
try
|
||||
{
|
||||
tag = v.toTag(force);
|
||||
@@ -483,30 +479,30 @@ 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");
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
MinecraftServer server = s.getServer();
|
||||
Value res = lv.get(0);
|
||||
List<ServerPlayerEntity> targets = null;
|
||||
List<ServerPlayer> targets = null;
|
||||
if (lv.size() == 2)
|
||||
{
|
||||
List<Value> playerValues = (res instanceof ListValue)?((ListValue) res).getItems():Collections.singletonList(res);
|
||||
List<ServerPlayerEntity> playerTargets = new ArrayList<>();
|
||||
List<ServerPlayer> playerTargets = new ArrayList<>();
|
||||
playerValues.forEach(pv -> {
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, pv);
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(server, pv);
|
||||
if (player == null) throw new InternalExpressionException("Cannot target player "+pv.getString()+" in print");
|
||||
playerTargets.add(player);
|
||||
});
|
||||
targets = playerTargets;
|
||||
res = lv.get(1);
|
||||
}
|
||||
Text message = FormattedTextValue.getTextByValue(res);
|
||||
Component message = FormattedTextValue.getTextByValue(res);
|
||||
if (targets == null)
|
||||
{
|
||||
s.sendFeedback(message, false);
|
||||
s.sendSuccess(message, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
targets.forEach(p -> p.getCommandSource().sendFeedback(message, false));
|
||||
targets.forEach(p -> p.createCommandSourceStack().sendSuccess(message, false));
|
||||
}
|
||||
return res; // pass through for variables
|
||||
});
|
||||
@@ -516,40 +512,40 @@ public class Auxiliary {
|
||||
Value pVal = lv.get(0);
|
||||
if (!(pVal instanceof ListValue)) pVal = ListValue.of(pVal);
|
||||
MinecraftServer server = ((CarpetContext)c).s.getServer();
|
||||
Stream<ServerPlayerEntity> targets = ((ListValue) pVal).getItems().stream().map(v ->
|
||||
Stream<ServerPlayer> targets = ((ListValue) pVal).getItems().stream().map(v ->
|
||||
{
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(server, v);
|
||||
ServerPlayer 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;
|
||||
});
|
||||
Function<Text, Packet<?>> packetGetter = null;
|
||||
Function<Component, Packet<?>> packetGetter = null;
|
||||
//TitleS2CPacket.Action action;
|
||||
String actionString = lv.get(1).getString().toLowerCase(Locale.ROOT);
|
||||
switch (actionString)
|
||||
{
|
||||
case "title":
|
||||
packetGetter = TitleS2CPacket::new;
|
||||
packetGetter = ClientboundSetTitleTextPacket::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":
|
||||
packetGetter = SubtitleS2CPacket::new;
|
||||
packetGetter = ClientboundSetSubtitleTextPacket::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":
|
||||
packetGetter = OverlayMessageS2CPacket::new;
|
||||
packetGetter = ClientboundSetActionBarTextPacket::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":
|
||||
packetGetter = (x) -> new ClearTitleS2CPacket(true); // resetting default fade
|
||||
packetGetter = (x) -> new ClientboundClearTitlesPacket(true); // resetting default fade
|
||||
//action = Action.CLEAR;
|
||||
break;
|
||||
case "player_list_header":
|
||||
@@ -560,7 +556,7 @@ public class Auxiliary {
|
||||
}
|
||||
//if (action != Action.CLEAR && lv.size() < 3)
|
||||
// throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
Text title;
|
||||
Component title;
|
||||
boolean soundsTrue = false;
|
||||
if (lv.size() > 2)
|
||||
{
|
||||
@@ -571,35 +567,35 @@ public class Auxiliary {
|
||||
else title = null; // Will never happen, just to make lambda happy
|
||||
if (packetGetter == null)
|
||||
{
|
||||
Map<String, BaseText> map;
|
||||
Map<String, BaseComponent> 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());
|
||||
List<ServerPlayer> targetList = targets.collect(Collectors.toList());
|
||||
if (!soundsTrue) // null or empty string
|
||||
targetList.forEach(target -> {
|
||||
map.remove(target.getEntityName());
|
||||
map.remove(target.getScoreboardName());
|
||||
total.getAndIncrement();
|
||||
});
|
||||
else
|
||||
targetList.forEach(target -> {
|
||||
map.put(target.getEntityName(), (BaseText) title);
|
||||
map.put(target.getScoreboardName(), (BaseComponent) title);
|
||||
total.getAndIncrement();
|
||||
});
|
||||
HUDController.update_hud(((CarpetContext)c).s.getServer(), targetList);
|
||||
return NumericValue.of(total.get());
|
||||
}
|
||||
TitleFadeS2CPacket timesPacket; // TimesPacket
|
||||
ClientboundSetTitlesAnimationPacket 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 TitleFadeS2CPacket(in, stay, out);
|
||||
timesPacket = new ClientboundSetTitlesAnimationPacket(in, stay, out);
|
||||
//timesPacket = new TitleS2CPacket(Action.TIMES, null, in, stay, out);
|
||||
}
|
||||
else timesPacket = null;
|
||||
@@ -608,8 +604,8 @@ public class Auxiliary {
|
||||
//TitleS2CPacket packet = new TitleS2CPacket(action, title);
|
||||
AtomicInteger total = new AtomicInteger(0);
|
||||
targets.forEach(p -> {
|
||||
if (timesPacket != null) p.networkHandler.sendPacket(timesPacket);
|
||||
p.networkHandler.sendPacket(packet);
|
||||
if (timesPacket != null) p.connection.send(timesPacket);
|
||||
p.connection.send(packet);
|
||||
total.getAndIncrement();
|
||||
});
|
||||
return NumericValue.of(total.get());
|
||||
@@ -624,12 +620,12 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("run", 1, (c, t, lv) ->
|
||||
{
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
try
|
||||
{
|
||||
Text[] error = {null};
|
||||
List<Text> output = new ArrayList<>();
|
||||
Value retval = new NumericValue(s.getServer().getCommandManager().execute(
|
||||
Component[] error = {null};
|
||||
List<Component> output = new ArrayList<>();
|
||||
Value retval = new NumericValue(s.getServer().getCommands().performCommand(
|
||||
new SnoopyCommandSource(s, error, output),
|
||||
lv.get(0).getString())
|
||||
);
|
||||
@@ -641,39 +637,39 @@ public class Auxiliary {
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
return ListValue.of(Value.NULL, ListValue.of(), new FormattedTextValue(new LiteralText(exc.getMessage())));
|
||||
return ListValue.of(Value.NULL, ListValue.of(), new FormattedTextValue(new TextComponent(exc.getMessage())));
|
||||
}
|
||||
});
|
||||
|
||||
expression.addContextFunction("save", 0, (c, t, lv) ->
|
||||
{
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
s.getServer().getPlayerManager().saveAllPlayerData();
|
||||
s.getServer().save(true,true,true);
|
||||
for (ServerWorld world : s.getServer().getWorlds())
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
s.getServer().getPlayerList().saveAll();
|
||||
s.getServer().saveAllChunks(true,true,true);
|
||||
for (ServerLevel world : s.getServer().getAllLevels())
|
||||
{
|
||||
world.getChunkManager().tick(() -> true, false);
|
||||
world.getChunkSource().tick(() -> true, false);
|
||||
}
|
||||
CarpetScriptServer.LOG.warn("Saved chunks");
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
expression.addContextFunction("tick_time", 0, (c, t, lv) ->
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTicks()));
|
||||
new NumericValue(((CarpetContext) c).s.getServer().getTickCount()));
|
||||
|
||||
expression.addContextFunction("world_time", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("world_time()");
|
||||
return new NumericValue(((CarpetContext) c).s.getWorld().getTime());
|
||||
return new NumericValue(((CarpetContext) c).s.getLevel().getGameTime());
|
||||
});
|
||||
|
||||
expression.addContextFunction("day_time", -1, (c, t, lv) ->
|
||||
{
|
||||
Value time = new NumericValue(((CarpetContext) c).s.getWorld().getTimeOfDay());
|
||||
Value time = new NumericValue(((CarpetContext) c).s.getLevel().getDayTime());
|
||||
if (lv.size() > 0)
|
||||
{
|
||||
long newTime = NumericValue.asNumber(lv.get(0)).getLong();
|
||||
if (newTime < 0) newTime = 0;
|
||||
((CarpetContext) c).s.getWorld().setTimeOfDay(newTime);// setTimeOfDay(newTime);
|
||||
((CarpetContext) c).s.getLevel().setDayTime(newTime);// setTimeOfDay(newTime);
|
||||
}
|
||||
return time;
|
||||
});
|
||||
@@ -687,9 +683,9 @@ public class Auxiliary {
|
||||
|
||||
expression.addContextFunction("game_tick", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerCommandSource s = cc.s;
|
||||
CommandSourceStack s = cc.s;
|
||||
if (CarpetServer.scriptServer == null) return Value.NULL;
|
||||
if (!s.getServer().isOnThread()) throw new InternalExpressionException("Unable to run ticks from threads");
|
||||
if (!s.getServer().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
|
||||
{
|
||||
@@ -725,9 +721,9 @@ public class Auxiliary {
|
||||
});
|
||||
|
||||
expression.addContextFunction("seed", -1, (c, t, lv) -> {
|
||||
ServerCommandSource s = ((CarpetContext)c).s;
|
||||
CommandSourceStack s = ((CarpetContext)c).s;
|
||||
c.host.issueDeprecation("seed()");
|
||||
return new NumericValue(s.getWorld().getSeed());
|
||||
return new NumericValue(s.getLevel().getSeed());
|
||||
});
|
||||
|
||||
expression.addContextFunction("relight", -1, (c, t, lv) ->
|
||||
@@ -735,28 +731,28 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
BlockPos pos = locator.block.getPos();
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).relightChunk(new ChunkPos(pos));
|
||||
ServerLevel world = cc.s.getLevel();
|
||||
((ThreadedAnvilChunkStorageInterface) world.getChunkSource().chunkMap).relightChunk(new ChunkPos(pos));
|
||||
WorldTools.forceChunkUpdate(pos, world);
|
||||
return Value.TRUE;
|
||||
});
|
||||
|
||||
// Should this be deprecated for system_info('source_dimension')?
|
||||
expression.addContextFunction("current_dimension", 0, (c, t, lv) ->
|
||||
ValueConversions.of( ((CarpetContext)c).s.getWorld()));
|
||||
ValueConversions.of( ((CarpetContext)c).s.getLevel()));
|
||||
|
||||
expression.addContextFunction("view_distance", 0, (c, t, lv) -> {
|
||||
c.host.issueDeprecation("view_distance()");
|
||||
return new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance());
|
||||
return new NumericValue(((CarpetContext)c).s.getServer().getPlayerList().getViewDistance());
|
||||
});
|
||||
|
||||
// lazy due to passthrough and context changing ability
|
||||
expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> {
|
||||
ServerCommandSource outerSource = ((CarpetContext)c).s;
|
||||
CommandSourceStack outerSource = ((CarpetContext)c).s;
|
||||
Value dimensionValue = lv.get(0).evalValue(c);
|
||||
World world = ValueConversions.dimFromValue(dimensionValue, outerSource.getServer());
|
||||
if (world == outerSource.getWorld()) return lv.get(1);
|
||||
ServerCommandSource innerSource = outerSource.withWorld((ServerWorld)world);
|
||||
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;
|
||||
newCtx.variables = c.variables;
|
||||
@@ -769,21 +765,21 @@ public class Auxiliary {
|
||||
{
|
||||
Map<Value, Value> plopData = new HashMap<>();
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
DynamicRegistryManager registryManager = cc.s.getWorld().getRegistryManager();
|
||||
RegistryAccess registryManager = cc.s.getLevel().registryAccess();
|
||||
plopData.put(StringValue.of("scarpet_custom"),
|
||||
ListValue.wrap(FeatureGenerator.featureMap.keySet().stream().sorted().map(StringValue::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("features"),
|
||||
ListValue.wrap(Registry.FEATURE.getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(Registry.FEATURE.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_features"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).keySet().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()))
|
||||
ListValue.wrap(Registry.STRUCTURE_FEATURE.keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
plopData.put(StringValue.of("configured_structures"),
|
||||
ListValue.wrap(registryManager.get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).getIds().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
ListValue.wrap(registryManager.registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).keySet().stream().sorted().map(ValueConversions::of).collect(Collectors.toList()))
|
||||
);
|
||||
return MapValue.wrap(plopData);
|
||||
}
|
||||
@@ -792,14 +788,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().submitAndJoin( () ->
|
||||
((CarpetContext)c).s.getServer().executeBlocking( () ->
|
||||
{
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).s.getWorld(), locator.block.getPos());
|
||||
Boolean res = FeatureGenerator.plop(what, ((CarpetContext) c).s.getLevel(), locator.block.getPos());
|
||||
|
||||
if (res == null)
|
||||
return;
|
||||
if (what.equalsIgnoreCase("boulder")) // there might be more of those
|
||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getWorld());
|
||||
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getLevel());
|
||||
result[0] = BooleanValue.of(res);
|
||||
});
|
||||
return result[0];
|
||||
@@ -861,7 +857,7 @@ public class Auxiliary {
|
||||
Value retVal;
|
||||
if (fdesc.type == FileArgument.Type.NBT)
|
||||
{
|
||||
NbtElement state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
Tag state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
|
||||
if (state == null) return Value.NULL;
|
||||
retVal = new NBTSerializableValue(state);
|
||||
}
|
||||
@@ -898,7 +894,7 @@ public class Auxiliary {
|
||||
NBTSerializableValue tagValue = (val instanceof NBTSerializableValue)
|
||||
? (NBTSerializableValue) val
|
||||
: new NBTSerializableValue(val.getString());
|
||||
NbtElement tag = tagValue.getTag();
|
||||
Tag tag = tagValue.getTag();
|
||||
success = ((CarpetScriptHost) c.host).writeTagFile(tag, fdesc);
|
||||
}
|
||||
else if (fdesc.type == FileArgument.Type.JSON)
|
||||
@@ -970,17 +966,17 @@ public class Auxiliary {
|
||||
expression.addContextFunction("statistic", 3, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
ServerPlayerEntity player = EntityValue.getPlayerByValue(cc.s.getServer(), lv.get(0));
|
||||
ServerPlayer player = EntityValue.getPlayerByValue(cc.s.getServer(), lv.get(0));
|
||||
if (player == null) return Value.NULL;
|
||||
Identifier category;
|
||||
Identifier statName;
|
||||
ResourceLocation category;
|
||||
ResourceLocation statName;
|
||||
category = InputValidator.identifierOf(lv.get(1).getString());
|
||||
statName = InputValidator.identifierOf(lv.get(2).getString());
|
||||
StatType<?> type = Registry.STAT_TYPE.get(category);
|
||||
if (type == null) return Value.NULL;
|
||||
Stat<?> stat = getStat(type, statName);
|
||||
if (stat == null) return Value.NULL;
|
||||
return new NumericValue(player.getStatHandler().getStat(stat));
|
||||
return new NumericValue(player.getStats().getValue(stat));
|
||||
});
|
||||
|
||||
//handle_event('event', function...)
|
||||
@@ -1006,7 +1002,7 @@ public class Auxiliary {
|
||||
String eventName = lv.get(0).getString();
|
||||
// no such event yet
|
||||
if (CarpetEventServer.Event.getEvent(eventName, server) == null) return Value.NULL;
|
||||
ServerPlayerEntity player = null;
|
||||
ServerPlayer player = null;
|
||||
List<Value> args = Collections.emptyList();
|
||||
if (lv.size() > 1)
|
||||
{
|
||||
@@ -1024,11 +1020,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.getServer().getDataCommandStorage();
|
||||
CommandStorage storage = cc.s.getServer().getCommandStorage();
|
||||
if (lv.size() == 0)
|
||||
return ListValue.wrap(storage.getIds().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
||||
return ListValue.wrap(storage.keys().map(i -> new StringValue(nameFromRegistryId(i))).collect(Collectors.toList()));
|
||||
String key = lv.get(0).getString();
|
||||
NbtCompound old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
CompoundTag old_nbt = storage.get(InputValidator.identifierOf(key));
|
||||
if (lv.size() == 2) {
|
||||
Value nbt = lv.get(1);
|
||||
NBTSerializableValue new_nbt = (nbt instanceof NBTSerializableValue) ? (NBTSerializableValue) nbt
|
||||
@@ -1044,7 +1040,7 @@ public class Auxiliary {
|
||||
String origName = lv.get(0).getString();
|
||||
String name = InputValidator.validateSimpleString(origName, true);
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
for (String dpName : server.getDataPackManager().getNames())
|
||||
for (String dpName : server.getPackRepository().getAvailableIds())
|
||||
{
|
||||
if (dpName.equalsIgnoreCase("file/"+name+".zip") ||
|
||||
dpName.equalsIgnoreCase("file/"+name))
|
||||
@@ -1054,12 +1050,12 @@ public class Auxiliary {
|
||||
Value dpdata = lv.get(1);
|
||||
if (!(dpdata instanceof MapValue))
|
||||
throw new InternalExpressionException("datapack data needs to be a valid map type");
|
||||
ResourcePackManager packManager = server.getDataPackManager();
|
||||
Path dbFloder = server.getSavePath(WorldSavePath.DATAPACKS);
|
||||
PackRepository packManager = server.getPackRepository();
|
||||
Path dbFloder = server.getWorldPath(LevelResource.DATAPACK_DIR);
|
||||
Path packFloder = dbFloder.resolve(name+".zip");
|
||||
if (Files.exists(packFloder) || Files.exists(dbFloder.resolve(name))) return Value.NULL;
|
||||
Boolean [] successful = new Boolean[]{true};
|
||||
server.submitAndJoin( () ->
|
||||
server.executeBlocking( () ->
|
||||
{
|
||||
try {
|
||||
//Files.createDirectory(packFloder);
|
||||
@@ -1067,23 +1063,23 @@ public class Auxiliary {
|
||||
Path zipRoot = zipfs.getPath("/");
|
||||
zipValueToJson(zipRoot.resolve("pack.mcmeta"), MapValue.wrap(
|
||||
Map.of(StringValue.of("pack"), MapValue.wrap(Map.of(
|
||||
StringValue.of("pack_format"), new NumericValue(SharedConstants.getGameVersion().getPackVersion()),
|
||||
StringValue.of("pack_format"), new NumericValue(SharedConstants.getCurrentVersion().getPackVersion()),
|
||||
StringValue.of("description"), StringValue.of(name),
|
||||
StringValue.of("source"), StringValue.of("scarpet")
|
||||
)))
|
||||
));
|
||||
walkTheDPMap((MapValue) dpdata, zipRoot);
|
||||
}
|
||||
packManager.scanPacks();
|
||||
ResourcePackProfile resourcePackProfile = packManager.getProfile("file/" + name + ".zip");
|
||||
if (resourcePackProfile == null || packManager.getEnabledProfiles().contains(resourcePackProfile)) {
|
||||
packManager.reload();
|
||||
Pack resourcePackProfile = packManager.getPack("file/" + name + ".zip");
|
||||
if (resourcePackProfile == null || packManager.getSelectedPacks().contains(resourcePackProfile)) {
|
||||
throw new IOException();
|
||||
}
|
||||
List<ResourcePackProfile> list = Lists.newArrayList(packManager.getEnabledProfiles());
|
||||
resourcePackProfile.getInitialPosition().insert(list, resourcePackProfile, p -> p, false);
|
||||
List<Pack> list = Lists.newArrayList(packManager.getSelectedPacks());
|
||||
resourcePackProfile.getDefaultPosition().insert(list, resourcePackProfile, p -> p, false);
|
||||
|
||||
|
||||
server.reloadResources(list.stream().map(ResourcePackProfile::getName).collect(Collectors.toList())).
|
||||
server.reloadResources(list.stream().map(Pack::getId).collect(Collectors.toList())).
|
||||
exceptionally(exc -> {
|
||||
successful[0] = false;
|
||||
return null;
|
||||
@@ -1109,44 +1105,44 @@ public class Auxiliary {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
// from minecraft.server.Main.main
|
||||
MinecraftServer server = cc.s.getServer();
|
||||
LevelStorage.Session session = ((MinecraftServerInterface)server).getCMSession();
|
||||
DataPackSettings dataPackSettings = session.getDataPackSettings();
|
||||
ResourcePackManager resourcePackManager = server.getDataPackManager();
|
||||
DataPackSettings dataPackSettings2 = MinecraftServer.loadDataPacks(resourcePackManager, dataPackSettings == null ? DataPackSettings.SAFE_MODE : dataPackSettings, false);
|
||||
ServerResourceManager serverRM = ((MinecraftServerInterface)server).getResourceManager();
|
||||
ReloadableResourceManagerImpl resourceManager = (ReloadableResourceManagerImpl) serverRM.getResourceManager();
|
||||
LevelStorageSource.LevelStorageAccess session = ((MinecraftServerInterface)server).getCMSession();
|
||||
DataPackConfig dataPackSettings = session.getDataPacks();
|
||||
PackRepository resourcePackManager = server.getPackRepository();
|
||||
DataPackConfig dataPackSettings2 = MinecraftServer.configurePackRepository(resourcePackManager, dataPackSettings == null ? DataPackConfig.DEFAULT : dataPackSettings, false);
|
||||
ServerResources serverRM = ((MinecraftServerInterface)server).getResourceManager();
|
||||
SimpleReloadableResourceManager resourceManager = (SimpleReloadableResourceManager) serverRM.getResourceManager();
|
||||
|
||||
//believe the other one will fillup based on the datapacks only.
|
||||
resourceManager.close();
|
||||
resourcePackManager.createResourcePacks().forEach(resourceManager::addPack);
|
||||
resourcePackManager.openAllSelected().forEach(resourceManager::add);
|
||||
|
||||
//not sure its needed, but doesn't seem to have a negative effect and might be used in some custom shtuff
|
||||
serverRM.loadRegistryTags();
|
||||
serverRM.updateGlobals();
|
||||
|
||||
RegistryOps<NbtElement> registryOps = RegistryOps.of(NbtOps.INSTANCE, serverRM.getResourceManager(), (DynamicRegistryManager.Impl) server.getRegistryManager());
|
||||
SaveProperties saveProperties = session.readLevelProperties(registryOps, dataPackSettings2);
|
||||
RegistryReadOps<Tag> registryOps = RegistryReadOps.create(NbtOps.INSTANCE, serverRM.getResourceManager(), (RegistryAccess.RegistryHolder) server.registryAccess());
|
||||
WorldData saveProperties = session.getDataTag(registryOps, dataPackSettings2);
|
||||
if (saveProperties == null) return Value.NULL;
|
||||
//session.backupLevelDataFile(server.getRegistryManager(), saveProperties); // no need
|
||||
|
||||
// MinecraftServer.createWorlds
|
||||
// save properties should now contain dimension settings
|
||||
GeneratorOptions generatorOptions = saveProperties.getGeneratorOptions();
|
||||
boolean bl = generatorOptions.isDebugWorld();
|
||||
long l = generatorOptions.getSeed();
|
||||
long m = BiomeAccess.hashSeed(l);
|
||||
Map<RegistryKey<World>, ServerWorld> existing_worlds = ((MinecraftServerInterface)server).getCMWorlds();
|
||||
WorldGenSettings generatorOptions = saveProperties.worldGenSettings();
|
||||
boolean bl = generatorOptions.isDebug();
|
||||
long l = generatorOptions.seed();
|
||||
long m = BiomeManager.obfuscateSeed(l);
|
||||
Map<ResourceKey<Level>, ServerLevel> existing_worlds = ((MinecraftServerInterface)server).getCMWorlds();
|
||||
List<Value> addeds = new ArrayList<>();
|
||||
for (Map.Entry<RegistryKey<DimensionOptions>, DimensionOptions> entry : generatorOptions.getDimensions().getEntries()) {
|
||||
RegistryKey<DimensionOptions> registryKey = entry.getKey();
|
||||
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : generatorOptions.dimensions().entrySet()) {
|
||||
ResourceKey<LevelStem> registryKey = entry.getKey();
|
||||
if (!existing_worlds.containsKey(registryKey))
|
||||
{
|
||||
addeds.add(ValueConversions.of(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());
|
||||
ServerWorld serverWorld2 = new ServerWorld(server, Util.getMainWorkerExecutor(), session, unmodifiableLevelProperties, registryKey2, dimensionType3, WorldTools.NOOP_LISTENER, chunkGenerator3, bl, m, List.of(), false);
|
||||
server.getOverworld().getWorldBorder().addListener(new WorldBorderListener.WorldBorderSyncer(serverWorld2.getWorldBorder()));
|
||||
addeds.add(ValueConversions.of(registryKey.location()));
|
||||
ResourceKey<Level> registryKey2 = ResourceKey.create(Registry.DIMENSION_REGISTRY, registryKey.location());
|
||||
DimensionType dimensionType3 = entry.getValue().type();
|
||||
ChunkGenerator chunkGenerator3 = entry.getValue().generator();
|
||||
DerivedLevelData unmodifiableLevelProperties = new DerivedLevelData(saveProperties, ((ServerWorldInterface) server.overworld()).getWorldPropertiesCM());
|
||||
ServerLevel serverWorld2 = new ServerLevel(server, Util.backgroundExecutor(), session, unmodifiableLevelProperties, registryKey2, dimensionType3, WorldTools.NOOP_LISTENER, chunkGenerator3, bl, m, List.of(), false);
|
||||
server.overworld().getWorldBorder().addListener(new BorderChangeListener.DelegateBorderChangeListener(serverWorld2.getWorldBorder()));
|
||||
existing_worlds.put(registryKey2, serverWorld2);
|
||||
}
|
||||
}
|
||||
@@ -1240,14 +1236,14 @@ public class Auxiliary {
|
||||
NBTSerializableValue tagValue = (output instanceof NBTSerializableValue)
|
||||
? (NBTSerializableValue) output
|
||||
: new NBTSerializableValue(output.getString());
|
||||
NbtElement tag = tagValue.getTag();
|
||||
Tag tag = tagValue.getTag();
|
||||
Files.createDirectories(path.getParent());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (tag instanceof NbtCompound)
|
||||
NbtIo.writeCompressed((NbtCompound) tag, Files.newOutputStream(path));
|
||||
if (tag instanceof CompoundTag)
|
||||
NbtIo.writeCompressed((CompoundTag) tag, Files.newOutputStream(path));
|
||||
}
|
||||
catch (Throwable shitHappened)
|
||||
{
|
||||
@@ -1282,11 +1278,11 @@ public class Auxiliary {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> Stat<T> getStat(StatType<T> type, Identifier id)
|
||||
private static <T> Stat<T> getStat(StatType<T> type, ResourceLocation id)
|
||||
{
|
||||
T key = type.getRegistry().get(id);
|
||||
if (key == null || !type.hasStat(key))
|
||||
if (key == null || !type.contains(key))
|
||||
return null;
|
||||
return type.getOrCreateStat(key);
|
||||
return type.get(key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user