use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class BrainTreeFeature method place.
@Override
@SuppressWarnings("deprecation")
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
WorldGenLevel level = featurePlaceContext.level();
BlockPos center = featurePlaceContext.origin();
Random random = featurePlaceContext.random();
if (!EdenBlocks.PULSE_TREE_SAPLING.canSurvive(EdenBlocks.PULSE_TREE_SAPLING.defaultBlockState(), level, center)) {
return false;
}
if (TYPES[0] == null) {
TYPES[0] = EdenBlocks.BRAIN_TREE_BLOCK_IRON.defaultBlockState();
TYPES[1] = EdenBlocks.BRAIN_TREE_BLOCK_COPPER.defaultBlockState();
TYPES[2] = EdenBlocks.BRAIN_TREE_BLOCK_GOLD.defaultBlockState();
}
BlockState brain = TYPES[random.nextInt(3)];
BlockState brainActive = brain.setValue(BlockProperties.ACTIVE, true);
BlockState stem = EdenBlocks.BRAIN_TREE_LOG.defaultBlockState();
MutableBlockPos pos = center.mutable();
int h = MHelper.randRange(2, 4, random);
BlocksHelper.setWithoutUpdate(level, pos, stem);
for (int i = 1; i < h; i++) {
pos.setY(center.getY() + i);
setBlock(level, pos, stem);
}
pos.setY(center.getY() + h);
setBlock(level, pos, stem);
pos.setY(pos.getY() + 1);
setBlock(level, pos, stem);
setBlock(level, pos.north(), stem);
setBlock(level, pos.south(), stem);
setBlock(level, pos.east(), stem);
setBlock(level, pos.west(), stem);
pos.setY(pos.getY() + 1);
setBlock(level, pos.north(), stem);
setBlock(level, pos.south(), stem);
setBlock(level, pos.east(), stem);
setBlock(level, pos.west(), stem);
for (int y = 0; y < 4; y++) {
pos.setY(center.getY() + h + y);
for (int x = -1; x < 2; x++) {
pos.setX(center.getX() + x);
for (int z = -1; z < 2; z++) {
pos.setZ(center.getZ() + z);
setBlock(level, pos, random.nextInt(16) == 0 ? brainActive : brain);
}
}
}
for (int y = 0; y < 2; y++) {
pos.setY(center.getY() + h + y + 1);
for (int x = -2; x < 3; x++) {
pos.setX(center.getX() + x);
int ax = Mth.abs(x);
for (int z = -2; z < 3; z++) {
pos.setZ(center.getZ() + z);
int az = Mth.abs(z);
if (ax != 2 || az != 2 || ax != az) {
setBlock(level, pos, random.nextInt(16) == 0 ? brainActive : brain);
}
}
}
}
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class PulseTreeFeature method place.
@Override
@SuppressWarnings("deprecation")
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
WorldGenLevel level = featurePlaceContext.level();
BlockPos center = featurePlaceContext.origin();
Random random = featurePlaceContext.random();
if (!EdenBlocks.PULSE_TREE_SAPLING.canSurvive(EdenBlocks.PULSE_TREE_SAPLING.defaultBlockState(), level, center)) {
return false;
}
MutableBlockPos pos = center.mutable();
int h = MHelper.randRange(5, 12, random);
for (int i = 1; i < h; i++) {
pos.setY(center.getY() + i);
if (!level.getBlockState(pos).isAir()) {
h = i - 1;
break;
}
}
if (h < 5) {
return false;
}
BlockState headMedium = EdenBlocks.PULSE_TREE.defaultBlockState().setValue(EdenBlockProperties.PULSE_TREE, PulseTreeState.HEAD_MEDIUM);
BlockState headSmall = EdenBlocks.PULSE_TREE.defaultBlockState().setValue(EdenBlockProperties.PULSE_TREE, PulseTreeState.HEAD_SMALL);
BlockState headBig = EdenBlocks.PULSE_TREE.defaultBlockState().setValue(EdenBlockProperties.PULSE_TREE, PulseTreeState.HEAD_BIG);
BlockState stem = EdenBlocks.PULSE_TREE.defaultBlockState();
int mediumCount = Mth.floor(h * 0.2F + 0.5F);
int offsetCount = MHelper.randRange(2, 3, random);
int bigCount = h - offsetCount - mediumCount * 2 - 1;
pos.setY(center.getY());
for (int i = 0; i < offsetCount; i++) {
BlocksHelper.setWithoutUpdate(level, pos, stem);
pos.setY(pos.getY() + 1);
}
for (int i = 0; i < mediumCount; i++) {
BlocksHelper.setWithoutUpdate(level, pos, headMedium);
pos.setY(pos.getY() + 1);
}
for (int i = 0; i < bigCount; i++) {
BlocksHelper.setWithoutUpdate(level, pos, headBig);
pos.setY(pos.getY() + 1);
}
for (int i = 0; i < mediumCount; i++) {
BlocksHelper.setWithoutUpdate(level, pos, headMedium);
pos.setY(pos.getY() + 1);
}
BlocksHelper.setWithoutUpdate(level, pos, headSmall);
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class EdenPortalBlockEntity method getExit.
private static MutableBlockPos getExit(Level level, BlockPos start) {
int x1 = (start.getX() >> 4) - 1;
int z1 = (start.getZ() >> 4) - 1;
int x2 = x1 + 3;
int z2 = z1 + 3;
List<BlockEntity> entityList = new ArrayList<>();
for (int x = x1; x < x2; x++) {
for (int z = z1; z < z2; z++) {
Map<BlockPos, BlockEntity> entities = level.getChunk(x, z).getBlockEntities();
entityList.addAll(entities.values().stream().filter(entity -> entity instanceof EdenPortalBlockEntity).toList());
}
}
final int size = entityList.size();
if (size == 0) {
return null;
}
BlockEntity target = size == 1 ? entityList.get(0) : entityList.get(level.random.nextInt(size));
return target.getBlockPos().mutable();
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class TallBalloonMushroom method getBlocksBelow.
private int getBlocksBelow(LevelAccessor level, BlockPos pos) {
MutableBlockPos p = pos.mutable();
p.setY(p.getY() - 1);
int count;
for (count = 0; count < 5 && level.getBlockState(p).is(this); count++) {
p.setY(p.getY() - 1);
}
return count;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class SixSideScatter method place.
@Override
@SuppressWarnings("deprecation")
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
Random random = featurePlaceContext.random();
BlockPos center = featurePlaceContext.origin();
WorldGenLevel level = featurePlaceContext.level();
int minX = center.getX() & 0xFFFFFFF0;
int minZ = center.getZ() & 0xFFFFFFF0;
int px = minX | random.nextInt(16);
int py = MHelper.randRange(32, 224, random);
int pz = minZ | random.nextInt(16);
MutableBlockPos pos = new MutableBlockPos();
for (int x = -4; x < 5; x++) {
pos.setX(px + x);
for (int z = -4; z < 5; z++) {
pos.setZ(pz + z);
for (int y = -4; y < 5; y++) {
pos.setY(py + y);
if (random.nextInt(3) == 0 && Math.abs(x) + Math.abs(y) + Math.abs(z) < 7) {
if (level.getBlockState(pos).isAir()) {
BlockState state = block.getAttachedState(level, pos);
if (state != null) {
BlocksHelper.setWithoutUpdate(level, pos, state);
}
}
}
}
}
}
return true;
}
Aggregations