Search in sources :

Example 11 with SelectionOwner

use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.

the class CommandSetProperty method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    PositionedBlockExpression matcher = new PositionedBlockExpression(RecurrentComplex.specialRegistry);
    IvOptional.ifAbsent(parameters.rc("exp").expression(matcher).optional(), () -> matcher.setExpression(""));
    String propertyName = parameters.get().first().require();
    String propertyValue = parameters.get().at(1).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos pos : BlockAreas.mutablePositions(selectionOwner.getSelection())) {
        PositionedBlockExpression.Argument at = PositionedBlockExpression.Argument.at(world, pos);
        if (matcher.test(at))
            TransformerProperty.withProperty(at.state, propertyName, propertyValue).ifPresent(state -> world.setBlockState(pos, state, 3));
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) TransformerProperty(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.TransformerProperty) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IvOptional(ivorius.reccomplex.utils.optional.IvOptional) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) BlockPos(net.minecraft.util.math.BlockPos)

Example 12 with SelectionOwner

use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.

the class CommandNaturalSpace method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockArea area = selectionOwner.getSelection();
    RCParameters parameters = RCParameters.of(args);
    int floorDistance = parameters.get("distance-to-floor").intAt(0).optional().orElse(0) + 1;
    int maxClosedSides = parameters.get("max-closed-sides").intAt(1).optional().orElse(3);
    placeNaturalAir(world, area, floorDistance, maxClosedSides);
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner)

Example 13 with SelectionOwner

use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.

the class SelectionRenderer method renderSelection.

public static void renderSelection(EntityLivingBase entity, int ticks, float partialTicks) {
    Minecraft mc = Minecraft.getMinecraft();
    BlockPos selPoint1 = null;
    BlockPos selPoint2 = null;
    SelectionOwner owner = SelectionOwner.getOwner(entity, null);
    if (owner != null) {
        selPoint1 = owner.getSelectedPoint1();
        selPoint2 = owner.getSelectedPoint2();
    }
    GL11.glLineWidth(3.0f);
    if (selPoint1 != null) {
        GlStateManager.color(0.6f, 0.8f, 0.95f);
        AreaRenderer.renderAreaLined(new BlockArea(selPoint1, selPoint1), 0.03f);
    }
    if (selPoint2 != null) {
        GlStateManager.color(0.2f, 0.45f, 0.65f);
        AreaRenderer.renderAreaLined(new BlockArea(selPoint2, selPoint2), 0.04f);
    }
    for (EnumHand enumHand : EnumHand.values()) {
        ItemStack heldItem = entity.getHeldItem(enumHand);
        if (heldItem != null && heldItem.getItem() instanceof ItemBlockSelectorFloating) {
            float selectionRange = ((ItemBlockSelectorFloating) heldItem.getItem()).getSelectionRange(heldItem);
            BlockPos hoverPoint = ItemBlockSelectorFloating.getHoveredBlock(entity, selectionRange);
            GlStateManager.color(0.6f, 0.6f, 1.0f);
            AreaRenderer.renderAreaLined(new BlockArea(hoverPoint, hoverPoint), 0.05f);
        }
    }
    if (selPoint1 != null && selPoint2 != null) {
        BlockArea selArea = new BlockArea(selPoint1, selPoint2);
        GlStateManager.color(0.4f, 0.65f, 0.8f);
        AreaRenderer.renderAreaLined(selArea, 0.02f);
        GlStateManager.enableBlend();
        OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.0001f);
        ResourceLocation curTex = TEXTURE[MathHelper.floor((ticks + partialTicks) * 0.75f) % TEXTURE.length];
        mc.renderEngine.bindTexture(curTex);
        GlStateManager.color(0.2f, 0.5f, 0.6f, 0.5f);
        AreaRenderer.renderArea(selArea, false, true, 0.01f);
        GlStateManager.color(0.4f, 0.65f, 0.8f, 0.75f);
        AreaRenderer.renderArea(selArea, false, false, 0.01f);
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.002f);
        GlStateManager.disableBlend();
    }
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) ItemBlockSelectorFloating(ivorius.reccomplex.item.ItemBlockSelectorFloating) EnumHand(net.minecraft.util.EnumHand) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft)

Example 14 with SelectionOwner

use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.

the class CommandGenerateStructure method execute.

@Override
@ParametersAreNonnullByDefault
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "select");
    String structureID = parameters.get().first().require();
    Structure<?> structure = parameters.rc().structure().require();
    WorldServer world = parameters.mc("dimension").dimension(server, sender).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(null);
    GenerationType generationType = parameters.rc("gen").generationType(structure).require();
    BlockSurfacePos pos = parameters.surfacePos("x", "z", sender.getPosition(), false).require();
    String seed = parameters.get("seed").first().optional().orElse(null);
    boolean select = parameters.has("select");
    Placer placer = generationType.placer();
    StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).generationInfo(generationType).seed(RCStrings.seed(seed)).structureID(structureID).randomPosition(pos, placer).fromCenter(true).transform(transform);
    Optional<StructureBoundingBox> boundingBox = generator.boundingBox();
    if (!boundingBox.isPresent())
        throw ServerTranslations.commandException("commands.strucGen.noPlace");
    if (structure instanceof GenericStructure && world == sender.getEntityWorld()) {
        GenericStructure genericStructureInfo = (GenericStructure) structure;
        BlockPos lowerCoord = StructureBoundingBoxes.min(boundingBox.get());
        OperationRegistry.queueOperation(new OperationGenerateStructure(genericStructureInfo, generationType.id(), generator.transform(), lowerCoord, false).withSeed(seed).withStructureID(structureID).prepare(world), sender);
    } else {
        if (generator.generate() == null)
            throw ServerTranslations.commandException("commands.strucGen.noPlace");
    }
    if (select) {
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox.get()));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) 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) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 15 with SelectionOwner

use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.

the class CommandExportSchematic method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    BlockArea area = selectionOwner.getSelection();
    RCCommands.assertSize(commandSender, selectionOwner);
    String structureName = parameters.get().first().optional().orElse("NewStructure_" + commandSender.getEntityWorld().rand.nextInt(1000));
    BlockPos lowerCoord = area.getLowerCorner();
    BlockPos higherCoord = area.getHigherCorner();
    IvWorldData data = IvWorldData.capture(commandSender.getEntityWorld(), new BlockArea(lowerCoord, higherCoord), true);
    SchematicFile schematicFile = toSchematic(data);
    SchematicLoader.writeSchematicByName(schematicFile, structureName);
    commandSender.sendMessage(ServerTranslations.format("commands.strucExportSchematic.success", structureName));
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) SchematicFile(ivorius.reccomplex.world.gen.feature.structure.schematics.SchematicFile) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)17 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)14 BlockPos (net.minecraft.util.math.BlockPos)12 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)8 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)6 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)5 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)5 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)4 MockWorld (ivorius.ivtoolkit.world.MockWorld)4 RCConfig (ivorius.reccomplex.RCConfig)4 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)4 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 CommandException (net.minecraft.command.CommandException)4 ICommandSender (net.minecraft.command.ICommandSender)4 MinecraftServer (net.minecraft.server.MinecraftServer)4 WorldServer (net.minecraft.world.WorldServer)4