use of ivorius.ivtoolkit.math.AxisAlignedTransform2D in project RecurrentComplex by Ivorforce.
the class WorldScriptMazeGenerator method getPlacedRooms.
public List<PlacedMazeComponent<MazeComponentStructure<Connector>, Connector>> getPlacedRooms(Random random, AxisAlignedTransform2D transform, Environment environment) {
if (mazeComponent.rooms.isEmpty())
return null;
ConnectorFactory factory = new ConnectorFactory();
Connector wallConnector = factory.get(ConnectorStrategy.DEFAULT_WALL);
Connector defaultConnector = mazeComponent.defaultConnector.toConnector(factory);
// TODO Make configurable
Set<Connector> blockedConnections = Collections.singleton(wallConnector);
int[] boundsHigher = mazeComponent.rooms.boundsHigher();
int[] boundsLower = mazeComponent.rooms.boundsLower();
int[] oneArray = new int[boundsHigher.length];
Arrays.fill(oneArray, 1);
final int[] outsideBoundsHigher = IvVecMathHelper.add(boundsHigher, oneArray);
final int[] outsideBoundsLower = IvVecMathHelper.sub(boundsLower, oneArray);
List<MazeComponentStructure<Connector>> transformedComponents = StructureRegistry.INSTANCE.getStructuresInMaze(mazeID).flatMap(pair -> pair.getLeft().declaredVariables().omega(environment, true).flatMap(domain -> WorldGenMaze.transforms(pair.getLeft(), pair.getRight(), transform, factory, environment.copy(domain), blockedConnections))).collect(Collectors.toList());
MorphingMazeComponent<Connector> maze = new SetMazeComponent<>();
WorldScriptMazeGenerator.enclose(maze, new MazeRoom(outsideBoundsLower), new MazeRoom(outsideBoundsHigher), defaultConnector);
WorldScriptMazeGenerator.blockRooms(maze, mazeComponent.rooms.compile(false).keySet(), defaultConnector);
WorldGenMaze.buildExitPaths(environment, factory, mazeComponent.exitPaths, maze.rooms()).forEach(path -> maze.exits().put(path.getKey(), path.getValue()));
// Add reachability outside the maze
maze.reachability().putAll(WorldGenMaze.addExternalReachability(ImmutableListMultimap.builder(), maze.exits(), blockedConnections).build());
// Add reachability between exits
maze.reachability().putAll(mazeComponent.reachability.build(ImmutableListMultimap.builder(), AxisAlignedTransform2D.ORIGINAL, mazeComponent.boundsSize(), SavedMazeReachability.notBlocked(blockedConnections, maze.exits()), maze.exits().keySet()).build());
ConnectorStrategy connectorStrategy = new ConnectorStrategy();
List<MazePredicate<Connector>> predicates = rules.stream().map(r -> r.build(this, blockedConnections, factory, transformedComponents, connectorStrategy)).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));
predicates.add(new LimitAABBStrategy<>(outsideBoundsHigher));
predicates.add(new BlockedConnectorStrategy<>(blockedConnections));
int totalRooms = mazeComponent.rooms.compile(true).size();
return MazeComponentConnector.connect(maze, transformedComponents, connectorStrategy, new MazePredicateMany<>(predicates), random, RCConfig.mazePlacementReversesPerRoom >= 0 ? MathHelper.floor(totalRooms * RCConfig.mazePlacementReversesPerRoom + 0.5f) : MazeComponentConnector.INFINITE_REVERSES);
}
use of ivorius.ivtoolkit.math.AxisAlignedTransform2D in project RecurrentComplex by Ivorforce.
the class WorldScriptStructureGenerator method prepareInstanceData.
@Override
public InstanceData prepareInstanceData(StructurePrepareContext context, BlockPos pos) {
WorldScriptStructureGenerator.InstanceData instanceData = null;
Random random = context.random;
AxisAlignedTransform2D transform = context.transform;
if (simpleMode) {
if (structureNames.size() > 0) {
String structureID = structureNames.get(random.nextInt(structureNames.size()));
Structure<?> structure = StructureRegistry.INSTANCE.get(structureID);
if (structure != null) {
int rotations = structure.isRotatable() ? (structureRotation != null ? transform.getRotation() + structureRotation : random.nextInt(4)) : 0;
boolean mirrorX = structure.isMirrorable() && (structureMirror != null ? transform.isMirrorX() != structureMirror : random.nextBoolean());
AxisAlignedTransform2D strucTransform = AxisAlignedTransform2D.from(rotations, mirrorX);
int[] strucSize = structure.size();
BlockPos strucCoord = transform.apply(structureShift, new int[] { 1, 1, 1 }).subtract(transform.apply(BlockPos.ORIGIN, strucSize)).add(pos);
instanceData = new WorldScriptStructureGenerator.InstanceData(structureID, null, strucCoord, strucTransform, new StructureGenerator<>(structure).seed(random.nextLong()).environment(context.environment).transform(strucTransform).lowerCoord(strucCoord).asSource(context.generateAsSource).instanceData().orElse(null));
}
}
} else {
Collection<Pair<Structure<?>, ListGeneration>> generationInfos = StructureRegistry.INSTANCE.getStructuresInList(structureListID, front).collect(Collectors.toList());
if (generationInfos.size() > 0) {
Pair<Structure<?>, ListGeneration> pair = WeightedSelector.select(random, generationInfos, item -> RCConfig.tweakedSpawnRate(StructureRegistry.INSTANCE.id(item.getLeft())) * item.getRight().getWeight());
Structure<?> structure = pair.getLeft();
String structureID = StructureRegistry.INSTANCE.id(structure);
ListGeneration generationInfo = pair.getRight();
boolean mirrorX;
int rotations;
if (front != null) {
EnumFacing curFront = Directions.rotate(front, transform);
mirrorX = structure.isMirrorable() && structure.isRotatable() && random.nextBoolean();
Integer neededRotations = Directions.getHorizontalClockwiseRotations(curFront, generationInfo.front, mirrorX);
rotations = neededRotations != null ? neededRotations : 0;
} else {
mirrorX = structure.isMirrorable() && random.nextBoolean();
rotations = structure.isRotatable() ? random.nextInt(4) : 0;
}
AxisAlignedTransform2D strucTransform = AxisAlignedTransform2D.from(rotations, mirrorX);
int[] strucSize = structure.size();
BlockPos strucCoord = transform.apply(structureShift.add(generationInfo.shift), new int[] { 1, 1, 1 }).subtract(transform.apply(BlockPos.ORIGIN, strucSize)).add(pos);
instanceData = new WorldScriptStructureGenerator.InstanceData(structureID, generationInfo.id(), strucCoord, strucTransform, new StructureGenerator<>(structure).seed(random.nextLong()).environment(context.environment).transform(strucTransform).asSource(context.generateAsSource).lowerCoord(strucCoord).instanceData().orElse(null));
}
}
return instanceData != null ? instanceData : new WorldScriptStructureGenerator.InstanceData();
}
use of ivorius.ivtoolkit.math.AxisAlignedTransform2D 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;
AxisAlignedTransform2D transform = getTransform(vanillaGenInfo.front, mirrorX, getCoordBaseMode().getOpposite());
instanceData = new StructureGenerator<>(structure).seed(seed).environment(environment(world, generationType)).transform(transform).boundingBox(boundingBox).instanceData().map(NBTStorable::writeToNBT).orElse(null);
}
Aggregations