use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.
the class CrystallizedOreVeinFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
WorldGenLevel world = ctx.level();
if (AVAILABLE_TO_SPAWN == null) {
initList(world);
}
BlockPos pos = ctx.origin().below(13);
Random random = ctx.random();
Rotation rot = Rotation.getRandom(random);
StructureManager manager = world.getLevel().getStructureManager();
StructureTemplate templ = manager.getOrCreate(VEIN);
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;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project SolarCraftRepository by FINDERFEED.
the class CrystalCaveOreCrystal 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();
BlockState stateAtPos = world.getBlockState(pos);
if (!(stateAtPos.isAir())) {
return false;
}
Optional<Column> column = Column.scan(world, pos, 30, (state) -> state.is(Blocks.AIR) || state.is(Blocks.CAVE_AIR), (state) -> state.is(Blocks.STONE));
if (column.isPresent() && column.get().getFloor().isPresent()) {
Rotation rot = Rotation.getRandom(random);
StructureManager manager = world.getLevel().getStructureManager();
StructureTemplate templ = manager.getOrCreate(ORE_CRYSTAL);
StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(-templ.getSize().getX() / 2, 0, -templ.getSize().getZ() / 2), Mirror.NONE, rot);
blockpos1 = new BlockPos(blockpos1.getX(), column.get().getFloor().getAsInt() - 2, blockpos1.getZ());
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());
});
} else {
return false;
}
return true;
}
use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project RepurposedStructures by TelepathicGrunt.
the class MinecartFeature method place.
@Override
public boolean place(FeaturePlaceContext<MinecartConfig> context) {
// Check if below block is solid
BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(context.origin());
if (!context.level().getBlockState(mutable.below()).canOcclude()) {
return false;
}
// Check if spot allows for cart (liquid or non-liquid spot)
BlockState worldBlock = context.level().getBlockState(mutable);
if (context.config().waterBased ? !worldBlock.getFluidState().is(FluidTags.WATER) : !worldBlock.getFluidState().isEmpty()) {
return false;
}
BlockPos.MutableBlockPos blockpos$Mutable = new BlockPos.MutableBlockPos();
StructureManager templatemanager = context.level().getLevel().getServer().getStructureManager();
Optional<StructureTemplate> template = templatemanager.get(context.config().nbtPath);
if (template.isEmpty()) {
RepurposedStructures.LOGGER.warn(context.config().nbtPath.toString() + " NTB does not exist!");
return false;
}
BlockPos halfLengths = new BlockPos(template.get().getSize().getX() / 2, 0, template.get().getSize().getZ() / 2);
structurePlaceSettings.setRotation(Rotation.getRandom(context.random())).setRotationPivot(halfLengths).setIgnoreEntities(false);
blockpos$Mutable.set(context.origin());
BlockPos offset = new BlockPos(-template.get().getSize().getX() / 2, 0, -template.get().getSize().getZ() / 2);
template.get().placeInWorld(context.level(), blockpos$Mutable.offset(offset), blockpos$Mutable.offset(offset), structurePlaceSettings, context.random(), Block.UPDATE_CLIENTS);
return true;
}
Aggregations