Search in sources :

Example 1 with DoubleTag

use of org.jnbt.DoubleTag 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 DoubleTag

use of org.jnbt.DoubleTag 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)

Aggregations

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