use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class LayeredBulbFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
Random random = featurePlaceContext.random();
BlockPos center = featurePlaceContext.origin();
WorldGenLevel level = featurePlaceContext.level();
int posX = center.getX() & 0xFFFFFFF0;
int posZ = center.getZ() & 0xFFFFFFF0;
MutableBlockPos pos = new MutableBlockPos();
int iterations = MHelper.randRange(minCount, maxCount, random);
for (int n = 0; n < iterations; n++) {
int wx = posX | random.nextInt(16);
int wz = posZ | random.nextInt(16);
int wy = random.nextInt(256);
int radius = MHelper.randRange(minRadius, maxRadius, random);
int x1 = wx - radius;
int x2 = wx + radius;
int z1 = wz - radius;
int z2 = wz + radius;
int y1 = wy - radius;
int y2 = wy + radius;
for (int x = x1; x <= x2; x++) {
pos.setX(x);
for (int y = y1; y <= y2; y++) {
pos.setY(y);
for (int z = z1; z <= z2; z++) {
pos.setZ(z);
float dist = MHelper.length(x - wx, y - wy, z - wz);
float localRadius = radius - (float) NOISE.eval(x * 0.3, y * 0.3, z * 0.3) * radius * 0.3F;
if (dist < localRadius - random.nextInt(3)) {
int index = (int) (dist / localRadius * layers.length);
BlockState state = layers[index].defaultBlockState();
BlockState worldState = level.getBlockState(pos);
for (Block block : scatterIn) {
if (worldState.is(block)) {
BlocksHelper.setWithoutUpdate(level, pos, state);
}
}
}
}
}
}
}
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class ScatterFeature method place.
@Override
@SuppressWarnings("deprecation")
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
Random random = featurePlaceContext.random();
BlockPos center = featurePlaceContext.origin();
WorldGenLevel level = featurePlaceContext.level();
BlockState state = block.defaultBlockState();
MutableBlockPos pos = new MutableBlockPos();
int count = getCount(random);
for (int i = 0; i < count; i++) {
int px = center.getX() + Mth.floor(Mth.clamp(random.nextGaussian() * 2 + 0.5F, -8, 8));
int pz = center.getZ() + Mth.floor(Mth.clamp(random.nextGaussian() * 2 + 0.5F, -8, 8));
pos.setX(px);
pos.setZ(pz);
for (int y = 5; y > -5; y--) {
pos.setY(center.getY() + y);
if (level.getBlockState(pos).isFaceSturdy(level, pos, Direction.UP)) {
pos.setY(pos.getY() + 1);
if (level.getBlockState(pos).isAir() && block.canSurvive(state, level, pos)) {
placeBlock(level, pos, state);
break;
}
}
}
}
return true;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class TerrainFiller method fill.
public static InterpolationCell fill(ChunkAccess chunkAccess) {
final short minY = (short) chunkAccess.getMinBuildHeight();
final short maxY = (short) chunkAccess.getMaxBuildHeight();
ChunkPos chunkPos = chunkAccess.getPos();
final BlockPos origin = new BlockPos(chunkPos.getMinBlockX(), chunkAccess.getMinBuildHeight(), chunkPos.getMinBlockZ());
final short maxCell = (short) ((maxY - minY) / 8 + 1);
TerrainGenerator generator = MultiThreadGenerator.getTerrainGenerator();
InterpolationCell cellTerrain = new InterpolationCell(generator, 3, maxCell, 8, 8, origin);
MutableBlockPos pos = new MutableBlockPos();
for (byte x = 0; x < 16; x++) {
pos.setX(x);
for (byte z = 0; z < 16; z++) {
pos.setZ(z);
for (short y = minY; y < maxY; y++) {
pos.setY(y);
if (cellTerrain.get(pos, true) > 0) {
chunkAccess.setBlockState(pos, STONE, false);
}
}
}
}
return cellTerrain;
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class EdenPortalBlockEntity method serverTick.
public static <T extends BlockEntity> void serverTick(Level level, BlockPos blockPos, BlockState state, T entity) {
if (entity == null || !(entity instanceof EdenPortalBlockEntity)) {
return;
}
EdenPortalBlockEntity portal = (EdenPortalBlockEntity) entity;
if (portal.checkTicks > 10) {
portal.checkTicks = 0;
if (!EdenPortal.checkOldPortal(level, blockPos)) {
EdenPortal.destroyPortal(level, blockPos);
level.setBlockAndUpdate(blockPos, Blocks.AIR.defaultBlockState());
portal.setRemoved();
return;
}
}
portal.checkTicks++;
if (portal.box == null) {
portal.box = new AABB(blockPos);
portal.box = portal.box.inflate(0.5, 0, 0.5).setMaxY(blockPos.getY() + 3);
}
List<Entity> entities = level.getEntities(null, portal.box);
if (entities.isEmpty()) {
return;
}
MinecraftServer server = level.getServer();
ResourceKey key = level.dimension().equals(EdenRing.EDEN_RING_KEY) ? Level.OVERWORLD : EdenRing.EDEN_RING_KEY;
ServerLevel destination = server.getLevel(key);
if (destination == null) {
return;
}
MutableBlockPos preExit = getExit(destination, blockPos);
if (preExit == null) {
preExit = blockPos.mutable();
getLand(destination, preExit);
if (preExit.getY() == 130 && destination.getBlockState(preExit.below(2)).isAir()) {
EdenFeatures.SMALL_ISLAND.getFeature().place(new FeaturePlaceContext(Optional.empty(), destination, destination.getChunkSource().getGenerator(), destination.random, preExit.below(2), null));
}
EdenPortal.buildPortal(destination, preExit);
}
final MutableBlockPos exit = preExit;
entities.forEach(e -> {
if (e.isAlive()) {
EdenPortable portable = (EdenPortable) e;
if (portable.getPortalTimeout() > 0) {
portable.setPortalTimeout(20);
} else {
if (e instanceof ServerPlayer) {
ServerPlayer player = (ServerPlayer) e;
player.teleportTo(destination, exit.getX() + 0.5, exit.getY(), exit.getZ() + 0.5, player.getYRot(), player.getXRot());
((EdenPortable) player).setPortalTimeout(20);
} else {
e.ejectPassengers();
Entity newEntity = e.getType().create(destination);
newEntity.restoreFrom(e);
e.remove(RemovalReason.CHANGED_DIMENSION);
destination.addDuringTeleport(newEntity);
((EdenPortable) newEntity).setPortalTimeout(100);
newEntity.teleportTo(exit.getX() + 0.5, exit.getY(), exit.getZ() + 0.5);
}
}
}
});
}
use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.
the class BrainTreeBlock method hitLighting.
private void hitLighting(ServerLevel world, Random random, BlockPos pos) {
List<LivingEntity> entities = world.getNearbyEntities(LivingEntity.class, TargetingConditions.forNonCombat(), null, new AABB(pos).inflate(16, 16, 16));
if (!entities.isEmpty()) {
LivingEntity entity = entities.get(random.nextInt(entities.size()));
if (entity instanceof Player && ((Player) entity).isCreative()) {
return;
}
MutableBlockPos mpos = pos.mutable();
float dx = (float) (entity.getX() - pos.getX() - 0.5);
float dy = (float) (entity.getY() - pos.getY() - 0.5);
float dz = (float) (entity.getZ() - pos.getZ() - 0.5);
float ax = Mth.abs(dx);
float ay = Mth.abs(dy);
float az = Mth.abs(dz);
float max = MHelper.max(ax, ay, az);
int count = Mth.ceil(max);
dx /= count;
dy /= count;
dz /= count;
boolean hit = true;
for (int i = 2; i < count; i++) {
mpos.set(pos.getX() + dx * i, pos.getY() + dy * i, pos.getZ() + dz * i);
BlockState blockState = world.getBlockState(mpos);
if (blockState.getMaterial().blocksMotion() && !(blockState.getBlock() instanceof BrainTreeBlock)) {
hit = false;
break;
}
}
if (hit) {
LightningRayEntity lightningRay = EdenEntities.LIGHTNING_RAY.create(world);
lightningRay.teleportTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
lightningRay.setEnd(entity.position());
world.addFreshEntity(lightningRay);
world.playLocalSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.LIGHTNING_BOLT_IMPACT, SoundSource.WEATHER, MHelper.randRange(1.0F, 5.0F, random), MHelper.randRange(0.5F, 1.5F, random), false);
if (entity.isInvulnerable()) {
return;
}
float resistance = 0;
Iterator<ItemStack> iterator = entity.getArmorSlots().iterator();
while (iterator.hasNext()) {
ItemStack stack = iterator.next();
if (stack.getItem() instanceof ArmorItem) {
ArmorItem item = (ArmorItem) stack.getItem();
ArmorMaterial material = item.getMaterial();
for (ArmorMaterial m : PROTECTIVE) {
if (material == m) {
resistance += 0.25F;
break;
}
}
}
}
if (resistance < 1) {
entity.hurt(DamageSource.LIGHTNING_BOLT, (1 - resistance) * 3F);
}
}
}
}
Aggregations