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);
}
}
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));
}
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));
}
Aggregations