Search in sources :

Example 56 with MutableBlockPos

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;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 57 with MutableBlockPos

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;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 58 with MutableBlockPos

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;
}
Also used : ChunkPos(net.minecraft.world.level.ChunkPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) InterpolationCell(paulevs.edenring.noise.InterpolationCell) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 59 with MutableBlockPos

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);
                }
            }
        }
    });
}
Also used : EdenPortable(paulevs.edenring.interfaces.EdenPortable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) ServerLevel(net.minecraft.server.level.ServerLevel) ServerPlayer(net.minecraft.server.level.ServerPlayer) FeaturePlaceContext(net.minecraft.world.level.levelgen.feature.FeaturePlaceContext) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) AABB(net.minecraft.world.phys.AABB) MinecraftServer(net.minecraft.server.MinecraftServer) ResourceKey(net.minecraft.resources.ResourceKey)

Example 60 with MutableBlockPos

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);
            }
        }
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) LivingEntity(net.minecraft.world.entity.LivingEntity) ArmorItem(net.minecraft.world.item.ArmorItem) BlockState(net.minecraft.world.level.block.state.BlockState) LightningRayEntity(paulevs.edenring.entities.LightningRayEntity) ArmorMaterial(net.minecraft.world.item.ArmorMaterial) ItemStack(net.minecraft.world.item.ItemStack) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) AABB(net.minecraft.world.phys.AABB)

Aggregations

MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)60 BlockPos (net.minecraft.core.BlockPos)32 BlockState (net.minecraft.world.level.block.state.BlockState)31 Random (java.util.Random)16 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)16 Direction (net.minecraft.core.Direction)11 ArrayList (java.util.ArrayList)8 Block (net.minecraft.world.level.block.Block)4 Level (net.minecraft.world.level.Level)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Vector3f (com.mojang.math.Vector3f)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Nullable (javax.annotation.Nullable)2 AccessLevel (lombok.AccessLevel)2