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