Search in sources :

Example 1 with ListTag

use of org.jnbt.ListTag in project WorldPainter by Captain-Chaos.

the class RespawnPlayer method respawnPlayer.

public static void respawnPlayer(File levelDatFile) throws IOException {
    CompoundTag outerTag;
    try (NBTInputStream in = new NBTInputStream(new GZIPInputStream(new FileInputStream(levelDatFile)))) {
        outerTag = (CompoundTag) in.readTag();
    }
    CompoundTag dataTag = (CompoundTag) outerTag.getTag(TAG_DATA);
    int spawnX = ((IntTag) dataTag.getTag(TAG_SPAWN_X)).getValue();
    int spawnY = ((IntTag) dataTag.getTag(TAG_SPAWN_Y)).getValue();
    int spawnZ = ((IntTag) dataTag.getTag(TAG_SPAWN_Z)).getValue();
    CompoundTag playerTag = (CompoundTag) dataTag.getTag(TAG_PLAYER);
    playerTag.setTag(TAG_DEATH_TIME, new ShortTag(TAG_DEATH_TIME, (short) 0));
    playerTag.setTag(TAG_HEALTH, new ShortTag(TAG_HEALTH, (short) 20));
    List<Tag> motionList = new ArrayList<>(3);
    motionList.add(new DoubleTag(null, 0));
    motionList.add(new DoubleTag(null, 0));
    motionList.add(new DoubleTag(null, 0));
    playerTag.setTag(TAG_MOTION, new ListTag(TAG_MOTION, DoubleTag.class, motionList));
    List<Tag> posList = new ArrayList<>(3);
    posList.add(new DoubleTag(null, spawnX + 0.5));
    posList.add(new DoubleTag(null, spawnY + 3));
    posList.add(new DoubleTag(null, spawnZ + 0.5));
    playerTag.setTag(TAG_POS, new ListTag(TAG_POS, DoubleTag.class, posList));
    try (NBTOutputStream out = new NBTOutputStream(new GZIPOutputStream(new FileOutputStream(levelDatFile)))) {
        out.writeTag(outerTag);
    }
}
Also used : ArrayList(java.util.ArrayList) DoubleTag(org.jnbt.DoubleTag) ListTag(org.jnbt.ListTag) NBTOutputStream(org.jnbt.NBTOutputStream) FileInputStream(java.io.FileInputStream) ShortTag(org.jnbt.ShortTag) GZIPInputStream(java.util.zip.GZIPInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) NBTInputStream(org.jnbt.NBTInputStream) IntTag(org.jnbt.IntTag) DoubleTag(org.jnbt.DoubleTag) ShortTag(org.jnbt.ShortTag) CompoundTag(org.jnbt.CompoundTag) Tag(org.jnbt.Tag) ListTag(org.jnbt.ListTag) CompoundTag(org.jnbt.CompoundTag) IntTag(org.jnbt.IntTag)

Example 2 with ListTag

use of org.jnbt.ListTag in project WorldPainter by Captain-Chaos.

the class AbstractNBTItem method setDoubleList.

protected final void setDoubleList(String name, double[] values) {
    List<Tag> list = new ArrayList<>(values.length);
    for (double value : values) {
        list.add(new DoubleTag(null, value));
    }
    tag.setTag(name, new ListTag(name, DoubleTag.class, list));
}
Also used : ArrayList(java.util.ArrayList) IntTag(org.jnbt.IntTag) DoubleTag(org.jnbt.DoubleTag) ByteTag(org.jnbt.ByteTag) ShortTag(org.jnbt.ShortTag) FloatTag(org.jnbt.FloatTag) CompoundTag(org.jnbt.CompoundTag) LongTag(org.jnbt.LongTag) IntArrayTag(org.jnbt.IntArrayTag) StringTag(org.jnbt.StringTag) Tag(org.jnbt.Tag) ListTag(org.jnbt.ListTag) ByteArrayTag(org.jnbt.ByteArrayTag) DoubleTag(org.jnbt.DoubleTag) ListTag(org.jnbt.ListTag)

Example 3 with ListTag

use of org.jnbt.ListTag in project WorldPainter by Captain-Chaos.

the class AbstractNBTItem method setFloatList.

protected final void setFloatList(String name, float[] values) {
    List<Tag> list = new ArrayList<>(values.length);
    for (float value : values) {
        list.add(new FloatTag(null, value));
    }
    tag.setTag(name, new ListTag(name, FloatTag.class, list));
}
Also used : FloatTag(org.jnbt.FloatTag) ArrayList(java.util.ArrayList) IntTag(org.jnbt.IntTag) DoubleTag(org.jnbt.DoubleTag) ByteTag(org.jnbt.ByteTag) ShortTag(org.jnbt.ShortTag) FloatTag(org.jnbt.FloatTag) CompoundTag(org.jnbt.CompoundTag) LongTag(org.jnbt.LongTag) IntArrayTag(org.jnbt.IntArrayTag) StringTag(org.jnbt.StringTag) Tag(org.jnbt.Tag) ListTag(org.jnbt.ListTag) ByteArrayTag(org.jnbt.ByteArrayTag) ListTag(org.jnbt.ListTag)

Aggregations

ArrayList (java.util.ArrayList)3 CompoundTag (org.jnbt.CompoundTag)3 DoubleTag (org.jnbt.DoubleTag)3 IntTag (org.jnbt.IntTag)3 ListTag (org.jnbt.ListTag)3 ShortTag (org.jnbt.ShortTag)3 Tag (org.jnbt.Tag)3 ByteArrayTag (org.jnbt.ByteArrayTag)2 ByteTag (org.jnbt.ByteTag)2 FloatTag (org.jnbt.FloatTag)2 IntArrayTag (org.jnbt.IntArrayTag)2 LongTag (org.jnbt.LongTag)2 StringTag (org.jnbt.StringTag)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 NBTInputStream (org.jnbt.NBTInputStream)1 NBTOutputStream (org.jnbt.NBTOutputStream)1