Search in sources :

Example 21 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class FireArmorItem method clientTick.

// @Override
// public void damageArmor(LivingEntity player, ItemStack stack, DamageSource source, int damage, int slot) {
// if (source == DamageSource.IN_FIRE || source == DamageSource.LAVA) {
// //cheap way to slow the damage
// //if (player.worldObj.getWorldTime() % 2 == 0) {
// stack.damageItem(damage, player);
// }
// }
// 
@OnlyIn(Dist.CLIENT)
public void clientTick(Player player) {
    // Don't show fire particles underwater
    if (player.isInWater())
        return;
    float range = 0.2F;
    float speed = 0.08F;
    Random rand = new Random();
    Level worldRef = player.level;
    int extraRand = 0;
    final Vec3 motion = player.getDeltaMovement();
    double plSpeed = Math.sqrt(motion.x * motion.x + motion.z * motion.z);
    if (plSpeed < 0.1F) {
        extraRand = 7;
    }
    /**
     * 0 for all, 1 for minimal, 2 for off
     */
    ParticleStatus particles = Minecraft.getInstance().options.particles;
    if (particles == ParticleStatus.MINIMAL)
        return;
    if (this == TropicraftItems.FIRE_BOOTS.get()) {
        boolean onLava = false;
        boolean inLava = false;
        // for (int x = -1; x < 2; x++) {
        // for (int z = -1; z < 2; z++) {
        int x = 0;
        int z = 0;
        if (motion.y < 0) {
            BlockState state = player.level.getBlockState(new BlockPos(Mth.floor(player.getX() + x), Mth.floor(player.getY() - 2), Mth.floor(player.getZ() + z)));
            if (state.getMaterial() == Material.LAVA) {
                onLava = true;
            }
        }
        BlockState block2 = player.level.getBlockState(new BlockPos(Mth.floor(player.getX() + x), Mth.floor(player.getY() - 1), Mth.floor(player.getZ() + z)));
        if (block2.getMaterial() == Material.LAVA) {
            inLava = true;
        }
        // why do we do this on the client?
        if (onLava && !inLava) {
            player.setDeltaMovement(motion.multiply(1, 0, 1));
            player.setOnGround(true);
        }
        // why do we do this on the client???????
        if (inLava) {
            if (plSpeed < 0.4D) {
                player.setDeltaMovement(motion.multiply(1.5D, 1.5D, 1.5D));
            }
        }
        float look = player.level.getGameTime() * (10 + (onLava ? 10 : 0));
        double dist = 1F;
        double gatherX = player.getX();
        double gatherY = player.getBoundingBox().minY;
        double gatherZ = player.getZ();
        double motionX = ((rand.nextFloat() * speed) - (speed / 2));
        double motionZ = ((rand.nextFloat() * speed) - (speed / 2));
        final int numFeetParticles = particles == ParticleStatus.DECREASED ? 2 : 11;
        for (int i = 0; i < numFeetParticles + (onLava ? 5 : 0); i++) {
            motionX = (-Math.sin((look) / 180.0F * 3.1415927F) * Math.cos(0 / 180.0F * 3.1415927F) * (speed + (0.1 * rand.nextDouble())));
            motionZ = (Math.cos((look) / 180.0F * 3.1415927F) * Math.cos(0 / 180.0F * 3.1415927F) * (speed + (0.1 * rand.nextDouble())));
            SimpleParticleType particle = ParticleTypes.FLAME;
            if (rand.nextInt(22) == 0)
                particle = ParticleTypes.LARGE_SMOKE;
            if (onLava || rand.nextInt(1 + extraRand) == 0) {
                Vec3 motion1 = player.getDeltaMovement();
                player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), gatherY + ((rand.nextFloat() * range) - (range / 2)), gatherZ + ((rand.nextFloat() * range) - (range / 2)), motion1.x + motionX, 0.01F, motion1.z + motionZ);
                player.level.addParticle(particle, (double) gatherX + ((rand.nextFloat() * range) - (range / 2)), (double) gatherY + ((rand.nextFloat() * range) - (range / 2)), (double) gatherZ + ((rand.nextFloat() * range) - (range / 2)), motion1.x - motionX, 0.01F, motion1.z - motionZ);
            }
        }
    } else if (this == TropicraftItems.FIRE_LEGGINGS.get()) {
        SimpleParticleType particle = ParticleTypes.FLAME;
        if (rand.nextInt(2) == 0)
            particle = ParticleTypes.LARGE_SMOKE;
        if (rand.nextInt(3 + extraRand) == 0) {
            player.level.addParticle(particle, player.getX() + ((rand.nextFloat() * range) - (range / 2)), player.getY() - 0.8F + ((rand.nextFloat() * range) - (range / 2)), player.getZ() + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.05F, ((rand.nextFloat() * speed) - (speed / 2)));
        }
    } else if (this == TropicraftItems.FIRE_CHESTPLATE.get()) {
        float look = -180F;
        double dist = 0.5F;
        double gatherX = player.getX() + (-Math.sin((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
        double gatherZ = player.getZ() + (Math.cos((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
        SimpleParticleType particle = ParticleTypes.FLAME;
        if (rand.nextInt(2) == 0)
            particle = ParticleTypes.LARGE_SMOKE;
        if (rand.nextInt(1 + extraRand) == 0) {
            player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), player.getY() - 0.4F + ((rand.nextFloat() * range) - (range / 2)), gatherZ + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.01F, ((rand.nextFloat() * speed) - (speed / 2)));
        }
    } else if (this == TropicraftItems.FIRE_HELMET.get()) {
        float look = -180F;
        double dist = 0.5F;
        range = 2F;
        double gatherX = player.getX() + (-Math.sin((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
        double gatherZ = player.getZ() + (Math.cos((player.getYRot() + look) / 180.0F * 3.1415927F) * Math.cos(player.getXRot() / 180.0F * 3.1415927F) * dist);
        SimpleParticleType particle = ParticleTypes.FLAME;
        if (rand.nextInt(2) == 0)
            particle = ParticleTypes.LARGE_SMOKE;
        if (rand.nextInt(2) == 0) {
            player.level.addParticle(particle, gatherX + ((rand.nextFloat() * range) - (range / 2)), player.getY() + 0.7F, gatherZ + ((rand.nextFloat() * range) - (range / 2)), ((rand.nextFloat() * speed) - (speed / 2)), -0.01F, ((rand.nextFloat() * speed) - (speed / 2)));
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ParticleStatus(net.minecraft.client.ParticleStatus) Vec3(net.minecraft.world.phys.Vec3) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 22 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class FurnitureEntity method tick.

@Override
public void tick() {
    final int timeSinceHit = getTimeSinceHit();
    if (timeSinceHit > 0) {
        setTimeSinceHit(timeSinceHit - 1);
    }
    final float damage = getDamage();
    if (damage > 0) {
        setDamage(damage - 1);
    }
    final Vec3 currentPos = position();
    xo = currentPos.x;
    yo = currentPos.y;
    zo = currentPos.z;
    super.tick();
    tickLerp();
    if (preventMotion()) {
        setDeltaMovement(Vec3.ZERO);
    }
    // updateRocking();
    this.checkInsideBlocks();
    List<Entity> list = this.level.getEntities(this, this.getBoundingBox().inflate((double) 0.2F, (double) -0.01F, (double) 0.2F), EntitySelector.pushableBy(this));
    if (!list.isEmpty()) {
        for (Entity entity : list) {
            if (!entity.hasPassenger(this)) {
                this.push(entity);
            }
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) Vec3(net.minecraft.world.phys.Vec3)

Example 23 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class TropicraftFishEntity method setRandomTargetHeading.

public boolean setRandomTargetHeading() {
    boolean result = false;
    int dist = 16;
    Vec3 randBlock = new Vec3(getX() + randFlip(dist), getY() + randFlip(dist / 2), getZ() + randFlip(dist));
    result = this.setTargetHeading(randBlock.x, randBlock.y, randBlock.z, true);
    // Try to move towards a player
    if (this.approachPlayers) {
        if (random.nextInt(50) == 0) {
            Player closest = level.getNearestPlayer(this, 32D);
            if (closest != null) {
                if (closest.isInWater())
                    result = this.setTargetHeading(closest.getX(), closest.getY(), closest.getZ(), true);
            }
        }
    }
    return result;
}
Also used : Player(net.minecraft.world.entity.player.Player) Vec3(net.minecraft.world.phys.Vec3)

Example 24 with Vec3

use of net.minecraft.world.phys.Vec3 in project Tropicraft by Tropicraft.

the class HugePlantBlockHighlight method renderHugePlantHighlight.

private static void renderHugePlantHighlight(DrawSelectionEvent.HighlightBlock event, ClientLevel world, BlockPos pos, BlockState state) {
    HugePlantBlock.Shape shape = HugePlantBlock.Shape.matchIncomplete(state.getBlock(), world, pos);
    if (shape == null)
        return;
    VertexConsumer builder = event.getBuffers().getBuffer(RenderType.lines());
    Vec3 view = event.getInfo().getPosition();
    AABB aabb = shape.asAabb().move(-view.x, -view.y, -view.z);
    LevelRenderer.renderLineBox(event.getMatrix(), builder, aabb, 0.0F, 0.0F, 0.0F, 0.4F);
    event.setCanceled(true);
}
Also used : Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) AABB(net.minecraft.world.phys.AABB)

Example 25 with Vec3

use of net.minecraft.world.phys.Vec3 in project MC-Prefab by Brian-Wuest.

the class StructureRenderHandler method renderBlock.

private static void renderBlock(Level world, PoseStack matrixStack, Vec3 pos, BlockState state, MultiBufferSource.BufferSource entityVertexConsumer, BlockPos blockPos) {
    Minecraft minecraft = Minecraft.getInstance();
    Camera camera = minecraft.getEntityRenderDispatcher().camera;
    Vec3 projectedView = camera.getPosition();
    if (state.getRenderShape() != RenderShape.INVISIBLE && state.getRenderShape() == RenderShape.MODEL) {
        matrixStack.pushPose();
        matrixStack.translate(-projectedView.x(), -projectedView.y(), -projectedView.z());
        matrixStack.translate(pos.x(), pos.y(), pos.z());
        BlockRenderDispatcher renderer = minecraft.getBlockRenderer();
        VertexConsumer consumer = entityVertexConsumer.getBuffer(Sheets.translucentItemSheet());
        TranslucentVertexConsumer translucentConsumer = new TranslucentVertexConsumer(consumer, 100);
        int color = minecraft.getBlockColors().getColor(state, world, blockPos, 50);
        float r = (float) (color >> 16 & 255) / 255.0F;
        float g = (float) (color >> 8 & 255) / 255.0F;
        float b = (float) (color & 255) / 255.0F;
        renderer.getModelRenderer().renderModel(matrixStack.last(), translucentConsumer, state, renderer.getBlockModel(state), r, g, b, 0xF000F0, OverlayTexture.NO_OVERLAY);
        matrixStack.popPose();
    }
}
Also used : BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) Vec3(net.minecraft.world.phys.Vec3) Camera(net.minecraft.client.Camera) Minecraft(net.minecraft.client.Minecraft)

Aggregations

Vec3 (net.minecraft.world.phys.Vec3)1131 BlockPos (net.minecraft.core.BlockPos)341 ItemStack (net.minecraft.world.item.ItemStack)189 Entity (net.minecraft.world.entity.Entity)133 Direction (net.minecraft.core.Direction)127 AABB (net.minecraft.world.phys.AABB)125 LivingEntity (net.minecraft.world.entity.LivingEntity)124 BlockState (net.minecraft.world.level.block.state.BlockState)111 Player (net.minecraft.world.entity.player.Player)91 BlockHitResult (net.minecraft.world.phys.BlockHitResult)85 Level (net.minecraft.world.level.Level)81 ServerLevel (net.minecraft.server.level.ServerLevel)74 ItemEntity (net.minecraft.world.entity.item.ItemEntity)74 InputWindowElement (com.simibubi.create.foundation.ponder.element.InputWindowElement)61 Selection (com.simibubi.create.foundation.ponder.Selection)53 ClipContext (net.minecraft.world.level.ClipContext)53 ServerPlayer (net.minecraft.server.level.ServerPlayer)51 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)43 HitResult (net.minecraft.world.phys.HitResult)43 WorldSectionElement (com.simibubi.create.foundation.ponder.element.WorldSectionElement)40