Search in sources :

Example 1 with Environment

use of ivorius.reccomplex.world.gen.feature.structure.Environment in project RecurrentComplex by Ivorforce.

the class RCSaplingGenerator method findRandomSapling.

@Nullable
public static Pair<Structure<?>, SaplingGeneration> findRandomSapling(WorldServer world, BlockPos pos, Random random, boolean considerVanilla) {
    Environment baseEnv = Environment.inNature(world, new StructureBoundingBox(pos, pos));
    List<Pair<Structure<?>, SaplingGeneration>> applicable = StructureRegistry.INSTANCE.getStructureGenerations(SaplingGeneration.class).stream().filter(pair1 -> pair1.getRight().generatesIn(baseEnv.withGeneration(pair1.getRight()))).collect(Collectors.toCollection(ArrayList::new));
    // Hackily consider big vanilla trees too
    int vanillaComplexity = complexity(world, pos, random, predictors);
    ImmutableMultimap<Integer, Pair<Structure<?>, SaplingGeneration>> groups = IvFunctions.groupMap(applicable, pair -> pair.getRight().pattern.pattern.compile(true).size());
    List<Integer> complexities = Lists.newArrayList(groups.keySet());
    if (vanillaComplexity > 0)
        complexities.add(vanillaComplexity);
    Collections.sort(complexities);
    Pair<Structure<?>, SaplingGeneration> pair = null;
    while (complexities.size() > 0 && pair == null) {
        Integer complexity = complexities.remove(complexities.size() - 1);
        Set<Pair<Structure<?>, SaplingGeneration>> placeable = groups.get(complexity).stream().filter(p -> p.getRight().pattern.canPlace(world, pos, p.getLeft().size(), p.getLeft().isRotatable(), p.getLeft().isMirrorable())).collect(Collectors.toSet());
        double totalWeight = placeable.stream().mapToDouble(RCSaplingGenerator::getSpawnWeight).sum();
        if (complexity == vanillaComplexity && considerVanilla) {
            if (random.nextDouble() * (totalWeight * RCConfig.baseSaplingSpawnWeight + 1) < 1)
                break;
        }
        if (totalWeight > 0)
            pair = WeightedSelector.select(random, placeable, RCSaplingGenerator::getSpawnWeight);
    }
    return pair;
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) java.util(java.util) Blocks(net.minecraft.init.Blocks) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) World(net.minecraft.world.World) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) Multimap(com.google.common.collect.Multimap) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IBlockState(net.minecraft.block.state.IBlockState) IvFunctions(ivorius.ivtoolkit.util.IvFunctions) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorldServer(net.minecraft.world.WorldServer) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Nullable(javax.annotation.Nullable) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 2 with Environment

use of ivorius.reccomplex.world.gen.feature.structure.Environment 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 3 with Environment

use of ivorius.reccomplex.world.gen.feature.structure.Environment in project RecurrentComplex by Ivorforce.

the class TransformerAbstractCloud method buildCloud.

public TObjectDoubleMap<BlockPos> buildCloud(S instanceData, IvWorldData worldData, StructurePrepareContext context, TransformerMulti transformer, TransformerMulti.InstanceData transformerInstanceData) {
    Random random = context.random;
    Environment environment = context.environment;
    BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
    int[] strucSize = new int[] { worldData.blockCollection.width, worldData.blockCollection.height, worldData.blockCollection.length };
    TObjectDoubleMap<BlockPos> cloud = new TObjectDoubleHashMap<>();
    BlurredValueField blurredValueField = new BlurredValueField(strucSize);
    int gridCoords = 1;
    for (int d : strucSize) gridCoords *= d;
    int values = MathHelper.floor(gridCoords * (1f / 25f) + 0.5f);
    for (int i = 0; i < values; i++) blurredValueField.addValue(1 + (random.nextFloat() - random.nextFloat()) * (float) cloudExpansionRandomization() / 100f, random);
    BlockAreas.mutablePositions(worldData.blockCollection.area()).forEach(pos -> {
        IBlockState state = worldData.blockCollection.getBlockState(pos);
        BlockPos worldCoord = context.transform.apply(pos, strucSize).add(lowerCoord);
        if (matches(instanceData, state) && canPenetrate(environment, worldData, worldCoord, 1, transformer, transformerInstanceData))
            cloud.put(pos.toImmutable(), 1);
    });
    double expansionDistance = cloudExpansionDistance();
    BlockPos.MutableBlockPos sidePos = new BlockPos.MutableBlockPos();
    BlockPos.MutableBlockPos sideWorldCoord = new BlockPos.MutableBlockPos();
    if (expansionDistance > 0.000001) {
        // The code below will be called _often_, so let's cache the divisions
        double[] sideFalloffs = new double[6];
        List<EnumFacing> checkSides = new ArrayList<>();
        for (EnumFacing side : EnumFacing.values()) {
            double sideExpansionDistance = cloudExpansionDistance(side);
            double sideFalloff = sideExpansionDistance > 0.000001 ? 1.0f / sideExpansionDistance / expansionDistance : 0;
            if (sideFalloff > 0) {
                checkSides.add(side);
                sideFalloffs[side.getIndex()] = sideFalloff;
            }
        }
        visitRecursively(Sets.newHashSet(cloud.keySet()), (changed, pos) -> {
            double density = cloud.get(pos);
            for (EnumFacing side : checkSides) {
                double sideFalloff = sideFalloffs[side.getIndex()];
                IvMutableBlockPos.offset(pos, sidePos, side);
                double sideDensity = density - sideFalloff * blurredValueField.getValue(sidePos.getX(), sidePos.getY(), sidePos.getZ());
                if (sideDensity <= 0 || cloud.get(sidePos) >= sideDensity - 0.00001)
                    continue;
                IvMutableBlockPos.add(context.transform.applyOn(sidePos, sideWorldCoord, strucSize), lowerCoord);
                if (!canPenetrate(environment, worldData, sideWorldCoord, sideDensity, transformer, transformerInstanceData))
                    continue;
                BlockPos immutableSidePos = sidePos.toImmutable();
                cloud.put(immutableSidePos, sideDensity);
                changed.add(immutableSidePos);
            }
            return true;
        });
    }
    return cloud;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlurredValueField(ivorius.ivtoolkit.random.BlurredValueField) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos)

Aggregations

Environment (ivorius.reccomplex.world.gen.feature.structure.Environment)3 BlockPos (net.minecraft.util.math.BlockPos)3 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)2 RCConfig (ivorius.reccomplex.RCConfig)2 StructureRegistry (ivorius.reccomplex.world.gen.feature.structure.StructureRegistry)2 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 IBlockState (net.minecraft.block.state.IBlockState)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)1 BlockPositions (ivorius.ivtoolkit.blocks.BlockPositions)1 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)1 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)1 IvVecMathHelper (ivorius.ivtoolkit.math.IvVecMathHelper)1 ivorius.ivtoolkit.maze.components (ivorius.ivtoolkit.maze.components)1