use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.
the class EnergyPylonFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
WorldGenLevel world = ctx.level();
Random random = ctx.random();
BlockPos pos = ctx.origin();
Rotation rot = Rotation.NONE;
StructureManager manager = world.getLevel().getStructureManager();
StructureTemplate templ = manager.getOrCreate(LOCATIONS[world.getRandom().nextInt(LOCATIONS.length)]);
StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
BlockPos pos1 = findFlatChunkPosition(world, pos, 5);
if (!pos1.equals(Helpers.NULL_POS)) {
BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos1.offset(0, 1, 0), Mirror.NONE, rot);
templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.
the class MoltenForestRuins method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
BlockPos pos = ctx.origin();
WorldGenLevel world = ctx.level();
Random random = ctx.random();
Rotation rot = Rotation.getRandom(random);
StructureManager manager = world.getLevel().getStructureManager();
ResourceLocation[] LOC = { RUINS1, RUINS2, RUINS3 };
StructureTemplate templ = manager.getOrCreate(LOC[random.nextInt(3)]);
StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
BlockPos pos1 = findFlatChunkPosition(world, pos, 4, Blocks.GRASS_BLOCK);
if (!pos1.equals(Helpers.NULL_POS)) {
BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos1.offset(0, 1, 0), Mirror.NONE, rot);
templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project Ecologics by samedifferent.
the class DesertRuinFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> pContext) {
WorldGenLevel level = pContext.level();
BlockPos origin = pContext.origin();
Random random = pContext.random();
BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(origin);
for (mutable.move(Direction.UP); level.isEmptyBlock(mutable) && mutable.getY() > 2; ) {
mutable.move(Direction.DOWN);
}
if (!level.getBlockState(mutable).isAir() && !level.isEmptyBlock(mutable.below()) && !level.isEmptyBlock(mutable.below(2))) {
mutable.move(Direction.DOWN);
} else {
return false;
}
BlockPos.MutableBlockPos blockpos$Mutable = new BlockPos.MutableBlockPos();
StructureManager templatemanager = level.getLevel().getServer().getStructureManager();
ResourceLocation nbtRL = pieces[random.nextInt(pieces.length)];
Optional<StructureTemplate> template = templatemanager.get(nbtRL);
if (template.isEmpty()) {
Ecologics.LOGGER.warn(nbtRL + " NTB does not exist!");
return false;
}
for (int x = 0; x < template.get().getSize().getX(); x++) {
for (int z = 0; z < template.get().getSize().getZ(); z++) {
blockpos$Mutable.set(origin.below()).move(x, 0, z);
if (!level.getBlockState(blockpos$Mutable).is(BlockTags.SAND)) {
return false;
}
}
}
int radius = template.get().getSize().getX() / 2;
for (int x = -radius; x <= radius; x++) {
for (int z = -radius; z <= radius; z++) {
if ((x * x) + (z * z) < radius * radius + 1) {
blockpos$Mutable.set(origin).move(x, 0, z);
if (!level.getFluidState(blockpos$Mutable).isEmpty()) {
return false;
} else if (level.getBlockState(blockpos$Mutable.move(Direction.UP)).canOcclude() || !level.getBlockState(blockpos$Mutable.move(Direction.DOWN, 3)).canOcclude()) {
return false;
} else if (!level.getBlockState(blockpos$Mutable).is(BlockTags.SAND)) {
return false;
}
}
}
}
BlockPos halfLengths = new BlockPos(template.get().getSize().getX() / 2, 0, template.get().getSize().getZ() / 2);
placementsettings.setRotation(Rotation.getRandom(random)).setRotationPivot(halfLengths).setIgnoreEntities(false);
blockpos$Mutable.set(origin);
BlockPos offset = new BlockPos(-template.get().getSize().getX() / 2, nbtRL.getPath().contains("pit") ? -2 : 0, -template.get().getSize().getZ() / 2);
template.get().placeInWorld(level, blockpos$Mutable.offset(offset), blockpos$Mutable.offset(offset), placementsettings, random, Block.UPDATE_CLIENTS);
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project TerraFirmaCraft by TerraFirmaCraft.
the class OverlayTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<OverlayTreeConfig> context) {
final WorldGenLevel worldIn = context.level();
final BlockPos pos = context.origin();
final Random random = context.random();
final OverlayTreeConfig 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);
final StructureTemplate structureBase = manager.getOrCreate(config.base());
final StructureTemplate structureOverlay = manager.getOrCreate(config.overlay());
if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 3)) {
return false;
}
config.trunk().ifPresent(trunk -> {
final int height = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, trunk);
mutablePos.move(0, height, 0);
});
TreeHelpers.placeTemplate(structureBase, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structureBase.getSize(), settings)));
settings.addProcessor(new BlockRotProcessor(config.overlayIntegrity()));
TreeHelpers.placeTemplate(structureOverlay, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structureOverlay.getSize(), settings)));
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project TerraFirmaCraft by TerraFirmaCraft.
the class RandomTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<RandomTreeConfig> context) {
final WorldGenLevel worldIn = context.level();
final BlockPos pos = context.origin();
final Random random = context.random();
final RandomTreeConfig 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);
final ResourceLocation structureId = config.structureNames().get(random.nextInt(config.structureNames().size()));
final StructureTemplate structure = manager.getOrCreate(structureId);
if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 2)) {
return false;
}
config.trunk().ifPresent(trunk -> {
final int height = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, trunk);
mutablePos.move(0, height, 0);
});
TreeHelpers.placeTemplate(structure, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structure.getSize(), settings)));
return true;
}
Aggregations