its a doozie

This commit is contained in:
gnembon committed 2021-03-24 10:35:52 -03:00
1 parent 365892b9ca
commit ab553187c5
43 files changed
+356 -351

No files matched your search

@@ -29,7 +29,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@@ -60,7 +60,7 @@ public class CarpetScriptHost extends ScriptHost
private final CarpetScriptServer scriptServer;
ServerCommandSource responsibleSource;
private Tag globalState;
private NbtElement globalState;
private int saveTimeout;
public boolean persistenceRequired;
@@ -789,12 +789,12 @@ public class CarpetScriptHost extends ScriptHost
Module.saveData(main, globalState);
}
private Tag loadState()
private NbtElement loadState()
{
return Module.getData(main);
}
public Tag readFileTag(FileArgument fdesc)
public NbtElement readFileTag(FileArgument fdesc)
{
if (getName() == null && !fdesc.isShared) return null;
if (fdesc.resource != null)
@@ -804,7 +804,7 @@ public class CarpetScriptHost extends ScriptHost
return ((CarpetScriptHost)parent).globalState;
}
public boolean writeTagFile(Tag tag, FileArgument fdesc)
public boolean writeTagFile(NbtElement tag, FileArgument fdesc)
{
if (getName() == null && !fdesc.isShared) return false; // if belongs to an app, cannot be default host.
+13 -13
View File
@@ -51,11 +51,11 @@ 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;
@@ -459,7 +459,7 @@ public class Auxiliary {
expression.addLazyFunction("escape_nbt", 1, (c, t, lv) -> {
Value v = lv.get(0).evalValue(c);
String string = v.getString();
Value ret = new StringValue(StringTag.escape(string));
Value ret = new StringValue(NbtString.escape(string));
return (cc, tt) -> ret;
});
@@ -482,8 +482,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 new NumericValue(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
});
@@ -492,7 +492,7 @@ public class Auxiliary {
if (argSize==0 || argSize > 2) throw new InternalExpressionException("'encode_nbt' requires 1 or 2 parameters");
Value v = lv.get(0).evalValue(c);
boolean force = (argSize > 1) && lv.get(1).evalValue(c).getBoolean();
Tag tag;
NbtElement tag;
try
{
tag = v.toTag(force);
@@ -877,7 +877,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 LazyValue.NULL;
retVal = new NBTSerializableValue(state);
}
@@ -916,7 +916,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)
@@ -963,7 +963,7 @@ public class Auxiliary {
boolean shared = lv.size() > 1 && lv.get(1).evalValue(c).getBoolean();
fdesc = new FileArgument(resource, FileArgument.Type.NBT, null, false, shared, FileArgument.Reason.READ);
}
Tag state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
NbtElement state = ((CarpetScriptHost) c.host).readFileTag(fdesc);
if (state == null)
return (cc, tt) -> Value.NULL;
Value retVal = new NBTSerializableValue(state);
@@ -986,7 +986,7 @@ public class Auxiliary {
NBTSerializableValue tagValue = (val instanceof NBTSerializableValue)
? (NBTSerializableValue) val
: new NBTSerializableValue(val.getString());
Tag tag = tagValue.getTag();
NbtElement tag = tagValue.getTag();
boolean success = ((CarpetScriptHost) c.host).writeTagFile(tag, fdesc);
return success?LazyValue.TRUE:LazyValue.FALSE;
});
@@ -1074,7 +1074,7 @@ public class Auxiliary {
return (_c, _t) -> ret;
}
String key = lv.get(0).evalValue(c).getString();
CompoundTag old_nbt = storage.get(new Identifier(key));
NbtCompound old_nbt = storage.get(new Identifier(key));
if (lv.size() == 2) {
Value nbt = lv.get(1).evalValue(c);
NBTSerializableValue new_nbt = (nbt instanceof NBTSerializableValue) ? (NBTSerializableValue) nbt
@@ -1170,7 +1170,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 LazyValue.NULL;
//session.backupLevelDataFile(server.getRegistryManager(), saveProperties); // no need
@@ -21,7 +21,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;
@@ -140,7 +140,7 @@ public class Entities {
Vector3Argument position = Vector3Argument.findIn(cc, 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)
{
@@ -25,7 +25,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;
@@ -35,6 +35,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;
@@ -97,7 +98,7 @@ public class Inventories {
return (_c, _t) -> ret;
}
String tag = lv.get(1).evalValue(c).getString();
net.minecraft.tag.Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(new Identifier(tag));
Tag<Item> itemTag = tagManager.getOrCreateTagGroup(Registry.ITEM_KEY).getTag(new Identifier(tag));
if (itemTag == null) return LazyValue.NULL;
return itemTag.contains(item)?LazyValue.TRUE:LazyValue.FALSE;
});
@@ -277,7 +278,7 @@ public class Inventories {
syncPlayerInventory(inventoryLocator, slot);
return (_c, _t) -> ListValue.fromItemStack(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).evalValue(c);
@@ -59,8 +59,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.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ChunkTicket;
import net.minecraft.server.world.ChunkTicketType;
@@ -70,6 +70,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;
@@ -289,7 +290,7 @@ public class WorldAccess {
{
throw new InternalExpressionException("Block requires at least one parameter");
}
CompoundTag tag = BlockArgument.findIn(cc, lv, 0, true).block.getData();
NbtCompound tag = BlockArgument.findIn(cc, lv, 0, true).block.getData();
if (tag == null)
return (c_, t_) -> Value.NULL;
Value retval = new NBTSerializableValue(tag);
@@ -756,7 +757,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<>();
@@ -815,7 +816,7 @@ public class WorldAccess {
}
if (data == null) data = sourceLocator.block.getData();
CompoundTag finalData = data;
NbtCompound finalData = data;
if (sourceBlockState == targetBlockState && data == null)
return (c_, t_) -> Value.FALSE;
@@ -831,7 +832,7 @@ 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());
@@ -875,7 +876,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");
@@ -937,7 +938,7 @@ public class WorldAccess {
return (c_, t_) -> Value.TRUE;
if (toolBroke)
return LazyValue.NULL;
Tag outtag = tool.getTag();
NbtElement outtag = tool.getTag();
if (outtag == null)
return LazyValue.TRUE;
Value ret = new NBTSerializableValue(() -> outtag);
@@ -1130,7 +1131,7 @@ public class WorldAccess {
return (_c, _t) -> ret;
}
String tag = lv.get(blockLocator.offset).evalValue(c).getString();
net.minecraft.tag.Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(new Identifier(tag));
Tag<Block> blockTag = tagManager.getOrCreateTagGroup(Registry.BLOCK_KEY).getTag(new Identifier(tag));
if (blockTag == null) return LazyValue.NULL;
return blockLocator.block.getBlockState().isIn(blockTag)?LazyValue.TRUE:LazyValue.FALSE;
});
@@ -1354,7 +1355,7 @@ public class WorldAccess {
return;
}
StructureStart<?> start = structures.get(structure);
ChunkPos structureChunkPos = start.method_34000(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
ChunkPos structureChunkPos = start.getPos(); // new ChunkPos(start.getChunkX(), start.getChunkZ());
BlockBox box = start.getBoundingBox();
for (int chx = box.minX / 16; chx <= box.maxX / 16; chx++)
{
@@ -15,11 +15,11 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtTagSizeTracker;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.TagReaders;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtTypes;
import net.minecraft.util.WorldSavePath;
import net.minecraft.util.crash.CrashException;
import org.apache.commons.io.FilenameUtils;
@@ -302,7 +302,7 @@ public class FileArgument
return true;
}
public Tag getNbtData(Module module) // aka getData
public NbtElement getNbtData(Module module) // aka getData
{
try { synchronized (writeIOSync) {
Path dataFile = toPath(module);
@@ -316,7 +316,7 @@ public class FileArgument
//copied private method from net.minecraft.nbt.NbtIo.read()
// to read non-compound tags - these won't be compressed
public static Tag readTag(Path path)
public static NbtElement readTag(Path path)
{
try
{
@@ -346,7 +346,7 @@ public class FileArgument
else
{
dataInput_1.readUTF();
return TagReaders.of(byte_1).read(dataInput_1, 0, NbtTagSizeTracker.EMPTY);
return NbtTypes.byId(byte_1).read(dataInput_1, 0, NbtTagSizeTracker.EMPTY);
}
}
catch (IOException ignored)
@@ -361,7 +361,7 @@ public class FileArgument
}
}
public boolean saveNbtData(Module module, Tag tag) // aka saveData
public boolean saveNbtData(Module module, NbtElement tag) // aka saveData
{
try { synchronized (writeIOSync) {
Path dataFile = toPath(module);
@@ -376,7 +376,7 @@ public class FileArgument
}
//copied private method from net.minecraft.nbt.NbtIo.write() and client method safe_write
public static boolean writeTagDisk(Tag tag_1, Path path, boolean zipped)
public static boolean writeTagDisk(NbtElement tag_1, Path path, boolean zipped)
{
Path original = path;
try
@@ -387,9 +387,9 @@ public class FileArgument
Files.deleteIfExists(path);
}
if (tag_1 instanceof CompoundTag)
if (tag_1 instanceof NbtCompound)
{
NbtIo.writeCompressed((CompoundTag) tag_1, Files.newOutputStream(path));
NbtIo.writeCompressed((NbtCompound) tag_1, Files.newOutputStream(path));
}
else
{
@@ -2,7 +2,7 @@ package carpet.script.bundled;
import carpet.CarpetServer;
import carpet.script.argument.FileArgument;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
import net.minecraft.util.WorldSavePath;
import java.nio.file.Files;
@@ -14,7 +14,7 @@ public abstract class Module
public abstract String getCode();
public abstract boolean isLibrary();
public static Tag getData(Module module)
public static NbtElement getData(Module module)
{
Path dataFile = resolveResource(module);
if (dataFile == null) return null;
@@ -22,7 +22,7 @@ public abstract class Module
synchronized (FileArgument.writeIOSync) { return FileArgument.readTag(dataFile); }
}
public static void saveData(Module module, Tag globalState)
public static void saveData(Module module, NbtElement globalState)
{
Path dataFile = resolveResource(module);
if (dataFile == null) return;
@@ -22,14 +22,14 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.command.argument.ParticleEffectArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtByte;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtDouble;
import net.minecraft.nbt.NbtFloat;
import net.minecraft.nbt.NbtInt;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@@ -123,7 +123,7 @@ public class ShapeDispatcher
if (!clientPlayers.isEmpty())
{
ListTag tag = new ListTag();
NbtList tag = new NbtList();
int tagcount = 0;
for (Pair<ExpiringShape, Map<String, Value>> s : shapes)
{
@@ -131,12 +131,12 @@ public class ShapeDispatcher
if (tagcount++>1000)
{
tagcount = 0;
Tag finalTag = tag;
NbtElement finalTag = tag;
clientPlayers.forEach( p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
tag = new ListTag();
tag = new NbtList();
}
}
Tag finalTag = tag;
NbtElement finalTag = tag;
if (tag.size() > 0) clientPlayers.forEach( p -> ServerNetworkHandler.sendCustomCommand(p, "scShapes", finalTag));
}
if (!alternativePlayers.isEmpty())
@@ -194,7 +194,7 @@ public class ShapeDispatcher
}
// client
public static ExpiringShape fromTag(CompoundTag tag)
public static ExpiringShape fromTag(NbtCompound tag)
{
Map<String, Value> options = new HashMap<>();
for (String key : tag.getKeys())
@@ -265,11 +265,11 @@ public class ShapeDispatcher
protected ExpiringShape() { }
public static CompoundTag toTag(Map<String, Value> params)
public static NbtCompound toTag(Map<String, Value> params)
{
CompoundTag tag = new CompoundTag();
NbtCompound tag = new NbtCompound();
params.forEach((k, v) -> {
Tag valTag = Param.of.get(k).toTag(v);
NbtElement valTag = Param.of.get(k).toTag(v);
if (valTag != null) tag.put(k, valTag);
});
return tag;
@@ -890,9 +890,9 @@ public class ShapeDispatcher
this.id = id;
}
public abstract Tag toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
public abstract NbtElement toTag(Value value); //validates value, returning null if not necessary to keep it and serialize
public abstract Value validate(Map<String, Value> options, CarpetContext cc, Value value); // makes sure the value is proper
public abstract Value decode(Tag tag);
public abstract Value decode(NbtElement tag);
}
public abstract static class StringParam extends Param
@@ -900,8 +900,8 @@ public class ShapeDispatcher
protected StringParam(String id) { super(id); }
@Override
public Tag toTag(Value value) { return StringTag.of(value.getString()); }
public Value decode(Tag tag) { return new StringValue(tag.asString()); }
public NbtElement toTag(Value value) { return NbtString.of(value.getString()); }
public Value decode(NbtElement tag) { return new StringValue(tag.asString()); }
}
public static class TextParam extends StringParam
{
@@ -931,15 +931,15 @@ public class ShapeDispatcher
}
@Override
public Tag toTag(Value value)
public NbtElement toTag(Value value)
{
if (!(value instanceof FormattedTextValue))
value = new FormattedTextValue(new LiteralText(value.getString()));
return StringTag.of(((FormattedTextValue)value).serialize());
return NbtString.of(((FormattedTextValue)value).serialize());
}
@Override
public Value decode(Tag tag)
public Value decode(NbtElement tag)
{
return FormattedTextValue.deserialize(tag.asString());
}
@@ -1004,24 +1004,24 @@ public class ShapeDispatcher
}
@Override
public Tag toTag(Value value)
public NbtElement toTag(Value value)
{
return ByteTag.of(value.getBoolean());
return NbtByte.of(value.getBoolean());
}
@Override
public Value decode(Tag tag)
public Value decode(NbtElement tag)
{
return new NumericValue(((ByteTag) tag).getByte() > 0);
return new NumericValue(((NbtByte) tag).byteValue() > 0);
}
}
public static class FloatParam extends NumericParam
{
protected FloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
@Override
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
}
public static abstract class PositiveParam extends NumericParam
@@ -1038,27 +1038,27 @@ public class ShapeDispatcher
{
protected PositiveFloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
@Override
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
}
public static class PositiveIntParam extends PositiveParam
{
protected PositiveIntParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
@Override
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
}
public static class NonNegativeIntParam extends NumericParam
{
protected NonNegativeIntParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
@Override
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
@Override public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
Value ret = super.validate(options, cc, value);
@@ -1070,9 +1070,9 @@ public class ShapeDispatcher
{
protected NonNegativeFloatParam(String id) { super(id); }
@Override
public Value decode(Tag tag) { return new NumericValue(((FloatTag)tag).getFloat()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtFloat)tag).floatValue()); }
@Override
public Tag toTag(Value value) { return FloatTag.of(NumericValue.asNumber(value, id).getFloat()); }
public NbtElement toTag(Value value) { return NbtFloat.of(NumericValue.asNumber(value, id).getFloat()); }
@Override public Value validate(Map<String, Value> options, CarpetContext cc, Value value)
{
Value ret = super.validate(options, cc, value);
@@ -1137,9 +1137,9 @@ public class ShapeDispatcher
throw new InternalExpressionException("'"+p.id+"' requires a triple, block or entity to indicate position");
}
public Value decode(Tag tag)
public Value decode(NbtElement tag)
{
ListTag ctag = (ListTag)tag;
NbtList ctag = (NbtList)tag;
return ListValue.of(
new NumericValue(ctag.getDouble(0)),
new NumericValue(ctag.getDouble(1)),
@@ -1147,13 +1147,13 @@ public class ShapeDispatcher
);
}
@Override
public Tag toTag(Value value)
public NbtElement toTag(Value value)
{
List<Value> lv = ((ListValue)value).getItems();
ListTag tag = new ListTag();
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
NbtList tag = new NbtList();
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
return tag;
}
}
@@ -1175,13 +1175,13 @@ public class ShapeDispatcher
return ListValue.wrap(points);
}
public Value decode(Tag tag)
public Value decode(NbtElement tag)
{
ListTag ltag = (ListTag)tag;
NbtList ltag = (NbtList)tag;
List<Value> points = new ArrayList<>();
for (int i=0, ll = ltag.size(); i<ll; i++)
{
ListTag ptag = ltag.getList(i);
NbtList ptag = ltag.getList(i);
points.add(ListValue.of(
new NumericValue(ptag.getDouble(0)),
new NumericValue(ptag.getDouble(1)),
@@ -1191,17 +1191,17 @@ public class ShapeDispatcher
return ListValue.wrap(points);
}
@Override
public Tag toTag(Value pointsValue)
public NbtElement toTag(Value pointsValue)
{
List<Value> lv = ((ListValue)pointsValue).getItems();
ListTag ltag = new ListTag();
NbtList ltag = new NbtList();
for (Value value : lv)
{
List<Value> coords = ((ListValue)value).getItems();
ListTag tag = new ListTag();
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
tag.add(DoubleTag.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
NbtList tag = new NbtList();
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(0), "x").getDouble()));
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(1), "y").getDouble()));
tag.add(NbtDouble.of(NumericValue.asNumber(lv.get(2), "z").getDouble()));
ltag.add(tag);
}
return ltag;
@@ -1216,9 +1216,9 @@ public class ShapeDispatcher
super(id);
}
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
@Override
public Tag toTag(Value value) { return IntTag.of(NumericValue.asNumber(value, id).getInt()); }
public NbtElement toTag(Value value) { return NbtInt.of(NumericValue.asNumber(value, id).getInt()); }
}
public static class EntityParam extends Param
@@ -1227,9 +1227,9 @@ public class ShapeDispatcher
protected EntityParam(String id) { super(id); }
@Override
public Tag toTag(Value value)
public NbtElement toTag(Value value)
{
return IntTag.of(NumericValue.asNumber(value, id).getInt());
return NbtInt.of(NumericValue.asNumber(value, id).getInt());
}
@Override
@@ -1242,7 +1242,7 @@ public class ShapeDispatcher
return new NumericValue(player.getId());
}
public Value decode(Tag tag) { return new NumericValue(((IntTag)tag).getInt()); }
public Value decode(NbtElement tag) { return new NumericValue(((NbtInt)tag).intValue()); }
}
private static boolean isStraight(Vec3d from, Vec3d to, double density)
@@ -14,8 +14,8 @@ import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@@ -60,7 +60,7 @@ public class ShapesRenderer
long currentTime = client.world.getTime();
RenderSystem.disableTexture();
RenderSystem.enableDepthTest();
RenderSystem.setShader(GameRenderer::method_34540);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.depthFunc(515);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
@@ -122,7 +122,7 @@ public class ShapesRenderer
RenderSystem.enableTexture();
}
public void addShapes(ListTag tag)
public void addShapes(NbtList tag)
{
for (int i=0, count = tag.size(); i < count; i++)
{
@@ -130,7 +130,7 @@ public class ShapesRenderer
}
}
public void addShape(CompoundTag tag)
public void addShape(NbtCompound tag)
{
ShapeDispatcher.ExpiringShape shape = ShapeDispatcher.fromTag(tag);
if (shape == null) return;
@@ -13,9 +13,9 @@ import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.Property;
import net.minecraft.util.dynamic.GlobalPos;
@@ -45,7 +45,7 @@ public class BlockValue extends Value
private BlockState blockState;
private final BlockPos pos;
private final ServerWorld world;
private CompoundTag data;
private NbtCompound data;
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
{
@@ -63,9 +63,9 @@ public class BlockValue extends Value
BlockArgumentParser blockstateparser = (new BlockArgumentParser(new StringReader(str), false)).parse(true);
if (blockstateparser.getBlockState() != null)
{
CompoundTag bd = blockstateparser.getNbtData();
NbtCompound bd = blockstateparser.getNbtData();
if (bd == null)
bd = new CompoundTag();
bd = new NbtCompound();
bv = new BlockValue(blockstateparser.getBlockState(), null, null, bd );
if (bvCache.size()>10000)
bvCache.clear();
@@ -107,7 +107,7 @@ public class BlockValue extends Value
}
public CompoundTag getData()
public NbtCompound getData()
{
if (data != null)
{
@@ -118,7 +118,7 @@ public class BlockValue extends Value
if (world != null && pos != null)
{
BlockEntity be = getBlockEntity(world, pos);
CompoundTag tag = new CompoundTag();
NbtCompound tag = new NbtCompound();
if (be == null)
{
data = tag;
@@ -139,7 +139,7 @@ public class BlockValue extends Value
data = null;
}
public BlockValue(BlockState state, ServerWorld world, BlockPos position, CompoundTag nbt)
public BlockValue(BlockState state, ServerWorld world, BlockPos position, NbtCompound nbt)
{
this.world = world;
blockState = state;
@@ -188,26 +188,26 @@ public class BlockValue extends Value
public ServerWorld getWorld() { return world;}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
// follows falling block convertion
CompoundTag tag = new CompoundTag();
CompoundTag state = new CompoundTag();
NbtCompound tag = new NbtCompound();
NbtCompound state = new NbtCompound();
BlockState s = getBlockState();
state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
state.put("Name", NbtString.of(Registry.BLOCK.getId(s.getBlock()).toString()));
Collection<Property<?>> properties = s.getProperties();
if (!properties.isEmpty())
{
CompoundTag props = new CompoundTag();
NbtCompound props = new NbtCompound();
for (Property<?> p: properties)
{
props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
props.put(p.getName(), NbtString.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
}
state.put("Properties", props);
}
tag.put("BlockState", state);
CompoundTag dataTag = getData();
NbtCompound dataTag = getData();
if (dataTag != null)
{
tag.put("TileEntityData", dataTag);
@@ -2,8 +2,8 @@ package carpet.script.value;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtByte;
import net.minecraft.nbt.NbtElement;
public class BooleanValue extends NumericValue
{
@@ -47,8 +47,8 @@ public class BooleanValue extends NumericValue
}
@Override
public Tag toTag(boolean force) {
return ByteTag.of(boolValue);
public NbtElement toTag(boolean force) {
return NbtByte.of(boolValue);
}
@Override
@@ -27,8 +27,8 @@ import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
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.s2c.play.EntityPassengersSetS2CPacket;
import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket;
import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket;
@@ -49,12 +49,13 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.passive.PassiveEntity;
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.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.Tag;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypeFilter;
@@ -241,7 +242,7 @@ public class EntityValue extends Value
positive = false;
who = who.substring(1);
}
net.minecraft.tag.Tag<EntityType<?>> eTag = server.getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(who));
Tag<EntityType<?>> eTag = server.getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(who));
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor");
if (positive)
{
@@ -450,7 +451,7 @@ public class EntityValue extends Value
put("has_scoreboard_tag", (e, a) -> new NumericValue(e.getScoreboardTags().contains(a.getString())));
put("has_entity_tag", (e, a) -> {
net.minecraft.tag.Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
Tag<EntityType<?>> tag = e.getServer().getTagManager().getOrCreateTagGroup(Registry.ENTITY_TYPE_KEY).getTag(new Identifier(a.getString()));
if (tag == null) return Value.NULL;
return new NumericValue(e.getType().isIn(tag));
});
@@ -841,7 +842,7 @@ public class EntityValue extends Value
});
put("nbt",(e, a) -> {
CompoundTag nbttagcompound = e.writeNbt((new CompoundTag()));
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
if (a==null)
return new NBTSerializableValue(nbttagcompound);
return new NBTSerializableValue(nbttagcompound).get(a);
@@ -1470,7 +1471,7 @@ public class EntityValue extends Value
Value tagValue = NBTSerializableValue.fromValue(v);
if (tagValue instanceof NBTSerializableValue)
{
CompoundTag nbttagcompound = e.writeNbt((new CompoundTag()));
NbtCompound nbttagcompound = e.writeNbt((new NbtCompound()));
nbttagcompound.copyFrom(((NBTSerializableValue) tagValue).getCompoundTag());
e.readNbt(nbttagcompound);
e.setUuid(uUID);
@@ -1493,12 +1494,12 @@ public class EntityValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
CompoundTag tag = new CompoundTag();
tag.put("Data", getEntity().writeNbt( new CompoundTag()));
tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
NbtCompound tag = new NbtCompound();
tag.put("Data", getEntity().writeNbt( new NbtCompound()));
tag.put("Name", NbtString.of(Registry.ENTITY_TYPE.getId(getEntity().getType()).toString()));
return tag;
}
}
@@ -1,7 +1,7 @@
package carpet.script.value;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import net.minecraft.text.BaseText;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@@ -70,10 +70,10 @@ public class FormattedTextValue extends StringValue
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
return StringTag.of(Text.Serializer.toJson(text));
return NbtString.of(Text.Serializer.toJson(text));
}
@Override
@@ -1,6 +1,6 @@
package carpet.script.value;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
public abstract class FrameworkValue extends Value
{
@@ -29,7 +29,7 @@ public abstract class FrameworkValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
throw new UnsupportedOperationException("Scarpet language component cannot be serialized to the tag");
}
@@ -1,7 +1,7 @@
package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
public class FunctionAnnotationValue extends Value
{
@@ -35,7 +35,7 @@ public class FunctionAnnotationValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
throw new UnsupportedOperationException("Global value cannot be serialized to the tag");
}
@@ -12,8 +12,8 @@ import carpet.script.exception.ExpressionException;
import carpet.script.exception.InternalExpressionException;
import carpet.script.exception.ReturnStatement;
import carpet.script.exception.ThrowStatement;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import java.util.ArrayList;
import java.util.Collections;
@@ -246,10 +246,10 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
public String getVarArgs() {return varArgs; }
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
return StringTag.of(getString());
return NbtString.of(getString());
}
public void assertArgsOk(List<?> list, Consumer<Boolean> feedback)
@@ -1,8 +1,8 @@
package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import java.util.ArrayList;
import java.util.Iterator;
@@ -199,9 +199,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
return StringTag.of(getString());
return NbtString.of(getString());
}
}
@@ -5,14 +5,14 @@ import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.AbstractNumberTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.AbstractNbtNumber;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtDouble;
import net.minecraft.nbt.NbtInt;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtLong;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import java.util.ArrayList;
import java.util.Arrays;
@@ -481,31 +481,31 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
LIST,
MAP,
STRING;
private static TagTypeCompat getType(Tag tag)
private static TagTypeCompat getType(NbtElement tag)
{
if (tag instanceof IntTag) return INT;
if (tag instanceof LongTag) return LONG;
if (tag instanceof DoubleTag) return DBL;
if (tag instanceof ListTag) return LIST;
if (tag instanceof CompoundTag) return MAP;
if (tag instanceof NbtInt) return INT;
if (tag instanceof NbtLong) return LONG;
if (tag instanceof NbtDouble) return DBL;
if (tag instanceof NbtList) return LIST;
if (tag instanceof NbtCompound) return MAP;
return STRING;
}
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
int argSize = items.size();
if (argSize == 0) return new ListTag();
ListTag tag = new ListTag();
if (argSize == 0) return new NbtList();
NbtList tag = new NbtList();
if (argSize ==1)
{
tag.add(items.get(0).toTag(force));
return tag;
}
// figuring out the types
List<Tag> tags= new ArrayList<>();
List<NbtElement> tags= new ArrayList<>();
items.forEach(v -> tags.add(v.toTag(force)));
Set<TagTypeCompat> cases = EnumSet.noneOf(TagTypeCompat.class);
tags.forEach(t -> cases.add(TagTypeCompat.getType(t)));
@@ -519,17 +519,17 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|| cases.contains(TagTypeCompat.STRING)) // incompatible types
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
tags.forEach(t -> tag.add(StringTag.of(t.asString())));
tags.forEach(t -> tag.add(NbtString.of(t.asString())));
return tag;
}
// only numbers / mixed types
if (cases.contains(TagTypeCompat.DBL))
{
tags.forEach(t -> tag.add(DoubleTag.of(((AbstractNumberTag)t).getDouble())));
tags.forEach(t -> tag.add(NbtDouble.of(((AbstractNbtNumber)t).doubleValue())));
}
else
{
tags.forEach(t -> tag.add(LongTag.of(((AbstractNumberTag)t).getLong())));
tags.forEach(t -> tag.add(NbtLong.of(((AbstractNbtNumber)t).longValue())));
}
return tag;
}
@@ -3,8 +3,8 @@ package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import java.util.ArrayList;
import java.util.Collections;
@@ -254,9 +254,9 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
CompoundTag tag = new CompoundTag() ;
NbtCompound tag = new NbtCompound() ;
map.forEach( (k, v) ->
{
if (!force && !(k instanceof StringValue)) throw new NBTSerializableValue.IncompatibleTypeException(k);
@@ -25,13 +25,13 @@ import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.AbstractListTag;
import net.minecraft.nbt.AbstractNumberTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.AbstractNbtList;
import net.minecraft.nbt.AbstractNbtNumber;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
@@ -53,8 +53,8 @@ import java.util.stream.Collectors;
public class NBTSerializableValue extends Value implements ContainerValueInterface
{
private String nbtString = null;
private Tag nbtTag = null;
private Supplier<Tag> nbtSupplier = null;
private NbtElement nbtTag = null;
private Supplier<NbtElement> nbtSupplier = null;
private boolean owned = false;
private NBTSerializableValue() {}
@@ -65,7 +65,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
{
try
{
return (new StringNbtReader(new StringReader(nbtString))).parseTag();
return (new StringNbtReader(new StringReader(nbtString))).parseElement();
}
catch (CommandSyntaxException e)
{
@@ -75,13 +75,13 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
owned = true;
}
public NBTSerializableValue(Tag tag)
public NBTSerializableValue(NbtElement tag)
{
nbtTag = tag;
owned = true;
}
public NBTSerializableValue(Supplier<Tag> tagSupplier)
public NBTSerializableValue(Supplier<NbtElement> tagSupplier)
{
nbtSupplier = tagSupplier;
}
@@ -108,10 +108,10 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
public static NBTSerializableValue parseString(String nbtString, boolean fail)
{
Tag tag;
NbtElement tag;
try
{
tag = (new StringNbtReader(new StringReader(nbtString))).parseTag();
tag = (new StringNbtReader(new StringReader(nbtString))).parseElement();
}
catch (CommandSyntaxException e)
{
@@ -276,7 +276,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
return parseItem(itemString, null);
}
public static ItemStackArgument parseItem(String itemString, CompoundTag customTag)
public static ItemStackArgument parseItem(String itemString, NbtCompound customTag)
{
try
{
@@ -313,12 +313,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
return slot;
}
private static Value decodeTag(Tag t)
private static Value decodeTag(NbtElement t)
{
if (t instanceof CompoundTag)
if (t instanceof NbtCompound)
return new NBTSerializableValue(() -> t);
if (t instanceof AbstractNumberTag)
return new NumericValue(((AbstractNumberTag) t).getDouble());
if (t instanceof AbstractNbtNumber)
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
// more can be done here
return new StringValue(t.asString());
}
@@ -338,35 +338,35 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
}
private static Value decodeTagDeep(Tag t)
private static Value decodeTagDeep(NbtElement t)
{
if (t instanceof CompoundTag)
if (t instanceof NbtCompound)
{
Map<Value, Value> pairs = new HashMap<>();
CompoundTag ctag = (CompoundTag)t;
NbtCompound ctag = (NbtCompound)t;
for (String key: ctag.getKeys())
{
pairs.put(new StringValue(key), decodeTagDeep(ctag.get(key)));
}
return MapValue.wrap(pairs);
}
if (t instanceof AbstractListTag)
if (t instanceof AbstractNbtList)
{
List<Value> elems = new ArrayList<>();
AbstractListTag<? extends Tag> ltag = (AbstractListTag<? extends Tag>)t;
for (Tag elem: ltag)
AbstractNbtList<? extends NbtElement> ltag = (AbstractNbtList<? extends NbtElement>)t;
for (NbtElement elem: ltag)
{
elems.add(decodeTagDeep(elem));
}
return ListValue.wrap(elems);
}
if (t instanceof AbstractNumberTag)
return new NumericValue(((AbstractNumberTag) t).getDouble());
if (t instanceof AbstractNbtNumber)
return new NumericValue(((AbstractNbtNumber) t).doubleValue());
// more can be done here
return new StringValue(t.asString());
}
public Tag getTag()
public NbtElement getTag()
{
if (nbtTag == null)
nbtTag = nbtSupplier.get();
@@ -392,24 +392,24 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
@Override
public boolean getBoolean()
{
Tag tag = getTag();
if (tag instanceof CompoundTag)
return !((CompoundTag) tag).isEmpty();
if (tag instanceof AbstractListTag)
return ((AbstractListTag) tag).isEmpty();
if (tag instanceof AbstractNumberTag)
return ((AbstractNumberTag) tag).getDouble()!=0.0;
if (tag instanceof StringTag)
NbtElement tag = getTag();
if (tag instanceof NbtCompound)
return !((NbtCompound) tag).isEmpty();
if (tag instanceof AbstractNbtList)
return ((AbstractNbtList) tag).isEmpty();
if (tag instanceof AbstractNbtNumber)
return ((AbstractNbtNumber) tag).doubleValue()!=0.0;
if (tag instanceof NbtString)
return tag.asString().isEmpty();
return true;
}
public CompoundTag getCompoundTag()
public NbtCompound getCompoundTag()
{
try
{
ensureOwnership();
return (CompoundTag) getTag();
return (NbtCompound) getTag();
}
catch (ClassCastException e)
{
@@ -429,7 +429,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
/// WIP
ensureOwnership();
NbtPathArgumentType.NbtPath path = cachePath(where.getString());
Tag tagToInsert = value instanceof NBTSerializableValue ?
NbtElement tagToInsert = value instanceof NBTSerializableValue ?
((NBTSerializableValue) value).getTag() :
new NBTSerializableValue(value.getString()).getTag();
boolean modifiedTag;
@@ -459,17 +459,17 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement)
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement)
{
return modify_insert(index, nbtPath, newElement, this.getTag());
}
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, Tag newElement, Tag currentTag)
private boolean modify_insert(int index, NbtPathArgumentType.NbtPath nbtPath, NbtElement newElement, NbtElement currentTag)
{
Collection<Tag> targets;
Collection<NbtElement> targets;
try
{
targets = nbtPath.getOrInit(currentTag, ListTag::new);
targets = nbtPath.getOrInit(currentTag, NbtList::new);
}
catch (CommandSyntaxException e)
{
@@ -477,16 +477,16 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
}
boolean modified = false;
for (Tag target : targets)
for (NbtElement target : targets)
{
if (!(target instanceof AbstractListTag))
if (!(target instanceof AbstractNbtList))
{
continue;
}
try
{
AbstractListTag<?> targetList = (AbstractListTag) target;
if (!targetList.addTag(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
AbstractNbtList<?> targetList = (AbstractNbtList) target;
if (!targetList.addElement(index < 0 ? targetList.size() + index + 1 : index, newElement.copy()))
return false;
modified = true;
}
@@ -498,22 +498,22 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
}
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
private boolean modify_merge(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
{
if (!(replacement instanceof CompoundTag))
if (!(replacement instanceof NbtCompound))
{
return false;
}
Tag ownTag = getTag();
NbtElement ownTag = getTag();
try
{
for (Tag target : nbtPath.getOrInit(ownTag, CompoundTag::new))
for (NbtElement target : nbtPath.getOrInit(ownTag, NbtCompound::new))
{
if (!(target instanceof CompoundTag))
if (!(target instanceof NbtCompound))
{
continue;
}
((CompoundTag) target).copyFrom((CompoundTag) replacement);
((NbtCompound) target).copyFrom((NbtCompound) replacement);
}
}
catch (CommandSyntaxException ignored)
@@ -523,9 +523,9 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
return true;
}
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, Tag replacement) //nbtPathArgumentType$NbtPath_1, list_1)
private boolean modify_replace(NbtPathArgumentType.NbtPath nbtPath, NbtElement replacement) //nbtPathArgumentType$NbtPath_1, list_1)
{
Tag tag = getTag();
NbtElement tag = getTag();
String pathText = nbtPath.toString();
if (pathText.endsWith("]")) // workaround for array replacement or item in the array replacement
{
@@ -572,7 +572,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
NbtPathArgumentType.NbtPath path = cachePath(value.getString());
try
{
List<Tag> tags = path.get(getTag());
List<NbtElement> tags = path.get(getTag());
if (tags.size()==0)
return Value.NULL;
if (tags.size()==1)
@@ -669,7 +669,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
ensureOwnership();
@@ -4,8 +4,8 @@ import java.util.ArrayList;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
public class NullValue extends NumericValue // TODO check nonsingleton code
{
@@ -80,10 +80,10 @@ public class NullValue extends NumericValue // TODO check nonsingleton code
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
return StringTag.of("null");
return NbtString.of("null");
}
@Override
@@ -3,10 +3,10 @@ package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtDouble;
import net.minecraft.nbt.NbtInt;
import net.minecraft.nbt.NbtLong;
import net.minecraft.nbt.NbtElement;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
@@ -271,20 +271,20 @@ public class NumericValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (longValue != null)
return LongTag.of(longValue);
return NbtLong.of(longValue);
long lv = getLong();
if (value == (double)lv)
{
if (abs(value) < Integer.MAX_VALUE-2)
return IntTag.of((int)lv);
return LongTag.of(getLong());
return NbtInt.of((int)lv);
return NbtLong.of(getLong());
}
else
{
return DoubleTag.of(value);
return NbtDouble.of(value);
}
}
@@ -1,7 +1,7 @@
package carpet.script.value;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtString;
import net.minecraft.nbt.NbtElement;
public class StringValue extends Value
{
@@ -43,8 +43,8 @@ public class StringValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
return StringTag.of(str);
return NbtString.of(str);
}
}
@@ -6,7 +6,7 @@ import carpet.script.Tokenizer;
import carpet.script.exception.ExitStatement;
import carpet.script.exception.ExpressionException;
import carpet.script.exception.InternalExpressionException;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -117,7 +117,7 @@ public class ThreadValue extends Value
}
@Override
public Tag toTag(boolean force)
public NbtElement toTag(boolean force)
{
if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
return getValue().toTag(true);
+2 -2
View File
@@ -3,7 +3,7 @@ package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtElement;
import java.util.ArrayList;
import java.util.Arrays;
@@ -251,7 +251,7 @@ public abstract class Value implements Comparable<Value>, Cloneable
}
}
public abstract Tag toTag(boolean force);
public abstract NbtElement toTag(boolean force);
public JsonElement toJson()
{