Search in sources :

Example 11 with Blueprint

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

the class Manager method generateRandomShape.

/**
 * Randomly generates shape based on an equation.
 *
 * @param height   the height.
 * @param width    the width.
 * @param length   the length.
 * @param equation the equation.
 * @param block    the block.
 * @return the created blueprint
 */
public static Blueprint generateRandomShape(final int height, final int width, final int length, final String equation, final BlockState block) {
    Expression e = new Expression(equation);
    final Argument argumentX = new Argument("x = 0");
    final Argument argumentY = new Argument("y = 0");
    final Argument argumentZ = new Argument("z = 0");
    final Argument argumentH = new Argument("h = " + height);
    final Argument argumentW = new Argument("w = " + width);
    final Argument argumentL = new Argument("l = " + length);
    e.addArguments(argumentX, argumentY, argumentZ, argumentH, argumentW, argumentL);
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (double x = -length / 2.0; x <= length / 2; x++) {
        for (double y = -height / 2.0; y <= height / 2; y++) {
            for (double z = -width / 2.0; z <= width / 2; z++) {
                argumentX.setArgumentValue(x);
                argumentY.setArgumentValue(y);
                argumentZ.setArgumentValue(z);
                if (e.calculate() == 1) {
                    addPosToList(new BlockPos(x + length / 2.0, y + height / 2.0, z + width / 2.0), block, posList);
                }
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) (length + 1), (short) (height + 1), (short) (width + 1));
    posList.forEach(blueprint::addBlockState);
    return blueprint;
}
Also used : BlockState(net.minecraft.block.BlockState) Argument(org.mariuszgromada.math.mxparser.Argument) Expression(org.mariuszgromada.math.mxparser.Expression) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockPos(net.minecraft.util.math.BlockPos)

Example 12 with Blueprint

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

the class Manager method generateCylinder.

/**
 * Generates a cube with the specific size and adds it to the blueprint provided.
 *
 * @param height    the height.
 * @param width     the width.
 * @param block     the block to use.
 * @param fillBlock the fill block.
 * @param hollow    if full.
 */
private static Blueprint generateCylinder(final int height, final int width, final BlockState block, final BlockState fillBlock, final boolean hollow) {
    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++) {
                int sum = x * x + z * z;
                if (sum < (width * width) / 4 && (!hollow || sum > (width * width) / 4 - width)) {
                    final BlockState blockToUse = (sum > (width * width) / 4 - width) ? 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 13 with Blueprint

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

the class Manager method generateCube.

/**
 * Generates a cube 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.
 * @param fillBlock the fill block.
 * @param hollow    if full.
 */
private static Blueprint generateCube(final int height, final int width, final int length, final BlockState block, final BlockState fillBlock, final boolean hollow) {
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            for (int z = 0; z < length; z++) {
                if ((x == 0 || x == width - 1) || (y == 0 || y == height - 1) || (z == 0 || z == length - 1)) {
                    posList.put(new BlockPos(x, y, z), block);
                } else if (!hollow) {
                    posList.put(new BlockPos(x, y, z), fillBlock);
                }
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) width, (short) height, (short) length);
    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 14 with Blueprint

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

the class Manager method getStructureFromFormula.

/**
 * Just returns a cube for now, I can tinker this later.
 *
 * @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.
 * @return the new blueprint.
 */
public static Blueprint getStructureFromFormula(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 Blueprint blueprint;
    final BlockState mainBlock = BlockUtils.getBlockStateFromStack(inputBlock, Blocks.GOLD_BLOCK.defaultBlockState());
    final BlockState fillBlock = BlockUtils.getBlockStateFromStack(inputFillBlock, Blocks.GOLD_BLOCK.defaultBlockState());
    if (shape == Shape.SPHERE || shape == Shape.HALF_SPHERE || shape == Shape.BOWL) {
        blueprint = generateSphere(height / 2, mainBlock, fillBlock, hollow, shape);
    } else if (shape == Shape.CUBE) {
        blueprint = generateCube(height, width, length, mainBlock, fillBlock, hollow);
    } else if (shape == Shape.WAVE) {
        blueprint = generateWave(height, width, length, frequency, mainBlock, true);
    } else if (shape == Shape.WAVE_3D) {
        blueprint = generateWave(height, width, length, frequency, mainBlock, false);
    } else if (shape == Shape.CYLINDER) {
        blueprint = generateCylinder(height, width, mainBlock, fillBlock, hollow);
    } else if (shape == Shape.PYRAMID || shape == Shape.UPSIDE_DOWN_PYRAMID || shape == Shape.DIAMOND) {
        blueprint = generatePyramid(height, mainBlock, fillBlock, hollow, shape);
    } else if (shape == Shape.CONE) {
        blueprint = generateCone(height, width, mainBlock, fillBlock, hollow, shape);
    } else {
        blueprint = generateRandomShape(height, width, length, equation, mainBlock);
    }
    return blueprint;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 15 with Blueprint

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

the class Manager method generatePyramid.

private static Blueprint generatePyramid(final int inputHeight, final BlockState block, final BlockState fillBlock, final boolean hollow, final Shape shape) {
    final int height = shape == Shape.DIAMOND ? inputHeight : inputHeight * 2;
    final int hHeight = height / 2;
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (int y = 0; y < hHeight; y++) {
        for (int x = 0; x < hHeight; x++) {
            for (int z = 0; z < hHeight; z++) {
                if (((x == z && x >= y) || (x == y && x >= z) || ((hollow ? y == z : y >= z) && y >= x)) && x * z <= y * y) {
                    final BlockState blockToUse = x == z && x >= y || x == y || y == z ? block : fillBlock;
                    if (shape == Shape.UPSIDE_DOWN_PYRAMID || shape == Shape.DIAMOND) {
                        addPosToList(new BlockPos(hHeight + x, y, hHeight + z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight + x, y, hHeight - z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight - x, y, hHeight + z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight - x, y, hHeight - z), blockToUse, posList);
                    }
                    if (shape == Shape.PYRAMID || shape == Shape.DIAMOND) {
                        addPosToList(new BlockPos(hHeight + x, -y + height - (shape == Shape.DIAMOND ? 2 : inputHeight), hHeight + z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight + x, -y + height - (shape == Shape.DIAMOND ? 2 : inputHeight), hHeight - z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight - x, -y + height - (shape == Shape.DIAMOND ? 2 : inputHeight), hHeight + z), blockToUse, posList);
                        addPosToList(new BlockPos(hHeight - x, -y + height - (shape == Shape.DIAMOND ? 2 : inputHeight), hHeight - z), blockToUse, posList);
                    }
                }
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) height, (short) (shape == Shape.DIAMOND ? height : inputHeight + 2), (short) height);
    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