Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.Blocks;
import net.minecraft.server.v1_10_R1.ChunkCoordIntPair;
import net.minecraft.server.v1_10_R1.DefinedStructure;
import net.minecraft.server.v1_10_R1.DefinedStructureInfo;
import net.minecraft.server.v1_10_R1.DefinedStructureManager;
import net.minecraft.server.v1_10_R1.EnumBlockMirror;
import net.minecraft.server.v1_10_R1.EnumBlockRotation;
import net.minecraft.server.v1_10_R1.MinecraftKey;
import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
/**
* Created by Martin on 05.11.2016.
*/
public class StructureUtil {
/**
* Saves a schematic
*
* @param start the start location
* @param size the size
* @param name the name
* @param author the author
* @return idk, ask nms...
*/
public static boolean save(Location start, Vector size, String name, String author) {
BlockPosition startPos = new BlockPosition(start.getBlockX(), start.getBlockY(), start.getBlockZ());
BlockPosition sizePos = new BlockPosition(size.getBlockX(),size.getBlockY(),size.getBlockZ());
WorldServer world = ((CraftWorld) start.getWorld()).getHandle();
MinecraftServer server = world.getMinecraftServer();
DefinedStructureManager structureManager = world.y();
DefinedStructure structure = structureManager.a(server, new MinecraftKey(name));
structure.a(world, startPos, sizePos, true, Blocks.dj); // false -> do not includ entities, dj -> stucture void
structure.a(author); // set author
return structureManager.d(server, new MinecraftKey(name)); // rename to c for 1.11
}
/**
* Loads a structure
*
* @param origin the origin location
* @param name the name
* @return if is was successful
*/
public static boolean load(Location origin, String name) {
BlockPosition originPos = new BlockPosition(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
WorldServer world = ((CraftWorld) origin.getWorld()).getHandle();
MinecraftServer server = world.getMinecraftServer();
DefinedStructureManager structureManager = world.y();
DefinedStructure structure = structureManager.b(server, new MinecraftKey(name));
if (structure == null) {
return false;
} else {
DefinedStructureInfo structureInfo = (new DefinedStructureInfo()).a(EnumBlockMirror.NONE).a(EnumBlockRotation.NONE).a(false).a((ChunkCoordIntPair) null).a((Block) null).b(false);
structure.a(world, originPos, structureInfo);
return true;
}
}
}
@yannicklamprecht
Copy link

yannicklamprecht commented Dec 8, 2016

https://gist.github.com/MiniDigger/e10fdb52db509f4b82980ea9b4040e60#file-structureutil-java-L33

Replace the getX/Y/Z with getBlockX/Y/Z. I forgot it while writing on phone.

@MiniDigger
Copy link
Author

MiniDigger commented Dec 8, 2016

ah, saw that two while writing the reflection version, forgot to update this one, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment