Search in sources :

Example 6 with AxisAlignedTransform2D

use of ivorius.ivtoolkit.math.AxisAlignedTransform2D in project RecurrentComplex by Ivorforce.

the class StructureGenerator method transform.

@Nonnull
public AxisAlignedTransform2D transform() {
    if (this.transform != null)
        return this.transform;
    else {
        Structure<S> structure = structure();
        Random random = new Random(seed() ^ TRANSFORM_SEED);
        AxisAlignedTransform2D transform = AxisAlignedTransform2D.from(structure.isRotatable() ? random.nextInt(4) : 0, structure.isMirrorable() && random.nextBoolean());
        return this.transform = transform;
    }
}
Also used : Random(java.util.Random) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) Nonnull(javax.annotation.Nonnull)

Example 7 with AxisAlignedTransform2D

use of ivorius.ivtoolkit.math.AxisAlignedTransform2D in project RecurrentComplex by Ivorforce.

the class GenericVillageCreationHandler method buildComponent.

@Override
public StructureVillagePieces.Village buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List<StructureComponent> pieces, Random random, int x, int y, int z, EnumFacing front, int generationDepth) {
    Structure structure = StructureRegistry.INSTANCE.get(structureID);
    if (structure == null)
        return kill(villagePiece);
    GenerationType generationType = structure.generationType(generationID);
    if (!(generationType instanceof VanillaGeneration))
        return kill(villagePiece);
    VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
    boolean mirrorX = structure.isMirrorable() && random.nextBoolean();
    AxisAlignedTransform2D transform = GenericVillagePiece.getTransform(vanillaGenInfo.front, mirrorX, front.getOpposite());
    if (!vanillaGenInfo.generatesIn(startPiece.biome) || (!structure.isRotatable() && transform.getRotation() != 0))
        return kill(villagePiece);
    int[] structureSize = RCAxisAlignedTransform.applySize(transform, structure.size());
    StructureBoundingBox strucBB = Structures.boundingBox(new BlockPos(x, y, z), structureSize);
    if (!GenericVillagePiece.canVillageGoDeeperC(strucBB) || StructureComponent.findIntersecting(pieces, strucBB) != null)
        return null;
    GenericVillagePiece genericVillagePiece = GenericVillagePiece.create(structureID, generationID, startPiece, generationDepth);
    genericVillagePiece.seed = random.nextLong();
    if (genericVillagePiece == null)
        return kill(villagePiece);
    genericVillagePiece.setIds(structureID, generationID);
    genericVillagePiece.setOrientation(front, mirrorX, strucBB);
    return genericVillagePiece;
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockPos(net.minecraft.util.math.BlockPos) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) VanillaGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaGeneration) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)

Example 8 with AxisAlignedTransform2D

use of ivorius.ivtoolkit.math.AxisAlignedTransform2D in project RecurrentComplex by Ivorforce.

the class GenericVillagePiece method addComponentParts.

@Override
@ParametersAreNonnullByDefault
public boolean addComponentParts(World world, Random random, StructureBoundingBox boundingBox) {
    Structure<?> structure = StructureRegistry.INSTANCE.get(structureID);
    if (structure == null)
        return false;
    GenerationType generationType = structure.generationType(generationID);
    if (!(generationType instanceof VanillaGeneration))
        return false;
    VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
    AxisAlignedTransform2D transform = getCoordBaseMode() != null ? getTransform(vanillaGenInfo.front, mirrorX, getCoordBaseMode().getOpposite()) : AxisAlignedTransform2D.ORIGINAL;
    BlockPos structureShift = transform.apply(vanillaGenInfo.spawnShift, new int[] { 1, 1, 1 });
    if (this.averageGroundLvl < 0) {
        this.averageGroundLvl = this.getAverageGroundLevel(world, boundingBox);
        if (this.averageGroundLvl < 0)
            return true;
        // Structure shift y was included in bounding box, but must be re-added because it is overwritten
        this.boundingBox.offset(0, this.averageGroundLvl - this.boundingBox.minY + structureShift.getY(), 0);
    }
    if (world instanceof WorldServer)
        generate((WorldServer) world, boundingBox, structure, generationType, transform);
    return true;
}
Also used : AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) VanillaGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaGeneration) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 9 with AxisAlignedTransform2D

use of ivorius.ivtoolkit.math.AxisAlignedTransform2D 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 10 with AxisAlignedTransform2D

use of ivorius.ivtoolkit.math.AxisAlignedTransform2D 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

AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)13 BlockPos (net.minecraft.util.math.BlockPos)11 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)6 WorldServer (net.minecraft.world.WorldServer)6 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)6 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)5 StructureGenerator (ivorius.reccomplex.world.gen.feature.StructureGenerator)5 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)4 GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)2 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)2 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)2 RCConfig (ivorius.reccomplex.RCConfig)2 NBTStorable (ivorius.reccomplex.nbt.NBTStorable)2 Environment (ivorius.reccomplex.world.gen.feature.structure.Environment)2 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)2 StructureRegistry (ivorius.reccomplex.world.gen.feature.structure.StructureRegistry)2 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)2