Search in sources :

Example 26 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class WindowBuildTool method adjustToGroundOffset.

/**
 * Detects the intended ground level via tag and offsets the blueprint accordingly
 */
private void adjustToGroundOffset() {
    final Blueprint blueprint = Settings.instance.getActiveStructure();
    if (blueprint != null) {
        int groundOffset;
        switch(groundstyle) {
            case GROUNDSTYLE_LEGACY_CAMP:
                groundOffset = BlueprintTagUtils.getGroundAnchorOffsetFromGroundLevels(blueprint, BlueprintTagUtils.getNumberOfGroundLevels(blueprint, 1));
                break;
            case GROUNDSTYLE_LEGACY_SHIP:
                groundOffset = BlueprintTagUtils.getGroundAnchorOffsetFromGroundLevels(blueprint, BlueprintTagUtils.getNumberOfGroundLevels(blueprint, 3));
                break;
            case GROUNDSTYLE_RELATIVE:
            default:
                groundOffset = BlueprintTagUtils.getGroundAnchorOffset(blueprint, 1);
                break;
        }
        // compensate for clicking the top face of the ground block
        --groundOffset;
        Settings.instance.setGroundOffset(groundOffset);
    }
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 27 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class ItemScanTool method saveStructure.

/**
 * Scan the structure and save it to the disk.
 *
 * @param world        Current world.
 * @param from         First corner.
 * @param to           Second corner.
 * @param player       causing this action.
 * @param name         the name of it.
 * @param saveEntities whether to scan in entities
 */
public static void saveStructure(@NotNull final World world, @NotNull final BlockPos from, @NotNull final BlockPos to, @NotNull final PlayerEntity player, final String name, final boolean saveEntities, final Optional<BlockPos> anchorPos) {
    if (anchorPos.isPresent()) {
        if (!BlockPosUtil.isInbetween(anchorPos.get(), from, to)) {
            LanguageHandler.sendPlayerMessage(player, ANCHOR_POS_OUTSIDE_SCHEMATIC);
            return;
        }
    }
    final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
    final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
    final BlockPos size = blockpos1.subtract(blockpos).offset(1, 1, 1);
    if (size.getX() * size.getY() * size.getZ() > Structurize.getConfig().getServer().schematicBlockLimit.get()) {
        LanguageHandler.sendPlayerMessage(player, MAX_SCHEMATIC_SIZE_REACHED, Structurize.getConfig().getServer().schematicBlockLimit.get());
        return;
    }
    final long currentMillis = System.currentTimeMillis();
    final String currentMillisString = Long.toString(currentMillis);
    final String fileName;
    if (name == null || name.isEmpty()) {
        fileName = LanguageHandler.format("item.sceptersteel.scanformat", "", currentMillisString);
    } else {
        fileName = name;
    }
    final Blueprint bp = BlueprintUtil.createBlueprint(world, blockpos, saveEntities, (short) size.getX(), (short) size.getY(), (short) size.getZ(), fileName, anchorPos);
    if (!anchorPos.isPresent() && bp.getPrimaryBlockOffset().equals(new BlockPos(bp.getSizeX() / 2, 0, bp.getSizeZ() / 2))) {
        final List<BlockInfo> list = bp.getBlockInfoAsList().stream().filter(blockInfo -> blockInfo.hasTileEntityData() && blockInfo.getTileEntityData().contains(TAG_BLUEPRINTDATA)).collect(Collectors.toList());
        if (list.size() > 1) {
            player.sendMessage(new TranslationTextComponent("com.ldtteam.structurize.gui.scantool.scanbadanchor", fileName), player.getUUID());
        }
    }
    Network.getNetwork().sendToPlayer(new SaveScanMessage(BlueprintUtil.writeBlueprintToNBT(bp), fileName), (ServerPlayerEntity) player);
}
Also used : Network(com.ldtteam.structurize.Network) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) Item(net.minecraft.item.Item) Structures(com.ldtteam.structurize.management.Structures) WindowScan(com.ldtteam.structurize.client.gui.WindowScan) TAG_BLUEPRINTDATA(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider.TAG_BLUEPRINTDATA) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) ItemStack(net.minecraft.item.ItemStack) Structurize(com.ldtteam.structurize.Structurize) Utils(com.ldtteam.structurize.api.util.Utils) Rarity(net.minecraft.item.Rarity) Settings(com.ldtteam.structures.helpers.Settings) Log(com.ldtteam.structurize.api.util.Log) BlockState(net.minecraft.block.BlockState) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureLoadingUtils(com.ldtteam.structurize.util.StructureLoadingUtils) OutputStream(java.io.OutputStream) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockPosUtil(com.ldtteam.structurize.api.util.BlockPosUtil) StructureName(com.ldtteam.structurize.management.StructureName) BlueprintUtil(com.ldtteam.structures.blueprints.v1.BlueprintUtil) World(net.minecraft.world.World) FileOutputStream(java.io.FileOutputStream) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) MAX_SCHEMATIC_SIZE_REACHED(com.ldtteam.structurize.api.util.constant.TranslationConstants.MAX_SCHEMATIC_SIZE_REACHED) ANCHOR_POS_OUTSIDE_SCHEMATIC(com.ldtteam.structurize.api.util.constant.TranslationConstants.ANCHOR_POS_OUTSIDE_SCHEMATIC) ItemGroup(net.minecraft.item.ItemGroup) CompressedStreamTools(net.minecraft.nbt.CompressedStreamTools) SaveScanMessage(com.ldtteam.structurize.network.messages.SaveScanMessage) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) NBTUtil(net.minecraft.nbt.NBTUtil) ActionResultType(net.minecraft.util.ActionResultType) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) SaveScanMessage(com.ldtteam.structurize.network.messages.SaveScanMessage)

Example 28 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class Manager method generateCone.

private static Blueprint generateCone(final int inputHeight, final int width, final BlockState block, final BlockState fillBlock, final boolean hollow, final Shape shape) {
    final int height = shape == Shape.DIAMOND ? inputHeight : inputHeight * 2;
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (int x = 0; x < width; x++) {
        for (int z = 0; z < width; z++) {
            for (int y = 0; y < height; y++) {
                final int consideredWidth = (int) (width - y);
                int sum = x * x + z * z;
                final boolean shouldBeEmpty = sum > (consideredWidth * consideredWidth) / 4 - consideredWidth;
                if (sum < (consideredWidth * consideredWidth) / 4 && (!hollow || shouldBeEmpty) && consideredWidth > 0) {
                    final BlockState blockToUse = shouldBeEmpty ? block : fillBlock;
                    addPosToList(new BlockPos(width + x, y, width + z), blockToUse, posList);
                    addPosToList(new BlockPos(width + x, y, width - z), blockToUse, posList);
                    addPosToList(new BlockPos(width - x, y, width + z), blockToUse, posList);
                    addPosToList(new BlockPos(width - x, y, width - z), blockToUse, posList);
                }
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) (width * 2), (short) height, (short) (width * 2));
    posList.forEach(blueprint::addBlockState);
    return blueprint;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 29 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class Manager method pasteStructure.

/**
 * Paste a structure into the world.
 *
 * @param server         the server world.
 * @param pos            the position.
 * @param width          the width.
 * @param length         the length.
 * @param height         the height.
 * @param frequency      the frequency.
 * @param equation       the equation.
 * @param shape          the shape.
 * @param inputBlock     the input block.
 * @param inputFillBlock the fill block.
 * @param hollow         if hollow or not.
 * @param player         the player.
 * @param mirror         the mirror.
 * @param rotation       the rotation.
 */
public static void pasteStructure(final ServerWorld server, final BlockPos pos, final int width, final int length, final int height, final int frequency, final String equation, final Shape shape, final ItemStack inputBlock, final ItemStack inputFillBlock, final boolean hollow, final ServerPlayerEntity player, final Mirror mirror, final Rotation rotation) {
    final Blueprint blueprint = Manager.getStructureFromFormula(width, length, height, frequency, equation, shape, inputBlock, inputFillBlock, hollow);
    StructurePlacementUtils.loadAndPlaceStructureWithRotation(server, blueprint, pos, rotation, mirror, true, player);
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 30 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class Manager method generateWave.

/**
 * Generates a wave with the specific size and adds it to the blueprint provided.
 *
 * @param height the height.
 * @param width  the width.
 * @param length the length.
 * @param block  the block to use.
 */
private static Blueprint generateWave(final int height, final int width, final int length, final int frequency, final BlockState block, final boolean flat) {
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (int x = 0; x < length; x++) {
        for (int z = 0; z < width; z++) {
            final double yVal = (flat ? 0 : z) + (double) frequency * Math.sin(x / (double) height);
            addPosToList(new BlockPos(x, yVal + frequency, (flat ? 0 : width) + z), block, posList);
            if (!flat) {
                addPosToList(new BlockPos(x, yVal + frequency, width - z), block, posList);
                addPosToList(new BlockPos(x, yVal + width - 1 + frequency, width + z - width + 1), block, posList);
                addPosToList(new BlockPos(x, yVal + width - 1 + frequency, width - z + width - 1), block, posList);
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) length, (short) (frequency * 2 + 1 + (!flat ? width * 2 : 0)), (short) (width * 2 + 1));
    posList.forEach(blueprint::addBlockState);
    return blueprint;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Aggregations

Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)37 BlockPos (net.minecraft.util.math.BlockPos)23 BlockState (net.minecraft.block.BlockState)13 StructureName (com.ldtteam.structurize.management.StructureName)8 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)8 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 Nullable (org.jetbrains.annotations.Nullable)6 BlockInfo (com.ldtteam.structurize.util.BlockInfo)5 NotNull (org.jetbrains.annotations.NotNull)5 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 World (net.minecraft.world.World)4 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)2 PlacementError (com.ldtteam.structurize.placement.handlers.placement.PlacementError)2 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)2