Search in sources :

Example 6 with DefinedStructure

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

the class StructureService method createAndSaveAny.

/**
 * A comfort method for all lazy guys. Automatically switches to structure arrays, when using an area larger than 32x32x32
 * @param corners - 2 opposite edges (order doesn't matter)
 * @param author - The listed author
 * @param destination - The destination file (for single structure) or the destination folder (for structure array)
 */
public static void createAndSaveAny(Location[] corners, String author, File destination) throws IOException {
    Location[] normalized = normalizeEdges(corners[0], corners[1]);
    int[] dimensions = getDimensions(normalized);
    if (dimensions[0] > 32 || dimensions[1] > 32 || dimensions[2] > 32) {
        DefinedStructure[] structures = createStructuresArray(normalized, author);
        saveStructuresArray(structures, destination);
        saveAreaDimFile(dimensions, destination);
    } else {
        DefinedStructure structure = createSingleStructure(normalized, author);
        saveSingleStructure(structure, destination);
    }
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) Location(org.bukkit.Location)

Example 7 with DefinedStructure

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

the class StructureService method loadSingleStructure.

/**
 * Loads a single structure NBT file and creates a new structure object instance. Works only for structures created with 1.13 or later!
 * @param source - The structure file
 * @return DefinedStructure - The new instance
 */
public static DefinedStructure loadSingleStructure(File source) throws IOException {
    DefinedStructure structure = new DefinedStructure();
    structure.b(NBTCompressedStreamTools.a(new FileInputStream(source)));
    return structure;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure)

Example 8 with DefinedStructure

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

the class StructureService method loadStructuresArray.

/**
 * Loads all structure segments back into one array. The folder file contents are important, don't change it after saving. Works only for structures created with 1.13 or later!
 * @param folder - The folder containing an NBT file by the same name with dimensions and NBT files of structures with an counter added
 * @return DefinedStructure[] - A one dimensional array, just like the folder
 */
public static DefinedStructure[] loadStructuresArray(File folder) throws IOException {
    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")) {
            DefinedStructure structure = new DefinedStructure();
            structure.b(NBTCompressedStreamTools.a(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)

Example 9 with DefinedStructure

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

the class StructureService method loadLegacySingleStructure.

/*
     * Loads a single structure NBT file and creates a new structure object instance. Also converts pre1.13 versions.
     * param source - The structure file
     * param world - The world (actually ANY world) instance to receive a data fixer (legacy converter)
     * return DefinedStructure - The new instance
     * deprecated Only for pre1.13, uses the NMS 1.13 DataFixer to convert stuff
     *
     */
public static DefinedStructure loadLegacySingleStructure(File source, World world) throws IOException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Method parseAndConvert = DefinedStructureManager.class.getDeclaredMethod("a", InputStream.class);
    parseAndConvert.setAccessible(true);
    return (DefinedStructure) parseAndConvert.invoke(((CraftWorld) world).getHandle().r(), new FileInputStream(source));
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) Method(java.lang.reflect.Method)

Example 10 with DefinedStructure

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

the class StructureService method createStructuresArray.

/**
 * Splits up an area in 32x32x32 structures, creates those and fills an array with them
 * @param corners - 2 Edges of the area (order doesn't matter)
 * @param author - The listed author of the structure
 * @return DefinedStructure[] - The structures in a one dimensional array, sorted by y, z, x (iterates along x, then z, then y)
 */
public static DefinedStructure[] createStructuresArray(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);
    int[] areas = getAreaSections(dimensions);
    DefinedStructure[] structures = new DefinedStructure[areas[0] * areas[1] * areas[2]];
    for (int x = 0; x < areas[0]; x++) {
        for (int y = 0; y < areas[1]; y++) {
            for (int z = 0; z < areas[2]; z++) {
                DefinedStructure structure = new DefinedStructure();
                int width, height, length;
                if (x == areas[0] - 1 && dimensions[0] % 32 != 0)
                    width = dimensions[0] % 32;
                else
                    width = 32;
                if (y == areas[1] - 1 && dimensions[1] % 32 != 0)
                    height = dimensions[1] % 32;
                else
                    height = 32;
                if (z == areas[2] - 1 && dimensions[2] % 32 != 0)
                    length = dimensions[2] % 32;
                else
                    length = 32;
                structure.a(world, new BlockPosition((x * 32) + normalized[0].getBlockX(), (y * 32) + normalized[0].getBlockY(), (z * 32) + normalized[0].getBlockZ()), new BlockPosition(width, height, length), true, Blocks.jb);
                structure.a(author);
                structures[getYzxIndex(x, y, z, areas[0], areas[2])] = structure;
            }
        }
    }
    return structures;
}
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)

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