Search in sources :

Example 11 with AxisAlignedTransform2D

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);
}
Also used : IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) NBTTagLists(ivorius.ivtoolkit.tools.NBTTagLists) java.util(java.util) TIntArrayList(gnu.trove.list.array.TIntArrayList) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) Constants(net.minecraftforge.common.util.Constants) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) RCConfig(ivorius.reccomplex.RCConfig) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) MazeRule(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.MazeRule) NBTTagList(net.minecraft.nbt.NBTTagList) IvNBTHelper(ivorius.ivtoolkit.tools.IvNBTHelper) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) IvVecMathHelper(ivorius.ivtoolkit.math.IvVecMathHelper) IntAreas(ivorius.reccomplex.utils.IntAreas) BlockedConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.BlockedConnectorStrategy) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StructureLoadContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext) ivorius.reccomplex.world.gen.feature.structure.generic.maze(ivorius.reccomplex.world.gen.feature.structure.generic.maze) StructurePrepareContext(ivorius.reccomplex.world.gen.feature.structure.context.StructurePrepareContext) NBTBase(net.minecraft.nbt.NBTBase) BlockPositions(ivorius.ivtoolkit.blocks.BlockPositions) BlockPos(net.minecraft.util.math.BlockPos) Selection(ivorius.reccomplex.world.gen.feature.structure.generic.Selection) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) LimitAABBStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.LimitAABBStrategy) MathHelper(net.minecraft.util.math.MathHelper) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) TableDataSourceWorldScriptMazeGenerator(ivorius.reccomplex.gui.worldscripts.mazegenerator.TableDataSourceWorldScriptMazeGenerator) ivorius.ivtoolkit.maze.components(ivorius.ivtoolkit.maze.components) MazeRuleRegistry(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.MazeRuleRegistry) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) NBTCompoundObjects(ivorius.ivtoolkit.tools.NBTCompoundObjects) BlockedConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.BlockedConnectorStrategy)

Example 12 with AxisAlignedTransform2D

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();
}
Also used : TableDataSourceWorldScriptStructureGenerator(ivorius.reccomplex.gui.worldscripts.structuregenerator.TableDataSourceWorldScriptStructureGenerator) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) EnumFacing(net.minecraft.util.EnumFacing) NBTTagString(net.minecraft.nbt.NBTTagString) ListGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.ListGeneration) BlockPos(net.minecraft.util.math.BlockPos) Pair(org.apache.commons.lang3.tuple.Pair)

Example 13 with AxisAlignedTransform2D

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);
}
Also used : StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) 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)

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