Search in sources :

Example 1 with StructureGenerator

use of ivorius.reccomplex.world.gen.feature.StructureGenerator in project RecurrentComplex by Ivorforce.

the class CommandPaste method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "generate", "select");
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
    RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
    NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
    if (worldData == null)
        throw ServerTranslations.commandException("commands.strucPaste.noClipboard");
    WorldServer world = (WorldServer) sender.getEntityWorld();
    BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    String seed = parameters.get("seed").first().optional().orElse(null);
    boolean generate = parameters.has("generate");
    boolean select = parameters.has("select");
    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 (select) {
        StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // Can never not place so don't handle
        //noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
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) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) 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 2 with StructureGenerator

use of ivorius.reccomplex.world.gen.feature.StructureGenerator in project RecurrentComplex by Ivorforce.

the class CommandImportStructure method execute.

@Override
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(AxisAlignedTransform2D.ORIGINAL);
    BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
    boolean select = parameters.has("select");
    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 (select) {
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
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) WorldServer(net.minecraft.world.WorldServer) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 3 with StructureGenerator

use of ivorius.reccomplex.world.gen.feature.StructureGenerator in project RecurrentComplex by Ivorforce.

the class RCBiomeDecorator method generateSurface.

public static boolean generateSurface(Pair<Structure<?>, VanillaDecorationGeneration> generation, WorldServer worldIn, ChunkPos chunkPos, Random random) {
    long seed = random.nextLong();
    BlockPos shift = generation.getRight().spawnShift;
    return new StructureGenerator<>(generation.getLeft()).generationInfo(generation.getRight()).world(worldIn).seed(seed).maturity(StructureSpawnContext.GenerateMaturity.SUGGEST).memorize(RCConfig.memorizeDecoration).allowOverlaps(true).randomPosition(WorldGenStructures.randomSurfacePos(chunkPos, seed).add(shift.getX(), shift.getZ()), // Shift +1 because surface placer goes -1
    shift(generation.getRight().placer(), shift.getY() + 1)).fromCenter(true).generate() != null;
}
Also used : StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with StructureGenerator

use of ivorius.reccomplex.world.gen.feature.StructureGenerator in project RecurrentComplex by Ivorforce.

the class CommandSelectMove method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "noselect");
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockPos pos = parameters.pos("x", "y", "z", selectionOwner.getSelectedPoint1(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    boolean noselect = parameters.has("noselect");
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldDataCompound;
    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.world.gen.feature.structure.OperationGenerateStructure) 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) OperationClearArea(ivorius.reccomplex.world.gen.feature.structure.OperationClearArea) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationMulti(ivorius.reccomplex.world.gen.feature.structure.OperationMulti) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 5 with StructureGenerator

use of ivorius.reccomplex.world.gen.feature.StructureGenerator in project RecurrentComplex by Ivorforce.

the class RCSaplingGenerator method growSapling.

public static void growSapling(WorldServer world, BlockPos pos, Random random, Structure<?> structure, SaplingGeneration saplingGenInfo) {
    int[] strucSize = structure.size();
    Multimap<AxisAlignedTransform2D, BlockPos> placeables = saplingGenInfo.pattern.testAll(world, pos, strucSize, structure.isRotatable(), structure.isMirrorable());
    // Use keys() here to get the correct distribution
    AxisAlignedTransform2D transform = Lists.newArrayList(placeables.keys()).get(random.nextInt(placeables.keys().size()));
    Collection<BlockPos> transformedPositions = placeables.get(transform);
    BlockPos startPos = Lists.newArrayList(transformedPositions).get(random.nextInt(transformedPositions.size()));
    Map<BlockPos, IBlockState> before = new HashMap<>();
    IBlockState air = Blocks.AIR.getDefaultState();
    saplingGenInfo.pattern.copy(transform, strucSize).forEach(i -> i.delete, entry -> {
        BlockPos ePos = entry.getKey().add(startPos);
        before.put(ePos, world.getBlockState(ePos));
        world.setBlockState(ePos, air, 4);
    });
    BlockPos spawnPos = transform.apply(saplingGenInfo.spawnShift, new int[] { 1, 1, 1 }).add(startPos);
    boolean success = new StructureGenerator<>(structure).world(world).generationInfo(saplingGenInfo).transform(transform).seed(random.nextLong()).maturity(StructureSpawnContext.GenerateMaturity.SUGGEST).memorize(RCConfig.memorizeSaplings).allowOverlaps(true).randomPosition(BlockSurfacePos.from(spawnPos), (context, blockCollection) -> spawnPos.getY()).generate() != null;
    if (!success)
        before.forEach((pos1, state) -> world.setBlockState(pos1, state, 4));
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) java.util(java.util) Blocks(net.minecraft.init.Blocks) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) World(net.minecraft.world.World) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) Multimap(com.google.common.collect.Multimap) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IBlockState(net.minecraft.block.state.IBlockState) IvFunctions(ivorius.ivtoolkit.util.IvFunctions) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorldServer(net.minecraft.world.WorldServer) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Nullable(javax.annotation.Nullable) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) IBlockState(net.minecraft.block.state.IBlockState) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

StructureGenerator (ivorius.reccomplex.world.gen.feature.StructureGenerator)6 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)5 BlockPos (net.minecraft.util.math.BlockPos)5 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)4 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)3 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)3 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)3 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)3 WorldServer (net.minecraft.world.WorldServer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 WeightedSelector (ivorius.ivtoolkit.random.WeightedSelector)1 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)1 IvFunctions (ivorius.ivtoolkit.util.IvFunctions)1 RCConfig (ivorius.reccomplex.RCConfig)1 RCEntityInfo (ivorius.reccomplex.capability.RCEntityInfo)1