Search in sources :

Example 1 with ModTemplateManager

use of com.silverminer.shrines.utils.custom_structures.ModTemplateManager in project Shrines by Silverminer007.

the class CustomStructureData method loadPieces.

public boolean loadPieces(ServerWorld serverWorld, MinecraftServer server, BlockPos loadPos, Rotation rot) {
    ModTemplateManager templatemanager;
    for (PieceData pd : this.pieces.getValue()) {
        ResourceLocation location = new ResourceLocation(ShrinesMod.MODID, name + "/" + pd.path);
        try {
            templatemanager = new ModTemplateManager(Utils.getSaveLocation().getCanonicalFile().toPath(), server.getFixerUpper());
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        Template template;
        try {
            template = templatemanager.get(location);
        } catch (ResourceLocationException resourcelocationexception) {
            return false;
        }
        if (template == null)
            return false;
        BlockPos blockpos = loadPos.offset(pd.offset);
        PlacementSettings placementsettings = (new PlacementSettings()).setMirror(Mirror.NONE).setRotation(rot).setIgnoreEntities(false).setChunkPos((ChunkPos) null);
        template.placeInWorldChunk(serverWorld, blockpos, placementsettings, createRandom(this.seed.getValue()));
    }
    return true;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocationException(net.minecraft.util.ResourceLocationException) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) PlacementSettings(net.minecraft.world.gen.feature.template.PlacementSettings) ModTemplateManager(com.silverminer.shrines.utils.custom_structures.ModTemplateManager) Template(net.minecraft.world.gen.feature.template.Template)

Example 2 with ModTemplateManager

use of com.silverminer.shrines.utils.custom_structures.ModTemplateManager in project Shrines by Silverminer007.

the class CustomStructureData method savePieces.

public boolean savePieces(ServerWorld serverWorld, MinecraftServer server, String author, boolean includeEntities) {
    ModTemplateManager templatemanager;
    try {
        templatemanager = new ModTemplateManager(Utils.getSaveLocation().getCanonicalFile().toPath(), server.getFixerUpper());
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    for (ResourceData rd : PIECES_ON_FLY) {
        ResourceLocation location = new ResourceLocation(ShrinesMod.MODID, name + "/" + rd.getName());
        MutableBoundingBox mbb = rd.getBounds();
        BlockPos c0 = new BlockPos(mbb.x0, mbb.y0, mbb.z0);
        BlockPos c1 = new BlockPos(mbb.x1, mbb.y1, mbb.z1);
        Template template;
        try {
            template = templatemanager.getOrCreate(location);
        } catch (ResourceLocationException resourcelocationexception) {
            LOGGER.error(resourcelocationexception);
            return false;
        }
        template.fillFromWorld(serverWorld, c0, c1.subtract(c0), includeEntities, Blocks.STRUCTURE_VOID);
        template.setAuthor(author);
        try {
            if (!templatemanager.save(location)) {
                return false;
            }
        } catch (ResourceLocationException resourcelocationexception) {
            LOGGER.error(resourcelocationexception);
            return false;
        }
    }
    return true;
}
Also used : MutableBoundingBox(net.minecraft.util.math.MutableBoundingBox) ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocationException(net.minecraft.util.ResourceLocationException) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) ModTemplateManager(com.silverminer.shrines.utils.custom_structures.ModTemplateManager) Template(net.minecraft.world.gen.feature.template.Template)

Aggregations

ModTemplateManager (com.silverminer.shrines.utils.custom_structures.ModTemplateManager)2 IOException (java.io.IOException)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ResourceLocationException (net.minecraft.util.ResourceLocationException)2 BlockPos (net.minecraft.util.math.BlockPos)2 Template (net.minecraft.world.gen.feature.template.Template)2 MutableBoundingBox (net.minecraft.util.math.MutableBoundingBox)1 PlacementSettings (net.minecraft.world.gen.feature.template.PlacementSettings)1