use of com.sk89q.jnbt.ListTag in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardWriter method writeVector.
// FAWE start
default Tag writeVector(Vector3 vector) {
List<DoubleTag> list = new ArrayList<>();
list.add(new DoubleTag(vector.getX()));
list.add(new DoubleTag(vector.getY()));
list.add(new DoubleTag(vector.getZ()));
return new ListTag(DoubleTag.class, list);
}
use of com.sk89q.jnbt.ListTag in project FastAsyncWorldEdit by IntellectualSites.
the class ClipboardWriter method writeRotation.
default Tag writeRotation(Location location) {
List<FloatTag> list = new ArrayList<>();
list.add(new FloatTag(location.getYaw()));
list.add(new FloatTag(location.getPitch()));
return new ListTag(FloatTag.class, list);
}
use of com.sk89q.jnbt.ListTag in project FastAsyncWorldEdit by IntellectualSites.
the class BannerBlockCompatibilityHandler method updateNBT.
@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
Tag typeTag = values.get("Base");
if (typeTag instanceof IntTag) {
boolean isWall = block.getBlockType() == BlockTypes.WHITE_WALL_BANNER;
String bannerType = convertBannerType(((IntTag) typeTag).getValue(), isWall);
if (bannerType != null) {
BlockType type = BlockTypes.get("minecraft:" + bannerType);
if (type != null) {
BlockState state = type.getDefaultState();
if (isWall) {
Property<Direction> facingProp = type.getProperty("facing");
state = state.with(facingProp, block.getState(FacingProperty));
} else {
Property<Integer> rotationProp = type.getProperty("rotation");
state = state.with(rotationProp, block.getState(RotationProperty));
}
values.remove("Base");
Tag patternsTag = values.get("Patterns");
if (patternsTag instanceof ListTag) {
List<Tag> tempList = new ArrayList<>();
for (Tag pattern : ((ListTag) patternsTag).getValue()) {
if (pattern instanceof CompoundTag) {
Map<String, Tag> patternMap = ((CompoundTag) pattern).getValue();
Tag colorTag = patternMap.get("Color");
CompoundTagBuilder builder = CompoundTagBuilder.create();
builder.putAll(patternMap);
if (colorTag instanceof IntTag) {
builder.putInt("Color", 15 - ((IntTag) colorTag).getValue());
}
tempList.add(builder.build());
} else {
tempList.add(pattern);
}
}
values.put("Patterns", new ListTag(((ListTag) patternsTag).getType(), tempList));
}
return state;
}
}
}
return block;
}
use of com.sk89q.jnbt.ListTag in project FastAsyncWorldEdit by IntellectualSites.
the class NBTConverter method fromNative.
public static ListTag fromNative(net.minecraft.nbt.ListTag other) {
other = (net.minecraft.nbt.ListTag) other.copy();
List<Tag> list = new ArrayList<>();
Class<? extends Tag> listClass = StringTag.class;
int tags = other.size();
for (int i = 0; i < tags; i++) {
Tag child = fromNative(other.remove(0));
list.add(child);
listClass = child.getClass();
}
return new ListTag(listClass, list);
}
use of com.sk89q.jnbt.ListTag in project FastAsyncWorldEdit by IntellectualSites.
the class MobSpawnerBlock method setNbtData.
@Override
public void setNbtData(CompoundTag rootTag) {
if (rootTag == null) {
return;
}
Map<String, Tag> values = rootTag.getValue();
Tag t = values.get("id");
if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals(getNbtId())) {
throw new RuntimeException(String.format("'%s' tile entity expected", getNbtId()));
}
CompoundTag spawnDataTag;
String mobType;
ShortTag delayTag;
try {
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
mobType = spawnDataTag.getString("id");
if (mobType.equals("")) {
throw new InvalidFormatException("No spawn id.");
}
this.mobType = mobType;
this.spawnData = spawnDataTag;
} catch (InvalidFormatException ignored) {
throw new RuntimeException("Invalid mob spawner data: no SpawnData and/or no Delay");
}
try {
delayTag = NBTUtils.getChildTag(values, "Delay", ShortTag.class);
this.delay = delayTag.getValue();
} catch (InvalidFormatException ignored) {
this.delay = -1;
}
ShortTag spawnCountTag = null;
ShortTag spawnRangeTag = null;
ShortTag minSpawnDelayTag = null;
ShortTag maxSpawnDelayTag = null;
ShortTag maxNearbyEntitiesTag = null;
ShortTag requiredPlayerRangeTag = null;
ListTag spawnPotentialsTag = null;
try {
spawnCountTag = NBTUtils.getChildTag(values, "SpawnCount", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
spawnRangeTag = NBTUtils.getChildTag(values, "SpawnRange", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
minSpawnDelayTag = NBTUtils.getChildTag(values, "MinSpawnDelay", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
maxSpawnDelayTag = NBTUtils.getChildTag(values, "MaxSpawnDelay", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
maxNearbyEntitiesTag = NBTUtils.getChildTag(values, "MaxNearbyEntities", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
requiredPlayerRangeTag = NBTUtils.getChildTag(values, "RequiredPlayerRange", ShortTag.class);
} catch (InvalidFormatException ignored) {
}
try {
spawnPotentialsTag = NBTUtils.getChildTag(values, "SpawnPotentials", ListTag.class);
} catch (InvalidFormatException ignored) {
}
if (spawnCountTag != null) {
this.spawnCount = spawnCountTag.getValue();
}
if (spawnRangeTag != null) {
this.spawnRange = spawnRangeTag.getValue();
}
if (minSpawnDelayTag != null) {
this.minSpawnDelay = minSpawnDelayTag.getValue();
}
if (maxSpawnDelayTag != null) {
this.maxSpawnDelay = maxSpawnDelayTag.getValue();
}
if (maxNearbyEntitiesTag != null) {
this.maxNearbyEntities = maxNearbyEntitiesTag.getValue();
}
if (requiredPlayerRangeTag != null) {
this.requiredPlayerRange = requiredPlayerRangeTag.getValue();
}
if (spawnPotentialsTag != null) {
this.spawnPotentials = new ListTag(CompoundTag.class, spawnPotentialsTag.getValue());
}
}
Aggregations