Search in sources :

Example 1 with GenerationType

use of ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType 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;
    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);
    return true;
}
Also used : 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 2 with GenerationType

use of ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType 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;
    AxisAlignedTransform2D transform = GenericVillagePiece.getTransform(vanillaGenInfo.front, structure.isMirrorable(), structure.isRotatable(), front.getOpposite(), random);
    if (!vanillaGenInfo.generatesIn(startPiece.biome) || transform == null)
        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, transform, 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 3 with GenerationType

use of ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType 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)

Example 4 with GenerationType

use of ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType in project RecurrentComplex by Ivorforce.

the class GenericVillagePiece method prepare.

public void prepare(WorldServer world) {
    Structure<?> structure = StructureRegistry.INSTANCE.get(structureID);
    if (structure == null)
        return;
    GenerationType generationType = structure.generationType(generationID);
    if (!(generationType instanceof VanillaGeneration))
        return;
    VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
    instanceData = new StructureGenerator<>(structure).seed(seed).environment(environment(world, generationType)).transform(transform).boundingBox(boundingBox).instanceData().map(NBTStorable::writeToNBT).orElse(null);
}
Also used : StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) VanillaGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaGeneration) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)

Example 5 with GenerationType

use of ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType in project RecurrentComplex by Ivorforce.

the class GenericVillageCreationHandler method getVillagePieceWeight.

@Override
public StructureVillagePieces.PieceWeight getVillagePieceWeight(Random random, int villageSize) {
    Structure structure = StructureRegistry.INSTANCE.hasActive(structureID) ? StructureRegistry.INSTANCE.get(structureID) : null;
    if (structure != null) {
        float tweakedWeight = RCConfig.tweakedSpawnRate(structureID);
        GenerationType generationType = structure.generationType(generationID);
        if (generationType instanceof VanillaGeneration) {
            VanillaGeneration vanillaGenInfo = (VanillaGeneration) generationType;
            int spawnLimit = MathHelper.floor(MathHelper.nextDouble(random, vanillaGenInfo.minBaseLimit + villageSize * vanillaGenInfo.minScaledLimit, vanillaGenInfo.maxBaseLimit + villageSize * vanillaGenInfo.maxScaledLimit) + 0.5);
            return new StructureVillagePieces.PieceWeight(getComponentClass(), vanillaGenInfo.getVanillaWeight(tweakedWeight), spawnLimit);
        }
    }
    return new StructureVillagePieces.PieceWeight(getComponentClass(), 0, 0);
}
Also used : 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)

Aggregations

GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)5 VanillaGeneration (ivorius.reccomplex.world.gen.feature.structure.generic.generation.VanillaGeneration)4 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)2 StructureGenerator (ivorius.reccomplex.world.gen.feature.StructureGenerator)2 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)2 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 Parameters (ivorius.mcopts.commands.parameters.Parameters)1 NBTStorable (ivorius.reccomplex.nbt.NBTStorable)1 OperationGenerateStructure (ivorius.reccomplex.operation.OperationGenerateStructure)1 Placer (ivorius.reccomplex.world.gen.feature.structure.Placer)1 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)1 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)1