use of net.aufdemrand.denizen.nms.interfaces.BlockData in project Denizen-For-Bukkit by DenizenScript.
the class CuboidBlockSet method saveMCEditFormatToStream.
// Thanks to WorldEdit for sample code
public void saveMCEditFormatToStream(OutputStream os) {
try {
HashMap<String, Tag> schematic = new HashMap<String, Tag>();
schematic.put("Width", new ShortTag((short) (x_width)));
schematic.put("Length", new ShortTag((short) (z_height)));
schematic.put("Height", new ShortTag((short) (y_length)));
schematic.put("Materials", new StringTag("Alpha"));
schematic.put("DenizenOriginX", new IntTag((int) center_x));
schematic.put("DenizenOriginY", new IntTag((int) center_y));
schematic.put("DenizenOriginZ", new IntTag((int) center_z));
schematic.put("WEOriginX", new IntTag((int) center_x));
schematic.put("WEOriginY", new IntTag((int) center_y));
schematic.put("WEOriginZ", new IntTag((int) center_z));
schematic.put("WEOffsetX", new IntTag(0));
schematic.put("WEOffsetY", new IntTag(0));
schematic.put("WEOffsetZ", new IntTag(0));
byte[] blocks = new byte[(int) ((x_width) * (y_length) * (z_height))];
byte[] addBlocks = null;
byte[] blockData = new byte[blocks.length];
ArrayList<Tag> tileEntities = new ArrayList<Tag>();
int indexer = 0;
for (int x = 0; x < x_width; x++) {
for (int y = 0; y < y_length; y++) {
for (int z = 0; z < z_height; z++) {
int index = (int) (y * (x_width) * (z_height) + z * (x_width) + x);
//blockAt(x, y, z);
BlockData bd = this.blocks.get(indexer);
indexer++;
if (bd.getMaterial().getId() > 255) {
if (addBlocks == null) {
addBlocks = new byte[(blocks.length >> 1) + 1];
}
addBlocks[index >> 1] = (byte) (((index & 1) == 0) ? addBlocks[index >> 1] & 0xF0 | (bd.getMaterial().getId() >> 8) & 0xF : addBlocks[index >> 1] & 0xF | ((bd.getMaterial().getId() >> 8) & 0xF) << 4);
}
blocks[index] = (byte) bd.getMaterial().getId();
blockData[index] = bd.getData();
CompoundTag rawTag = bd.getCompoundTag();
if (rawTag != null) {
HashMap<String, Tag> values = new HashMap<String, Tag>();
for (Map.Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
values.put(entry.getKey(), entry.getValue());
}
// TODO: ??? -> values.put("id", new StringTag(null)); // block.getNbtId()
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
CompoundTag tileEntityTag = NMSHandler.getInstance().createCompoundTag(values);
tileEntities.add(tileEntityTag);
}
}
}
}
schematic.put("Blocks", new ByteArrayTag(blocks));
schematic.put("Data", new ByteArrayTag(blockData));
schematic.put("Entities", new ListTag(CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag(addBlocks));
}
CompoundTag schematicTag = NMSHandler.getInstance().createCompoundTag(schematic);
NBTOutputStream stream = new NBTOutputStream(new GZIPOutputStream(os));
stream.writeNamedTag("Schematic", schematicTag);
os.flush();
stream.close();
} catch (Exception e) {
dB.echoError(e);
}
}
use of net.aufdemrand.denizen.nms.interfaces.BlockData in project Denizen-For-Bukkit by DenizenScript.
the class SchematicCommand method schematicTags.
@TagManager.TagEvents
public void schematicTags(ReplaceableTagEvent event) {
if (!event.matches("schematic, schem")) {
return;
}
String id = event.hasNameContext() ? event.getNameContext().toUpperCase() : null;
Attribute attribute = event.getAttributes().fulfill(1);
// -->
if (attribute.startsWith("list")) {
event.setReplaced(new dList(schematics.keySet()).getAttribute(attribute.fulfill(1)));
}
if (id == null) {
return;
}
if (!schematics.containsKey(id)) {
// Meta below
if (attribute.startsWith("exists")) {
event.setReplaced(new Element(false).getAttribute(attribute.fulfill(1)));
return;
}
dB.echoError(attribute.getScriptEntry() != null ? attribute.getScriptEntry().getResidingQueue() : null, "Schematic file " + id + " is not loaded.");
return;
}
CuboidBlockSet set = schematics.get(id);
// -->
if (attribute.startsWith("exists")) {
event.setReplaced(new Element(true).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("height")) {
event.setReplaced(new Element(set.y_length).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("length")) {
event.setReplaced(new Element(set.z_height).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("width")) {
event.setReplaced(new Element(set.x_width).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("block")) {
if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
dLocation location = dLocation.valueOf(attribute.getContext(1));
BlockData block = set.blockAt(location.getX(), location.getY(), location.getZ());
event.setReplaced(dMaterial.getMaterialFrom(block.getMaterial(), block.getData()).getAttribute(attribute.fulfill(1)));
return;
}
}
// -->
if (attribute.startsWith("origin")) {
event.setReplaced(new dLocation(null, set.center_x, set.center_y, set.center_z).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("blocks")) {
event.setReplaced(new Element(set.blocks.size()).getAttribute(attribute.fulfill(1)));
return;
}
// -->
if (attribute.startsWith("cuboid") && attribute.hasContext(1)) {
dLocation origin = dLocation.valueOf(attribute.getContext(1));
event.setReplaced(set.getCuboid(origin).getAttribute(attribute.fulfill(1)));
return;
}
}
Aggregations