use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.
the class SpongeSchematicReader method getDataVersion.
@Override
public OptionalInt getDataVersion() {
try {
CompoundTag schematicTag = getBaseTag();
Map<String, Tag> schematic = schematicTag.getValue();
if (schematicVersion == 1) {
return OptionalInt.of(Constants.DATA_VERSION_MC_1_13_2);
} else if (schematicVersion == 2) {
int dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue();
if (dataVersion < 0) {
return OptionalInt.empty();
}
return OptionalInt.of(dataVersion);
}
return OptionalInt.empty();
} catch (IOException e) {
return OptionalInt.empty();
}
}
use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.
the class SpongeSchematicWriter method writeBiomes.
private void writeBiomes(Clipboard clipboard, Map<String, Tag> schematic) {
BlockVector3 min = clipboard.getMinimumPoint();
int width = clipboard.getRegion().getWidth();
int length = clipboard.getRegion().getLength();
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * length);
int paletteMax = 0;
Map<String, Integer> palette = new HashMap<>();
for (int z = 0; z < length; z++) {
int z0 = min.getBlockZ() + z;
for (int x = 0; x < width; x++) {
int x0 = min.getBlockX() + x;
BlockVector3 pt = BlockVector3.at(x0, min.getBlockY(), z0);
BiomeType biome = clipboard.getBiome(pt);
String biomeKey = biome.getId();
int biomeId;
if (palette.containsKey(biomeKey)) {
biomeId = palette.get(biomeKey);
} else {
biomeId = paletteMax;
palette.put(biomeKey, biomeId);
paletteMax++;
}
while ((biomeId & -128) != 0) {
buffer.write(biomeId & 127 | 128);
biomeId >>>= 7;
}
buffer.write(biomeId);
}
}
schematic.put("BiomePaletteMax", new IntTag(paletteMax));
Map<String, Tag> paletteTag = new HashMap<>();
palette.forEach((key, value) -> paletteTag.put(key, new IntTag(value)));
schematic.put("BiomePalette", new CompoundTag(paletteTag));
schematic.put("BiomeData", new ByteArrayTag(buffer.toByteArray()));
}
use of com.sk89q.jnbt.CompoundTag 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.CompoundTag 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());
}
}
use of com.sk89q.jnbt.CompoundTag in project FastAsyncWorldEdit by IntellectualSites.
the class MobSpawnerBlock method getNbtData.
@Override
public CompoundTag getNbtData() {
Map<String, Tag> values = new HashMap<>();
values.put("Delay", new ShortTag(delay));
values.put("SpawnCount", new ShortTag(spawnCount));
values.put("SpawnRange", new ShortTag(spawnRange));
values.put("MinSpawnDelay", new ShortTag(minSpawnDelay));
values.put("MaxSpawnDelay", new ShortTag(maxSpawnDelay));
values.put("MaxNearbyEntities", new ShortTag(maxNearbyEntities));
values.put("RequiredPlayerRange", new ShortTag(requiredPlayerRange));
if (spawnData == null) {
values.put("SpawnData", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))));
} else {
values.put("SpawnData", new CompoundTag(spawnData.getValue()));
}
if (spawnPotentials == null) {
values.put("SpawnPotentials", new ListTag(CompoundTag.class, ImmutableList.of(new CompoundTag(ImmutableMap.of("Weight", new IntTag(1), "Entity", new CompoundTag(ImmutableMap.of("id", new StringTag(mobType))))))));
} else {
values.put("SpawnPotentials", new ListTag(CompoundTag.class, spawnPotentials.getValue()));
}
return new CompoundTag(values);
}
Aggregations