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