use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project Brass_Amber_BattleTowers by BrassAmber-Mods.
the class BTLandJigsawPlacement method addPieces.
public static Optional<PieceGenerator<BTJigsawConfiguration>> addPieces(PieceGeneratorSupplier.Context<BTJigsawConfiguration> context, BTLandJigsawPlacement.PieceFactory pieceFactory, BlockPos placementPos, boolean boundaryAdjust, boolean useHeightMap, boolean water) {
WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
RegistryAccess registryaccess = context.registryAccess();
BTJigsawConfiguration jigsawconfiguration = context.config();
ChunkGenerator chunkgenerator = context.chunkGenerator();
StructureManager structuremanager = context.structureManager();
LevelHeightAccessor levelheightaccessor = context.heightAccessor();
Predicate<Biome> predicate = context.validBiome();
StructureFeature.bootstrap();
Registry<StructureTemplatePool> registry = registryaccess.registryOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
Rotation rotation = Rotation.getRandom(worldgenrandom);
watered = water;
StructureTemplatePool structuretemplatepool = jigsawconfiguration.startPool().get();
StructurePoolElement structurepoolelement = structuretemplatepool.getRandomTemplate(worldgenrandom);
if (structurepoolelement == EmptyPoolElement.INSTANCE) {
return Optional.empty();
} else {
PoolElementStructurePiece poolelementstructurepiece = pieceFactory.create(structuremanager, structurepoolelement, placementPos, structurepoolelement.getGroundLevelDelta(), rotation, structurepoolelement.getBoundingBox(structuremanager, placementPos, rotation));
BoundingBox boundingbox = poolelementstructurepiece.getBoundingBox();
int bbX = (boundingbox.maxX() + boundingbox.minX()) / 2;
int bbZ = (boundingbox.maxZ() + boundingbox.minZ()) / 2;
int ppY;
if (useHeightMap) {
ppY = placementPos.getY() + chunkgenerator.getFirstFreeHeight(bbX, bbZ, Heightmap.Types.WORLD_SURFACE_WG, levelheightaccessor);
} else {
ppY = placementPos.getY();
}
if (watered) {
poolelementstructurepiece.move(0, -5, 0);
}
if (!predicate.test(chunkgenerator.getNoiseBiome(QuartPos.fromBlock(bbX), QuartPos.fromBlock(ppY), QuartPos.fromBlock(bbZ)))) {
return Optional.empty();
} else {
int pieceYlevel = boundingbox.minY() + poolelementstructurepiece.getGroundLevelDelta();
poolelementstructurepiece.move(0, ppY - pieceYlevel, 0);
return Optional.of((piecesBuilder, pieceGenContext) -> {
List<PoolElementStructurePiece> list = Lists.newArrayList();
list.add(poolelementstructurepiece);
if (jigsawconfiguration.maxDepth() > 0) {
int sizeLimit = 120;
AABB aabb = new AABB(bbX - sizeLimit, ppY - sizeLimit, bbZ - sizeLimit, bbX + sizeLimit + 1, ppY + sizeLimit + 1, bbZ + sizeLimit + 1);
BTLandJigsawPlacement.Placer BTLandJigsawPlacement$placer = new BTLandJigsawPlacement.Placer(registry, jigsawconfiguration.maxDepth(), pieceFactory, chunkgenerator, structuremanager, list, worldgenrandom);
BTLandJigsawPlacement$placer.placing.addLast(new BTLandJigsawPlacement.PieceState(poolelementstructurepiece, new MutableObject<>(Shapes.join(Shapes.create(aabb), Shapes.create(AABB.of(boundingbox)), BooleanOp.ONLY_FIRST)), 0));
while (!BTLandJigsawPlacement$placer.placing.isEmpty()) {
BTLandJigsawPlacement.PieceState BTLandJigsawPlacement$piecestate = BTLandJigsawPlacement$placer.placing.removeFirst();
BTLandJigsawPlacement$placer.tryPlacingChildren(BTLandJigsawPlacement$piecestate.piece, BTLandJigsawPlacement$piecestate.free, BTLandJigsawPlacement$piecestate.depth, boundaryAdjust, levelheightaccessor);
}
list.forEach(piecesBuilder::addPiece);
}
});
}
}
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project The-Aether by Gilded-Games.
the class CrystalTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel reader = context.level();
BlockPos pos = context.origin();
Random rand = context.random();
Rotation rotation = Rotation.getRandom(rand);
StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
StructureTemplate tree = templatemanager.getOrCreate(TREE);
StructureTemplate fruit = templatemanager.getOrCreate(FRUIT);
ChunkPos chunkpos = new ChunkPos(pos);
BoundingBox mutableboundingbox = new BoundingBox(chunkpos.getMinBlockX(), 0, chunkpos.getMinBlockZ(), chunkpos.getMaxBlockX(), 256, chunkpos.getMaxBlockZ());
StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setBoundingBox(mutableboundingbox).setRandom(rand).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
Vec3i vec3i = tree.getSize(rotation);
int x = rand.nextInt(16 - vec3i.getX());
int z = rand.nextInt(16 - vec3i.getZ());
int y = Math.max(Math.min(reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x, pos.getZ() + z) + rand.nextInt(20) + 40, 200), 100);
BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos.offset(x, y, z), Mirror.NONE, rotation);
tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
placementsettings.clearProcessors().addProcessor(integrityprocessor);
fruit.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project The-Aether by Gilded-Games.
the class HolidayTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
BlockPos pos = context.origin();
Random rand = context.random();
WorldGenLevel reader = context.level();
Calendar calendar = Calendar.getInstance();
if ((AetherConfig.COMMON.generate_holiday_tree_seasonally.get() && (calendar.get(Calendar.MONTH) == Calendar.DECEMBER || calendar.get(Calendar.MONTH) == Calendar.JANUARY)) || AetherConfig.COMMON.generate_holiday_tree_always.get()) {
Rotation rotation = Rotation.getRandom(rand);
StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
StructureTemplate tree = templatemanager.getOrCreate(TREE);
StructureTemplate decor = templatemanager.getOrCreate(DECORATION);
ChunkPos chunkpos = new ChunkPos(pos);
BoundingBox mutableboundingbox = new BoundingBox(chunkpos.getMinBlockX(), 0, chunkpos.getMinBlockZ(), chunkpos.getMaxBlockX(), 256, chunkpos.getMaxBlockZ());
StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setBoundingBox(mutableboundingbox).setRandom(rand).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
Vec3i size = tree.getSize(rotation);
int rx = Math.floorDiv(size.getX(), 2);
int rz = Math.floorDiv(size.getZ(), 2);
int x = rand.nextInt(16 - size.getX());
int z = rand.nextInt(16 - size.getZ());
int y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x + rx, pos.getZ() + z + rz);
if (y <= 48)
return true;
pos = pos.offset(x, y, z);
for (int i = -rx * 2; i < rx * 2 + 1; i++) {
for (int j = -rz * 2; j < rz * 2 + 1; j++) {
if (i * i + j * j <= 3.5 * rx * rx) {
y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + rx + i, pos.getZ() + rz + j);
if (y <= 48)
continue;
BlockPos pos1 = new BlockPos(pos.getX() + rx + i, y, pos.getZ() + rz + j);
if (rand.nextInt(6) == 0) {
this.setBlock(reader, pos1, AetherBlocks.PRESENT.get().defaultBlockState());
} else {
this.setBlock(reader, pos1, Blocks.SNOW.defaultBlockState());
}
}
}
}
BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos, Mirror.NONE, rotation);
tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
placementsettings.clearProcessors().addProcessor(integrityprocessor);
decor.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project TerraFirmaCraft by TerraFirmaCraft.
the class StackedTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<StackedTreeConfig> context) {
final WorldGenLevel worldIn = context.level();
final BlockPos pos = context.origin();
final Random random = context.random();
final StackedTreeConfig config = context.config();
final ChunkPos chunkPos = new ChunkPos(pos);
final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos().set(pos);
final StructureManager manager = TreeHelpers.getStructureManager(worldIn);
final StructurePlaceSettings settings = TreeHelpers.getPlacementSettings(worldIn, chunkPos, random);
if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 2)) {
return false;
}
// Trunk first
int trunkHeight = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, config.trunk());
mutablePos.move(0, trunkHeight, 0);
for (StackedTreeConfig.Layer layer : config.layers()) {
// Place each layer
int layerCount = layer.getCount(random);
for (int i = 0; i < layerCount; i++) {
final ResourceLocation structureId = layer.templates().get(random.nextInt(layer.templates().size()));
final StructureTemplate structure = manager.getOrCreate(structureId);
TreeHelpers.placeTemplate(structure, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structure.getSize(), settings)));
mutablePos.move(0, structure.getSize().getY(), 0);
}
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.
the class RadiantLandFloatingIslands method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
WorldGenLevel world = ctx.level();
if (AVAILABLE_TO_SPAWN == null) {
initList(world);
}
BlockPos pos = ctx.origin();
Random random = ctx.random();
Rotation rot = Rotation.getRandom(random);
StructureManager manager = world.getLevel().getStructureManager();
StructureTemplate templ = manager.getOrCreate(List.of(ISLAND1, ISLAND2, ISLAND3, ISLAND4).get(random.nextInt(4)));
StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(0, 1, 0), Mirror.NONE, rot);
templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
});
return true;
}
Aggregations