Search in sources :

Example 1 with OperationGenerateStructure

use of ivorius.reccomplex.operation.OperationGenerateStructure in project RecurrentComplex by Ivorforce.

the class CommandSelectMove method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockPos move = parameters.get(RCP.pos("x", "y", "z", BlockPos.ORIGIN, false)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    boolean noselect = parameters.has("noselect");
    boolean duplicate = parameters.has("duplicate");
    int times = parameters.get("times").to(NaP::asInt).optional().orElse(1);
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldDataCompound;
    BlockPos pos = selectionOwner.getSelection().getLowerCorner();
    for (int i = 0; i < times; i++) {
        pos = pos.add(move);
        if (duplicate)
            OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
        else
            OperationRegistry.queueOperation(new OperationMulti(new OperationClearArea(area), new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld())), commandSender);
    }
    if (!noselect) {
        StructureGenerator<GenericStructure.InstanceData> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        selectionOwner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) OperationClearArea(ivorius.reccomplex.operation.OperationClearArea) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationMulti(ivorius.reccomplex.operation.OperationMulti) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) NaP(ivorius.mcopts.commands.parameters.NaP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 2 with OperationGenerateStructure

use of ivorius.reccomplex.operation.OperationGenerateStructure in project RecurrentComplex by Ivorforce.

the class CommandPaste method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
    RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
    NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
    if (worldData == null)
        throw RecurrentComplex.translations.commandException("commands.strucPaste.noClipboard");
    WorldServer world = (WorldServer) sender.getEntityWorld();
    BlockPos pos = parameters.get(MCP.pos("x", "y", "z", sender.getPosition(), false)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    String seed = parameters.get("seed").optional().orElse(null);
    boolean generate = parameters.has("generate");
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldData;
    // TODO Generate with generation info?
    OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, !generate).withSeed(seed).prepare(world), sender);
    if (parameters.has("select")) {
        StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // Can never not place so don't handle
        // noinspection OptionalGetWithoutIsPresent
        RCCommands.select(sender, RCBlockAreas.from(generator.boundingBox().get()));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 3 with OperationGenerateStructure

use of ivorius.reccomplex.operation.OperationGenerateStructure in project RecurrentComplex by Ivorforce.

the class CommandImportStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String structureID = parameters.get(0).require();
    Structure<?> structure = parameters.get(0).to(RCP::structure).require();
    WorldServer world = parameters.get("dimension").to(MCP.dimension(server, sender)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    BlockPos pos = parameters.get(MCP.pos("x", "y", "z", sender.getPosition(), false)).require();
    StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).transform(transform).lowerCoord(pos).asSource(true);
    // Can never not place so don't handle
    // noinspection OptionalGetWithoutIsPresent
    StructureBoundingBox boundingBox = generator.boundingBox().get();
    if (structure instanceof GenericStructure && world == sender.getEntityWorld())
        OperationRegistry.queueOperation(new OperationGenerateStructure((GenericStructure) structure, structureID, transform, pos, true).withStructureID(structureID).prepare(world), sender);
    else
        generator.generate();
    if (parameters.has("select"))
        RCCommands.select(sender, RCBlockAreas.from(boundingBox));
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 4 with OperationGenerateStructure

use of ivorius.reccomplex.operation.OperationGenerateStructure in project RecurrentComplex by Ivorforce.

the class CommandGenerateStructure method execute.

@Override
@ParametersAreNonnullByDefault
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String structureID = parameters.get(0).require();
    Structure<?> structure = parameters.get(0).to(RCP::structure).require();
    WorldServer world = parameters.get("dimension").to(MCP.dimension(server, sender)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(null);
    GenerationType generationType = parameters.get("gen").to(RCP::generationType, structure).require();
    BlockSurfacePos pos = parameters.get(IvP.surfacePos("x", "z", sender.getPosition(), false)).require();
    String seed = parameters.get("seed").optional().orElseGet(() -> RandomStringUtils.randomAlphanumeric(20).toUpperCase());
    boolean suggest = parameters.has("suggest");
    Placer placer = generationType.placer();
    StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).generationInfo(generationType).seed(RCStrings.seed(seed)).structureID(structureID).randomPosition(pos, placer).fromCenter(true).maturity(suggest ? SUGGEST : FIRST).transform(transform);
    if (structure instanceof GenericStructure && world == sender.getEntityWorld()) {
        GenericStructure genericStructureInfo = (GenericStructure) structure;
        // noinspection unchecked
        if (!OperationRegistry.queueOperation(new OperationGenerateStructure(genericStructureInfo, generationType.id(), generator.transform(), generator.lowerCoord().orElse(null), false).withSeed(seed).withStructureID(structureID).prepare((Optional<GenericStructure.InstanceData>) generator.instanceData()), sender))
            return;
    } else {
        StructureGenerator.GenerationResult result = generator.generate();
        if (result instanceof StructureGenerator.GenerationResult.Failure) {
            String reason = ((StructureGenerator.GenerationResult.Failure) result).description;
            throw RecurrentComplex.translations.commandException("commands.strucGen.failure", reason);
        }
    }
    if (parameters.has("select"))
        RCCommands.select(sender, RCBlockAreas.from(generator.boundingBox().get()));
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) WorldServer(net.minecraft.world.WorldServer) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)4 OperationGenerateStructure (ivorius.reccomplex.operation.OperationGenerateStructure)4 StructureGenerator (ivorius.reccomplex.world.gen.feature.StructureGenerator)4 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)4 WorldServer (net.minecraft.world.WorldServer)4 Parameters (ivorius.mcopts.commands.parameters.Parameters)3 BlockPos (net.minecraft.util.math.BlockPos)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)2 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)1 NaP (ivorius.mcopts.commands.parameters.NaP)1 RCEntityInfo (ivorius.reccomplex.capability.RCEntityInfo)1 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)1 OperationClearArea (ivorius.reccomplex.operation.OperationClearArea)1 OperationMulti (ivorius.reccomplex.operation.OperationMulti)1 Placer (ivorius.reccomplex.world.gen.feature.structure.Placer)1 GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1