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;
}
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;
}
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()));
}
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);
}
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);
}
Aggregations