use of net.minecraft.world.StructureWorldAccess in project artifality by PinkGoosik.
the class CrystalFeature method generate.
@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
boolean generated = false;
var pack = CrystalClusterPacks.getRandomPack();
for (int i = 0; i < 16; i++) {
int x = context.getOrigin().getX() + context.getRandom().nextInt(6);
int z = context.getOrigin().getZ() + context.getRandom().nextInt(6);
int y = context.getRandom().nextInt(8) + 16;
BlockPos pos = new BlockPos(x, y, z);
StructureWorldAccess world = context.getWorld();
if (world.isAir(pos)) {
if (isStone(world.getBlockState(pos.down()))) {
BlockState cluster = pack.getRandomCluster().getDefaultState();
setBlockState(world, pos, cluster);
setBlockState(world, pos.down(), pack.geode.getDefaultState());
generated = true;
} else if (isStone(world.getBlockState(pos.add(0, 0, -1)))) {
BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.SOUTH);
setBlockState(world, pos, cluster);
setBlockState(world, pos.add(0, 0, -1), pack.geode.getDefaultState());
generated = true;
} else if (isStone(world.getBlockState(pos.add(0, 0, 1)))) {
BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.NORTH);
setBlockState(world, pos, cluster);
setBlockState(world, pos.add(0, 0, 1), pack.geode.getDefaultState());
generated = true;
} else if (isStone(world.getBlockState(pos.add(-1, 0, 0)))) {
BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.EAST);
setBlockState(world, pos, cluster);
setBlockState(world, pos.add(-1, 0, 0), pack.geode.getDefaultState());
generated = true;
} else if (isStone(world.getBlockState(pos.add(1, 0, 0)))) {
BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.WEST);
setBlockState(world, pos, cluster);
setBlockState(world, pos.add(1, 0, 0), pack.geode.getDefaultState());
generated = true;
} else if (isStone(world.getBlockState(pos.up()))) {
BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.DOWN);
setBlockState(world, pos, cluster);
setBlockState(world, pos.up(), pack.geode.getDefaultState());
generated = true;
}
}
}
return generated;
}
use of net.minecraft.world.StructureWorldAccess in project SpoornPink by spoorn.
the class AbstractSPTree method generate.
@Override
public boolean generate(FeatureContext<FC> context) {
Set<BlockPos> changedTrunkBlocks = Sets.newHashSet();
Set<BlockPos> changedLeafBlocks = Sets.newHashSet();
StructureWorldAccess world = context.getWorld();
boolean generated = generate(changedTrunkBlocks, changedLeafBlocks, world, context.getRandom(), context.getOrigin(), context.getConfig());
if (!generated || changedTrunkBlocks.isEmpty() && changedLeafBlocks.isEmpty()) {
return false;
}
/**
* Copy vanilla's from {@link TreeFeature}.
*/
return BlockBox.encompassPositions(Iterables.concat(changedTrunkBlocks, changedLeafBlocks)).map(box -> {
VoxelSet voxelSet = placeLogsAndLeaves(world, box, changedTrunkBlocks);
Structure.updateCorner(world, Block.NOTIFY_ALL, voxelSet, box.getMinX(), box.getMinY(), box.getMinZ());
return true;
}).orElse(false);
}
use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.
the class CommonActivatorFeature method generate.
@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
StructureWorldAccess world = context.getWorld();
BlockPos pos = context.getOrigin();
if (blockTagsInSphere(context.getOrigin(), 2, SculkTags.COMMON_ACTIVATORS, context.getWorld()).isEmpty() && world.getBlockState(context.getOrigin()).getBlock() == sculk.getBlock()) {
if (context.getWorld().getBlockEntity(context.getOrigin()) == null) {
;
BlockState activator = SculkTags.COMMON_ACTIVATORS.getRandom(new Random(context.getWorld().getSeed())).getDefaultState();
if (SculkTags.GROUND_ACTIVATORS.contains(activator.getBlock())) {
world.setBlockState(pos, activator, 0);
} else {
BlockState stateUp = world.getBlockState(pos.up());
if (stateUp == water && activator.contains(waterLogged)) {
world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
} else if (stateUp.getBlock() != waterBlock) {
if (stateUp == vein.with(waterLogged, true) && activator.contains(waterLogged)) {
world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
} else {
world.setBlockState(pos.up(), activator, 0);
}
}
}
}
return true;
}
return false;
}
use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.
the class LargeSculkPatchFeature method placePatch.
public void placePatch(FeatureContext<DefaultFeatureConfig> context, BlockPos pos, int r, double min, double max, double average) {
StructureWorldAccess world = context.getWorld();
// Place Sculk Around Catalyst
int timesFailed = 0;
int groupsFailed = 1;
int loop = (int) (8 * Math.cos(((average) * Math.PI) / 24) + 24);
for (int l = 0; l < loop; ) {
double a = random() * 2 * PI;
double rad = sqrt(2 + (groupsFailed - 1)) * sqrt(random());
boolean succeed = placeSculk(pos.add((int) (rad * sin(a)), 0, (int) (rad * cos(a))), world);
// Determine If Sculk Placement Was Successful And If Radius Should Be Increased
if (!succeed) {
++timesFailed;
} else {
++l;
if (timesFailed > 0) {
--timesFailed;
}
}
if (timesFailed >= 10) {
timesFailed = 0;
groupsFailed = groupsFailed + 1;
}
if (sqrt(2 + (groupsFailed - 1)) > 10) {
break;
}
}
// Place Sculk
for (BlockPos blockpos : blockTagsInSphere(pos, r, SculkTags.BLOCK_REPLACEABLE, world)) {
double distance = pos.getSquaredDistance(blockpos, false);
double maxA = max;
double minA = min;
double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
if (r - 3 <= distance) {
// Semi-Fade On Edges
double equation = 0.15 * (Math.sin((r - distance * PI) / 6));
maxA = maxA - equation;
minA = minA + equation;
}
double dist = Math.max(r, distance * 1.8);
if (isWall(world, blockpos)) {
double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
maxA = maxA - maxEq;
minA = minA + minEq;
}
if (isCeiling(world, blockpos)) {
double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
maxA = maxA - maxEq;
minA = minA + minEq;
}
if (sampled > minA && sampled < maxA) {
placeSculkOptim(blockpos, world);
}
}
// Place Veins
for (BlockPos blockpos : solidInSphere(pos, r, world)) {
double minA = min;
double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
double distance = pos.getSquaredDistance(blockpos, false);
if (r - 3 <= distance) {
// Semi-Fade On Edges
double equation = 0.15 * (Math.sin((distance * PI) / 6));
minA = minA + equation;
}
double dist = Math.max(r, distance * 1.8);
if (isWall(world, blockpos)) {
double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
minA = minA + minEq;
}
if (isCeiling(world, blockpos)) {
double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
minA = minA + minEq;
}
if (sampled < minA && sampled > minA - 0.16) {
veins(blockpos, world);
}
}
for (BlockPos blockpos : solidInSphere(pos, r, world)) {
double distance = pos.getSquaredDistance(blockpos, false);
double maxA = max;
double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
if (r - 3 <= distance) {
// Semi-Fade On Edges
double equation = 0.15 * (Math.sin((distance * PI) / 6));
maxA = maxA - equation;
}
double dist = Math.max(r, distance * 1.8);
if (isWall(world, blockpos)) {
double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
maxA = maxA - maxEq;
}
if (isCeiling(world, blockpos)) {
double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
maxA = maxA - maxEq;
}
if (sampled > maxA && sampled < maxA + 0.16) {
veins(blockpos, world);
}
}
for (BlockPos blockpos : hollowedSphere(pos, r + 1, world)) {
veins(blockpos, world);
}
// Place Activators
for (BlockPos blockpos : blocksInSphere(pos, r, RegisterBlocks.SCULK, world)) {
double sampled = sample.sample(blockpos.getX() * 1.5, blockpos.getY() * 1.5, blockpos.getZ() * 1.5);
if (SculkTags.SCULK_VEIN_REPLACEABLE.contains(world.getBlockState(blockpos.up()).getBlock())) {
Block activator = null;
if (sampled < 0.55 && sampled > 0.41 && blockTagsInSphere(context.getOrigin(), 3, SculkTags.COMMON_ACTIVATORS, context.getWorld()).isEmpty()) {
activator = SculkTags.COMMON_ACTIVATORS.getRandom(random);
}
if (sampled < 1 && sampled > 0.57 && blockTagsInSphere(context.getOrigin(), 6, SculkTags.RARE_ACTIVATORS, context.getWorld()).isEmpty()) {
activator = SculkTags.RARE_ACTIVATORS.getRandom(random);
}
if (activator != null) {
if (SculkTags.GROUND_ACTIVATORS.contains(activator)) {
world.setBlockState(blockpos.up(), activator.getDefaultState(), 0);
} else {
if ((world.getBlockState(blockpos.up()).contains(waterLogged) && world.getBlockState(blockpos.up()).get(waterLogged)) || world.getBlockState(blockpos.up()) == water) {
world.setBlockState(blockpos.up(), activator.getDefaultState().with(waterLogged, true), 0);
} else {
world.setBlockState(blockpos.up(), activator.getDefaultState(), 0);
}
}
}
}
}
}
use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.
the class RareActivatorFeature method generate.
@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
StructureWorldAccess world = context.getWorld();
BlockPos pos = context.getOrigin();
if (blockTagsInSphere(context.getOrigin(), 6, SculkTags.RARE_ACTIVATORS, context.getWorld()).isEmpty() && world.getBlockState(context.getOrigin()).getBlock() == sculk.getBlock()) {
if (context.getWorld().getBlockEntity(context.getOrigin()) == null) {
;
BlockState activator = SculkTags.RARE_ACTIVATORS.getRandom(new Random(context.getWorld().getSeed())).getDefaultState();
if (SculkTags.GROUND_ACTIVATORS.contains(activator.getBlock())) {
world.setBlockState(pos, activator, 0);
} else {
BlockState stateUp = world.getBlockState(pos.up());
if (stateUp == water && activator.contains(waterLogged)) {
world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
} else if (stateUp.getBlock() != waterBlock) {
if (stateUp == vein.with(waterLogged, true) && activator.contains(waterLogged)) {
world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
} else {
world.setBlockState(pos.up(), activator, 0);
}
}
}
}
return true;
}
return false;
}
Aggregations