Search in sources :

Example 1 with DefinedStructure

use of net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure in project Crazy-Crates by Crazy-Crew.

the class StructureService method loadAndInsertAny.

/**
 * A comfort method for all lazy guys. Automatically switches to structure arrays, when the source is a folder, no file
 * @param source - The structure array folder or the structure NBT file
 * @param startEdge - The starting corner for pasting (lowest x, y, z coordinates)
 * @param rotation - You may rotate the structure by 90 degrees steps
 */
public static void loadAndInsertAny(File source, Location startEdge, Rotation rotation) throws IOException, SecurityException, IllegalArgumentException {
    if (source.isDirectory()) {
        DefinedStructure[] structures = loadStructuresArray(source);
        insertStructuresArray(structures, loadAreaDimFile(source), startEdge, rotation.getNMSRot());
    } else {
        DefinedStructure structure = loadSingleStructure(source);
        insertSingleStructure(structure, startEdge, rotation.getNMSRot());
    }
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure)

Example 2 with DefinedStructure

use of net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure in project Crazy-Crates by Crazy-Crew.

the class StructureService method createSingleStructure.

/**
 * Creates a single structure of maximum 32x32x32 blocks. If you need a larger area, use {@link #createStructuresArray(Location[], String)}
 * @param corners - The edges of the area (order doesn't matter)
 * @param author - The listed author of the structure
 * @return DefinedStructure - The new structure instance
 */
public static DefinedStructure createSingleStructure(Location[] corners, String author) {
    if (corners.length != 2)
        throw new IllegalArgumentException("An area needs to be set up by exactly 2 opposite edges!");
    Location[] normalized = normalizeEdges(corners[0], corners[1]);
    WorldServer world = ((CraftWorld) normalized[0].getWorld()).getHandle();
    int[] dimensions = getDimensions(normalized);
    if (dimensions[0] > 32 || dimensions[1] > 32 || dimensions[2] > 32)
        throw new IllegalArgumentException("A single structure can only be 32x32x32! If you need more, use #createStructuresArea.");
    DefinedStructure structure = new DefinedStructure();
    structure.a(world, new BlockPosition(normalized[0].getBlockX(), normalized[0].getBlockY(), normalized[0].getBlockZ()), new BlockPosition(dimensions[0], dimensions[1], dimensions[2]), true, Blocks.jb);
    structure.a(author);
    return structure;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) BlockPosition(net.minecraft.core.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) Location(org.bukkit.Location)

Example 3 with DefinedStructure

use of net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure in project Crazy-Crates by Crazy-Crew.

the class StructureService method loadLegacyStructuresArray.

/**
 * Loads all structure segments back into one array. The folder file contents are important, don't change it after saving. Also converts pre1.13 versions.
 * @param folder - The folder containing an NBT file by the same name with dimensions and NBT files of structures with a counter added
 * @param world - The world (actually ANY world) instance to receive a data fixer (legacy converter)
 * @return DefinedStructure[] - A one dimensional array, just like the folder
 * deprecated Only for pre 1.13, uses the NMS 1.13 DataFixer to convert stuff
 */
@Deprecated
public static DefinedStructure[] loadLegacyStructuresArray(File folder, World world) throws IOException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!new File(folder, folder.getName() + ".nbt").exists())
        throw new IllegalArgumentException("This is not a valid structure area export folder!");
    DefinedStructure[] structures = new DefinedStructure[folder.listFiles().length - 1];
    for (File file : folder.listFiles()) {
        if (!file.getName().equals(folder.getName() + ".nbt")) {
            Method parseAndConvert = DefinedStructureManager.class.getDeclaredMethod("a", InputStream.class);
            parseAndConvert.setAccessible(true);
            // 1.13 WorldServer#C, 1.13.1 WorldServer#D
            DefinedStructure structure = (DefinedStructure) parseAndConvert.invoke(((CraftWorld) world).getHandle().r(), new FileInputStream(file));
            String suffix = file.getName().split("_")[file.getName().split("_").length - 1];
            suffix = suffix.substring(0, suffix.length() - 4);
            structures[Integer.parseInt(suffix)] = structure;
        }
    }
    return structures;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) Method(java.lang.reflect.Method)

Example 4 with DefinedStructure

use of net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure in project Crazy-Crates by Crazy-Crew.

the class StructureService method getSingleStructureLocations.

public static List<Location> getSingleStructureLocations(File source, Location startEdge) throws IOException {
    DefinedStructure structure = loadSingleStructure(source);
    List<Location> locations = new ArrayList<>();
    NBTTagCompound fileTag = new NBTTagCompound();
    fileTag = structure.a(fileTag);
    NBTTagList list = (NBTTagList) fileTag.c("size");
    Location endEdge = startEdge.clone().add(Integer.parseInt(list.get(0).toString()) - 1, Integer.parseInt(list.get(1).toString()) - 1, Integer.parseInt(list.get(2).toString()) - 1);
    int topBlockX = (Math.max(startEdge.getBlockX(), endEdge.getBlockX()));
    int bottomBlockX = (Math.min(startEdge.getBlockX(), endEdge.getBlockX()));
    int topBlockY = (Math.max(startEdge.getBlockY(), endEdge.getBlockY()));
    int bottomBlockY = (Math.min(startEdge.getBlockY(), endEdge.getBlockY()));
    int topBlockZ = (Math.max(startEdge.getBlockZ(), endEdge.getBlockZ()));
    int bottomBlockZ = (Math.min(startEdge.getBlockZ(), endEdge.getBlockZ()));
    for (int x = bottomBlockX; x <= topBlockX; x++) {
        for (int z = bottomBlockZ; z <= topBlockZ; z++) {
            for (int y = bottomBlockY; y <= topBlockY; y++) {
                locations.add(new Location(startEdge.getWorld(), x, y, z));
            }
        }
    }
    return locations;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) NBTTagList(net.minecraft.nbt.NBTTagList) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Location(org.bukkit.Location)

Example 5 with DefinedStructure

use of net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure in project Crazy-Crates by Crazy-Crew.

the class StructureService method getOtherEdge.

public static Location getOtherEdge(File source, Location startEdge) throws IOException {
    DefinedStructure structure = loadSingleStructure(source);
    NBTTagCompound fileTag = new NBTTagCompound();
    fileTag = structure.a(fileTag);
    NBTTagList list = (NBTTagList) fileTag.c("size");
    return startEdge.clone().add(Integer.parseInt(list.get(0).toString()) - 1, Integer.parseInt(list.get(1).toString()) - 1, Integer.parseInt(list.get(2).toString()) - 1);
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Aggregations

DefinedStructure (net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure)10 Location (org.bukkit.Location)4 Method (java.lang.reflect.Method)2 BlockPosition (net.minecraft.core.BlockPosition)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 WorldServer (net.minecraft.server.level.WorldServer)2 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)2 ArrayList (java.util.ArrayList)1