use of net.minecraft.core.Holder in project Denizen by DenizenScript.
the class ChunkHelperImpl method setAllBiomes.
@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
ChunkPos chunkcoordintpair = nmsChunk.getPos();
int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
PalettedContainer<Holder<Biome>> datapaletteblock = (PalettedContainer<Holder<Biome>>) chunksection.getBiomes();
datapaletteblock.acquire();
for (int l = 0; l < 4; ++l) {
for (int i1 = 0; i1 < 4; ++i1) {
for (int j1 = 0; j1 < 4; ++j1) {
datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
}
}
}
datapaletteblock.release();
}
}
use of net.minecraft.core.Holder in project Denizen by DenizenScript.
the class ChunkHelperImpl method setAllBiomes.
@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
Holder<Biome> nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
ChunkPos chunkcoordintpair = nmsChunk.getPos();
int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
PalettedContainer<Holder<Biome>> datapaletteblock = chunksection.getBiomes();
datapaletteblock.acquire();
for (int l = 0; l < 4; ++l) {
for (int i1 = 0; i1 < 4; ++i1) {
for (int j1 = 0; j1 < 4; ++j1) {
datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
}
}
}
datapaletteblock.release();
}
}
use of net.minecraft.core.Holder in project PrimalMagick by daedalus4096.
the class AbstractPhasingTree method growTree.
@Override
public boolean growTree(ServerLevel world, ChunkGenerator chunkGenerator, BlockPos pos, BlockState state, Random rand) {
Map<TimePhase, Holder<ConfiguredFeature<TreeConfiguration, ?>>> featureMap = this.getTreeFeaturesByPhase(rand, false);
TimePhase currentPhase = this.getCurrentPhase(world);
ConfiguredFeature<TreeConfiguration, ?> configuredFeature = featureMap.get(currentPhase).value();
if (configuredFeature == null) {
return false;
} else {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_INVISIBLE);
if (configuredFeature.place(world, chunkGenerator, rand, pos)) {
return true;
} else {
world.setBlock(pos, state, Block.UPDATE_INVISIBLE);
return false;
}
}
}
use of net.minecraft.core.Holder in project BYG by AOCAWOL.
the class BYGUtil method createBiomesFromBiomeData.
@SuppressWarnings("unchecked")
public static List<Holder<Biome>> createBiomesFromBiomeData(Registry<Biome> biomeRegistry, LayersBiomeData... layersBiomeDatas) {
List<Holder<Biome>> biomes = new ArrayList<>();
for (LayersBiomeData layersBiomeData : layersBiomeDatas) {
ImmutableList<WeightedEntry.Wrapper<ResourceKey<Biome>>> items = ((WeightedListAccess<WeightedEntry.Wrapper<ResourceKey<Biome>>>) layersBiomeData.biomeWeights()).byg_getItems();
for (WeightedEntry.Wrapper<ResourceKey<Biome>> key : items) {
ResourceKey<Biome> resourceKey = key.getData();
Optional<Holder<Biome>> biome = biomeRegistry.getHolder(resourceKey);
if (biome.isPresent()) {
biomes.add(biome.get());
} else {
BYG.LOGGER.info("\"" + resourceKey.location() + "\" is not a value in the biome registry at this point, ignore this warning if the data pack containing this biome is not yet added during world creation.");
}
}
}
return biomes;
}
use of net.minecraft.core.Holder in project BYG by AOCAWOL.
the class LargeLakeFeature method place.
public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, LargeLakeFeatureConfig config) {
setSeed(world.getSeed());
BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(blockPos);
BlockPos.MutableBlockPos mutable2 = new BlockPos.MutableBlockPos().set(mutable);
int xRadius = config.getRandomRadius(random) / 2;
int yRadius = config.getRandomDepth(random);
int zRadius = config.getRandomRadius(random) / 2;
List<BlockPos> positions = new ArrayList<>();
List<BlockPos> edgePositions = new ArrayList<>();
Function<BlockPos, BlockState> lakeBorderStateFunction = (blockPos3) -> config.borderStateProvider().getState(random, blockPos3);
Function<BlockPos, BlockState> lakeFloorStateFunction = (blockPos3) -> config.lakeFloorStateProvider().getState(random, blockPos3);
for (int x = -xRadius; x <= xRadius; x++) {
for (int z = -zRadius; z <= zRadius; z++) {
for (int y = -yRadius; y <= 0; y++) {
mutable2.set(mutable).move(x, y, z);
// Credits to Hex_26 for this equation!
double xSquared = Math.pow(x, 2);
double ySquared = Math.pow(y, 2);
double zSquared = Math.pow(z, 2);
double squaredDistance = xSquared + ySquared + zSquared;
double equationResult = xSquared / Math.pow(xRadius, 2) + ySquared / Math.pow(yRadius, 2) + zSquared / Math.pow(zRadius, 2);
double threshold = 1 + 1.4 * fastNoise.GetNoise(mutable2.getX(), mutable2.getY() * 2, mutable2.getZ());
if (equationResult >= threshold) {
continue;
}
if (squaredDistance <= xRadius * zRadius) {
BlockPos immutable = mutable2.immutable();
if (y < 0) {
positions.add(immutable);
}
} else {
double sizeAmplifier = 1.6;
if (y >= 0 && squaredDistance <= ((xRadius + (xRadius * sizeAmplifier)) * (zRadius + (zRadius * sizeAmplifier)))) {
edgePositions.add(mutable2.immutable());
}
}
}
}
}
int waterLevel = blockPos.getY();
for (BlockPos position : positions) {
waterLevel = Math.min(world.getHeight(Heightmap.Types.WORLD_SURFACE, position.getX(), position.getZ()) - 1, waterLevel);
}
ArrayList<Pair<BlockPos, BlockState>> fallingBlocks = new ArrayList<>();
ArrayList<BlockPos> lakeSurfacePositions = new ArrayList<>();
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (BlockPos position : positions) {
BlockPos.MutableBlockPos mutable3 = mutableBlockPos.set(position.getX(), Math.min(position.getY(), waterLevel), position.getZ());
for (int i = mutable3.getY(); i <= waterLevel; i++) {
setLakeBlocks(world, mutable3.getY() == waterLevel ? lakeBorderStateFunction : lakeFloorStateFunction, mutable3);
mutable3.move(Direction.UP);
}
lakeSurfacePositions.add(mutable3.immutable());
BlockPos.MutableBlockPos mutable4 = new BlockPos.MutableBlockPos().set(mutable3);
for (int i = 0; i < 10; i++) {
BlockState blockStateAbove = world.getBlockState(mutable4);
Block stateAboveBlock = blockStateAbove.getBlock();
if (stateAboveBlock instanceof FallingBlock) {
fallingBlocks.add(new Pair<>(mutable4.immutable(), blockStateAbove));
world.removeBlock(mutable4, false);
} else if (canReplace(blockStateAbove)) {
world.removeBlock(mutable4, false);
} else {
break;
}
mutable4.move(Direction.UP);
}
}
for (BlockPos lakeSurfacePosition : lakeSurfacePositions) {
for (Holder<PlacedFeature> lakeSurfaceFeature : config.lakeSurfaceFeatures()) {
lakeSurfaceFeature.value().place(world, chunkGenerator, random, lakeSurfacePosition);
}
}
for (BlockPos lakeEdgePosition : edgePositions) {
for (Holder<PlacedFeature> lakeSurfaceFeature : config.lakeEdgeFeatures()) {
lakeSurfaceFeature.value().place(world, chunkGenerator, random, lakeEdgePosition);
}
if (DEBUG) {
world.setBlock(lakeEdgePosition.offset(0, 6, 0), Blocks.GLOWSTONE.defaultBlockState(), 2);
}
}
return true;
}
Aggregations