Search in sources :

Example 16 with Holder

use of net.minecraft.core.Holder in project Brass_Amber_BattleTowers by BrassAmber-Mods.

the class OceanBattleTower method createPiecesGenerator.

@NotNull
public static Optional<PieceGenerator<JigsawConfiguration>> createPiecesGenerator(PieceGeneratorSupplier.Context<JigsawConfiguration> context) {
    // Check if the spot is valid for our structure. This is just as another method for cleanness.
    // Returning an empty optional tells the game to skip this spot as it will not generate the structure. -- TelepathicGrunt
    Predicate<Holder<Biome>> predicate = context.validBiome();
    Optional<PieceGenerator<JigsawConfiguration>> piecesGenerator;
    int firstTowerDistance = BattleTowersConfig.firstTowerDistance.get();
    int minimumSeparation = BattleTowersConfig.oceanMinimumSeperation.get();
    int seperationRange = BattleTowersConfig.oceanAverageSeperationModifier.get();
    ChunkPos chunkPos = context.chunkPos();
    WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenRandom.setLargeFeatureSeed(context.seed(), chunkPos.x, chunkPos.z);
    boolean firstTowerDistanceCheck = (int) Mth.absMax(chunkPos.x, chunkPos.z) >= firstTowerDistance;
    BrassAmberBattleTowers.LOGGER.info("ocean current distance " + (int) Mth.absMax(chunkPos.x, chunkPos.z) + "  config f distance " + BattleTowersConfig.firstTowerDistance.get());
    int nextSeperation = minimumSeparation + worldgenRandom.nextInt(seperationRange);
    int spawnDistance = Math.min(Mth.abs(chunkPos.x - lastSpawnPosition.x), Mth.abs(chunkPos.z - lastSpawnPosition.z));
    BlockPos chunkCenter = context.chunkPos().getMiddleBlockPosition(0);
    int x = chunkCenter.getX();
    int z = chunkCenter.getZ();
    int y = context.chunkGenerator().getFirstFreeHeight(chunkCenter.getX(), chunkCenter.getZ(), Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
    Holder<Biome> biome = context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z));
    BlockPos spawnPos;
    if (firstTowerDistanceCheck && spawnDistance > nextSeperation && predicate.test(biome)) {
        spawnPos = isSpawnableChunk(context, worldgenRandom);
        BrassAmberBattleTowers.LOGGER.info("Biome correct? " + predicate.test(biome) + " Block: " + chunkCenter);
    } else {
        spawnPos = BlockPos.ZERO;
    }
    BrassAmberBattleTowers.LOGGER.info("ocean distance from last " + spawnDistance + "  config distance allowed " + nextSeperation);
    if (spawnPos.getY() != 0) {
        spawnPos = spawnPos.above(context.chunkGenerator().getSeaLevel() - 12);
        // Moved Biome check in JigsawPlacement outside
        BrassAmberBattleTowers.LOGGER.info("Spawnpos: " + spawnPos);
        int i;
        int j;
        int k;
        i = spawnPos.getX();
        j = spawnPos.getZ();
        k = spawnPos.getY() + context.chunkGenerator().getFirstFreeHeight(i, j, Heightmap.Types.WORLD_SURFACE_WG, context.heightAccessor());
        biome = context.chunkGenerator().getNoiseBiome(QuartPos.fromBlock(i), QuartPos.fromBlock(k), QuartPos.fromBlock(j));
        if (!predicate.test(biome)) {
            BrassAmberBattleTowers.LOGGER.info("Ocean tower incorrect biome " + biome);
            piecesGenerator = Optional.empty();
        } else {
            // All a structure has to do is call this method to turn it into a jigsaw based structure!
            piecesGenerator = BTOceanJigsawPlacement.addPieces(// Used for JigsawPlacement to get all the proper behaviors done.
            context, // Needed in order to create a list of jigsaw pieces when making the structure's layout.
            PoolElementStructurePiece::new, spawnPos);
        // Return the pieces generator that is now set up so that the game runs it when it needs to create the layout of structure pieces
        }
        if (piecesGenerator.isPresent()) {
            // I use to debug and quickly find out if the structure is spawning or not and where it is.
            // This is returning the coordinates of the center starting piece.
            BrassAmberBattleTowers.LOGGER.info("Ocean Tower at " + spawnPos);
            lastSpawnPosition = context.chunkPos();
        }
        return piecesGenerator;
    }
    return Optional.empty();
}
Also used : Biome(net.minecraft.world.level.biome.Biome) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) Holder(net.minecraft.core.Holder) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) BlockPos(net.minecraft.core.BlockPos) PieceGenerator(net.minecraft.world.level.levelgen.structure.pieces.PieceGenerator) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with Holder

use of net.minecraft.core.Holder in project TerraFirmaCraft by TerraFirmaCraft.

the class LocateVeinCommand method locateVein.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static int locateVein(CommandContext<CommandSourceStack> context, ResourceLocation veinName) throws CommandSyntaxException {
    final ServerLevel world = context.getSource().getLevel();
    final BlockPos sourcePos = new BlockPos(context.getSource().getPosition());
    final ChunkPos pos = new ChunkPos(sourcePos);
    final ConfiguredFeature<?, ? extends VeinFeature<?, ?>> vein = LocateVeinCommand.getVeins().get(veinName);
    final ArrayList<? extends Vein> veins = new ArrayList<>();
    final Random random = new Random();
    final BiomeSource source = world.getChunkSource().getGenerator().getBiomeSource();
    final Climate.Sampler sampler = world.getChunkSource().getGenerator().climateSampler();
    final BiomeManager biomeManager = world.getBiomeManager().withDifferentSource((x, y, z) -> source.getNoiseBiome(x, y, z, sampler));
    final WorldGenerationContext generationContext = new WorldGenerationContext(world.getChunkSource().getGenerator(), world);
    final Function<BlockPos, Holder<Biome>> biomeQuery = biomeManager::getBiome;
    for (int radius = 0; radius <= 16; radius++) {
        for (int dz = -radius; dz <= radius; dz++) {
            final boolean zEdge = Math.abs(dz) == radius;
            for (int dx = -radius; dx <= radius; dx++) {
                boolean xEdge = Math.abs(dx) == radius;
                if (!xEdge && !zEdge) {
                    continue;
                }
                ((VeinFeature) vein.feature()).getVeinsAtChunk(world, generationContext, pos.x + dx, pos.z + dz, veins, (VeinConfig) vein.config(), random, biomeQuery);
                if (!veins.isEmpty()) {
                    final BlockPos veinPos = veins.get(0).getPos();
                    return showLocateResult(context.getSource(), veinName.toString(), sourcePos, veinPos, "commands.locate.success");
                }
            }
        }
    }
    throw ERROR_VEIN_NOT_FOUND.create(veinName.toString());
}
Also used : BiomeManager(net.minecraft.world.level.biome.BiomeManager) ServerLevel(net.minecraft.server.level.ServerLevel) Climate(net.minecraft.world.level.biome.Climate) Holder(net.minecraft.core.Holder) ArrayList(java.util.ArrayList) WorldGenerationContext(net.minecraft.world.level.levelgen.WorldGenerationContext) Random(java.util.Random) BiomeSource(net.minecraft.world.level.biome.BiomeSource) VeinFeature(net.dries007.tfc.world.feature.vein.VeinFeature) BlockPos(net.minecraft.core.BlockPos) ChunkPos(net.minecraft.world.level.ChunkPos)

Example 18 with Holder

use of net.minecraft.core.Holder in project TerraFirmaCraft by TerraFirmaCraft.

the class TFCBiomeSource method findBiomeHorizontal.

@Override
@Nullable
public Pair<BlockPos, Holder<Biome>> findBiomeHorizontal(int blockX, int blockY, int blockZ, int maxRadius, int step, Predicate<Holder<Biome>> biome, Random random, boolean findClosest, @Nullable Climate.Sampler sampler) {
    // todo: can we avoid querying getNoiseBiome and instead query getNoiseBiomeIgnoreClimate ? as it causes a chunk data lookup which we don't have
    final int minQuartX = QuartPos.fromBlock(blockX);
    final int minQuartZ = QuartPos.fromBlock(blockZ);
    final int maxQuartRadius = QuartPos.fromBlock(maxRadius);
    Pair<BlockPos, Holder<Biome>> pair = null;
    int count = 0;
    for (int radius = findClosest ? 0 : maxQuartRadius; radius <= maxQuartRadius; radius += step) {
        for (int dz = -radius; dz <= radius; dz += step) {
            final boolean atZEdge = Math.abs(dz) == radius;
            for (int dx = -radius; dx <= radius; dx += step) {
                if (findClosest) {
                    boolean atXEdge = Math.abs(dx) == radius;
                    if (!atXEdge && !atZEdge) {
                        continue;
                    }
                }
                final int x = minQuartX + dx, z = minQuartZ + dz;
                Holder<Biome> found = getNoiseBiome(x, z);
                if (biome.test(found)) {
                    if (pair == null || random.nextInt(count + 1) == 0) {
                        BlockPos pos = new BlockPos(QuartPos.toBlock(x), blockY, QuartPos.toBlock(z));
                        if (findClosest) {
                            return Pair.of(pos, found);
                        }
                        pair = Pair.of(pos, found);
                    }
                    count++;
                }
            }
        }
    }
    return pair;
}
Also used : Biome(net.minecraft.world.level.biome.Biome) Holder(net.minecraft.core.Holder) BlockPos(net.minecraft.core.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with Holder

use of net.minecraft.core.Holder in project TerraFirmaCraft by TerraFirmaCraft.

the class NoisyMultipleFeature method place.

@Override
public boolean place(FeaturePlaceContext<SimpleRandomFeatureConfiguration> context) {
    final BlockPos pos = context.origin();
    final ChunkDataProvider provider = ChunkDataProvider.get(context.chunkGenerator());
    final ChunkData data = provider.get(context.level(), pos);
    final int rotation = (int) Math.ceil(data.getForestWeirdness() * 10 * context.config().features.size());
    List<Holder<PlacedFeature>> features = context.config().features.stream().collect(Collectors.toList());
    Collections.rotate(features, rotation);
    int placed = 0;
    for (Holder<PlacedFeature> feature : features) {
        if (feature.value().placeWithBiomeCheck(context.level(), context.chunkGenerator(), context.random(), pos)) {
            placed++;
            if (placed > 1) {
                return true;
            }
        }
    }
    return placed > 0;
}
Also used : ChunkDataProvider(net.dries007.tfc.world.chunkdata.ChunkDataProvider) ChunkData(net.dries007.tfc.world.chunkdata.ChunkData) Holder(net.minecraft.core.Holder) BlockPos(net.minecraft.core.BlockPos) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature)

Aggregations

Holder (net.minecraft.core.Holder)19 BlockPos (net.minecraft.core.BlockPos)10 Biome (net.minecraft.world.level.biome.Biome)9 ArrayList (java.util.ArrayList)5 ChunkPos (net.minecraft.world.level.ChunkPos)5 Random (java.util.Random)4 Registry (net.minecraft.core.Registry)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 LevelChunkSection (net.minecraft.world.level.chunk.LevelChunkSection)3 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)2 Codec (com.mojang.serialization.Codec)2 Collections (java.util.Collections)2 Direction (net.minecraft.core.Direction)2 ResourceKey (net.minecraft.resources.ResourceKey)2