use of com.sk89q.jnbt.IntTag in project FastAsyncWorldEdit by IntellectualSites.
the class SpongeSchematicReader method readBiomes.
private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
Map<Integer, BiomeType> palette = new HashMap<>();
if (maxTag.getValue() != paletteTag.getValue().size()) {
throw new IOException("Biome palette size does not match expected size.");
}
for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
String key = palettePart.getKey();
if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
}
BiomeType biome = BiomeTypes.get(key);
if (biome == null) {
LOGGER.warn("Unknown biome type :" + key + " in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?");
}
Tag idTag = palettePart.getValue();
if (!(idTag instanceof IntTag)) {
throw new IOException("Biome mapped to non-Int tag.");
}
palette.put(((IntTag) idTag).getValue(), biome);
}
int width = clipboard.getDimensions().getX();
byte[] biomes = dataTag.getValue();
int biomeIndex = 0;
int biomeJ = 0;
int bVal;
int varIntLength;
BlockVector3 min = clipboard.getMinimumPoint();
while (biomeJ < biomes.length) {
bVal = 0;
varIntLength = 0;
while (true) {
bVal |= (biomes[biomeJ] & 127) << (varIntLength++ * 7);
if (varIntLength > 5) {
throw new IOException("VarInt too big (probably corrupted data)");
}
if (((biomes[biomeJ] & 128) != 128)) {
biomeJ++;
break;
}
biomeJ++;
}
int z = biomeIndex / width;
int x = biomeIndex % width;
BiomeType type = palette.get(bVal);
for (int y = 0; y < clipboard.getRegion().getHeight(); y++) {
clipboard.setBiome(min.add(x, y, z), type);
}
biomeIndex++;
}
}
use of com.sk89q.jnbt.IntTag 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.IntTag 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.IntTag 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);
}
use of com.sk89q.jnbt.IntTag in project FastAsyncWorldEdit by IntellectualSites.
the class MinecraftStructure method read.
@Override
public Clipboard read(UUID clipboardId) throws IOException {
NamedTag rootTag = inputStream.readNamedTag();
// MC structures are all unnamed, but this doesn't seem to be necessary? might remove this later
if (!rootTag.getName().isEmpty()) {
throw new IOException("Root tag has name - are you sure this is a structure?");
}
Map<String, Tag> tags = ((CompoundTag) rootTag.getTag()).getValue();
ListTag size = (ListTag) tags.get("size");
int width = size.getInt(0);
int height = size.getInt(1);
int length = size.getInt(2);
// Init clipboard
BlockVector3 origin = BlockVector3.at(0, 0, 0);
CuboidRegion region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
Clipboard clipboard = new BlockArrayClipboard(region, clipboardId);
// Blocks
ListTag blocks = (ListTag) tags.get("blocks");
if (blocks != null) {
// Palette
List<CompoundTag> palette = (List<CompoundTag>) tags.get("palette").getValue();
BlockState[] combinedArray = new BlockState[palette.size()];
for (int i = 0; i < palette.size(); i++) {
CompoundTag compound = palette.get(i);
Map<String, Tag> map = compound.getValue();
String name = ((StringTag) map.get("Name")).getValue();
BlockType type = BlockTypes.get(name);
BlockState state = type.getDefaultState();
CompoundTag properties = (CompoundTag) map.get("Properties");
if (properties != null) {
for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
String key = entry.getKey();
String value = ((StringTag) entry.getValue()).getValue();
Property<Object> property = type.getProperty(key);
state = state.with(property, property.getValueFor(value));
}
}
combinedArray[i] = state;
}
// Populate blocks
List<CompoundTag> blocksList = (List<CompoundTag>) tags.get("blocks").getValue();
try {
for (CompoundTag compound : blocksList) {
Map<String, Tag> blockMap = compound.getValue();
IntTag stateTag = (IntTag) blockMap.get("state");
ListTag posTag = (ListTag) blockMap.get("pos");
BlockState state = combinedArray[stateTag.getValue()];
int x = posTag.getInt(0);
int y = posTag.getInt(1);
int z = posTag.getInt(2);
if (state.getBlockType().getMaterial().hasContainer()) {
CompoundTag nbt = (CompoundTag) blockMap.get("nbt");
if (nbt != null) {
BaseBlock block = state.toBaseBlock(nbt);
clipboard.setBlock(x, y, z, block);
continue;
}
}
clipboard.setBlock(x, y, z, state);
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Entities
ListTag entities = (ListTag) tags.get("entities");
if (entities != null) {
List<CompoundTag> entityList = (List<CompoundTag>) (List<?>) entities.getValue();
for (CompoundTag entityEntry : entityList) {
Map<String, Tag> entityEntryMap = entityEntry.getValue();
ListTag posTag = (ListTag) entityEntryMap.get("pos");
CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
String id = nbtTag.getString("Id");
Location location = NBTConversions.toLocation(clipboard, posTag, nbtTag.getListTag("Rotation"));
if (!id.isEmpty()) {
BaseEntity state = new BaseEntity(EntityTypes.get(id), nbtTag);
clipboard.createEntity(location, state);
}
}
}
return clipboard;
}
Aggregations