Search in sources :

Example 11 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project HWG by cybercat-mods.

the class RocketEntity method tick.

@Override
public void tick() {
    super.tick();
    boolean bl = this.isNoClip();
    Vec3d vec3d = this.getVelocity();
    if (this.prevPitch == 0.0F && this.prevYaw == 0.0F) {
        double f = vec3d.horizontalLength();
        this.setYaw((float) (MathHelper.atan2(vec3d.x, vec3d.z) * 57.2957763671875D));
        this.setPitch((float) (MathHelper.atan2(vec3d.y, f) * 57.2957763671875D));
        this.prevYaw = this.getYaw();
        this.prevPitch = this.getPitch();
    }
    if (this.age >= 80) {
        this.explode();
        this.remove(Entity.RemovalReason.DISCARDED);
    }
    if (this.inAir && !bl) {
        this.age();
        ++this.timeInAir;
    } else {
        this.timeInAir = 0;
        Vec3d vec3d3 = this.getPos();
        Vec3d vector3d3 = vec3d3.add(vec3d);
        HitResult hitResult = this.world.raycast(new RaycastContext(vec3d3, vector3d3, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, this));
        if (((HitResult) hitResult).getType() != HitResult.Type.MISS) {
            vector3d3 = ((HitResult) hitResult).getPos();
        }
        while (!this.isRemoved()) {
            EntityHitResult entityHitResult = this.getEntityCollision(vec3d3, vector3d3);
            if (entityHitResult != null) {
                hitResult = entityHitResult;
            }
            if (hitResult != null && ((HitResult) hitResult).getType() == HitResult.Type.ENTITY) {
                Entity entity = ((EntityHitResult) hitResult).getEntity();
                Entity entity2 = this.getOwner();
                if (entity instanceof PlayerEntity && entity2 instanceof PlayerEntity && !((PlayerEntity) entity2).shouldDamagePlayer((PlayerEntity) entity)) {
                    hitResult = null;
                    entityHitResult = null;
                }
            }
            if (hitResult != null && !bl) {
                this.onCollision((HitResult) hitResult);
                this.velocityDirty = true;
            }
            if (entityHitResult == null || this.getPierceLevel() <= 0) {
                break;
            }
            hitResult = null;
        }
        vec3d = this.getVelocity();
        double d = vec3d.x;
        double e = vec3d.y;
        double g = vec3d.z;
        double h = this.getX() + d;
        double j = this.getY() + e;
        double k = this.getZ() + g;
        double l = vec3d.horizontalLength();
        if (bl) {
            this.setYaw((float) (MathHelper.atan2(-e, -g) * 57.2957763671875D));
        } else {
            this.setYaw((float) (MathHelper.atan2(e, g) * 57.2957763671875D));
        }
        this.setPitch((float) (MathHelper.atan2(e, l) * 57.2957763671875D));
        this.setPitch(updateRotation(this.prevPitch, this.getPitch()));
        this.setYaw(updateRotation(this.prevYaw, this.getYaw()));
        float m = 0.99F;
        this.setVelocity(vec3d.multiply((double) m));
        if (!this.hasNoGravity() && !bl) {
            Vec3d vec3d5 = this.getVelocity();
            this.setVelocity(vec3d5.x, vec3d5.y - 0.05000000074505806D, vec3d5.z);
        }
        this.updatePosition(h, j, k);
        this.checkBlockCollision();
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) RaycastContext(net.minecraft.world.RaycastContext) Vec3d(net.minecraft.util.math.Vec3d) EntityHitResult(net.minecraft.util.hit.EntityHitResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 12 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project alaskanativecraft by Platymemo.

the class MinecraftClientMixin method pickDogsledItem.

@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/util/hit/EntityHitResult;getEntity()Lnet/minecraft/entity/Entity;", ordinal = 0), method = "doItemPick", cancellable = true)
private void pickDogsledItem(CallbackInfo ci) {
    Entity entity = ((EntityHitResult) this.crosshairTarget).getEntity();
    if (entity instanceof DogsledEntity) {
        ItemStack pickedDogsled = new ItemStack(((DogsledEntity) entity).asItem());
        PlayerInventory playerInventory = this.player.getInventory();
        int i = playerInventory.getSlotWithStack(pickedDogsled);
        if (this.player.getAbilities().creativeMode) {
            playerInventory.addPickBlock(pickedDogsled);
            this.interactionManager.clickCreativeStack(this.player.getStackInHand(Hand.MAIN_HAND), 36 + playerInventory.selectedSlot);
        } else if (i != -1) {
            if (PlayerInventory.isValidHotbarIndex(i)) {
                playerInventory.selectedSlot = i;
            } else {
                this.interactionManager.pickFromInventory(i);
            }
        }
        ci.cancel();
    }
}
Also used : Entity(net.minecraft.entity.Entity) DogsledEntity(com.github.platymemo.alaskanativecraft.entity.DogsledEntity) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) DogsledEntity(com.github.platymemo.alaskanativecraft.entity.DogsledEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ItemStack(net.minecraft.item.ItemStack) EntityHitResult(net.minecraft.util.hit.EntityHitResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 13 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project Client by MatHax.

the class ClickTP method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    if (mc.player.isUsingItem())
        return;
    if (mc.options.useKey.isPressed()) {
        HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);
        if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS)
            return;
        if (hitResult.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
            Direction side = ((BlockHitResult) hitResult).getSide();
            if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS)
                return;
            BlockState state = mc.world.getBlockState(pos);
            VoxelShape shape = state.getCollisionShape(mc.world, pos);
            if (shape.isEmpty())
                shape = state.getOutlineShape(mc.world, pos);
            double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y);
            mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ());
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) EventHandler(mathax.client.eventbus.EventHandler)

Example 14 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project Client by MatHax.

the class Freecam method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    if (mc.cameraEntity.isInsideWall())
        mc.getCameraEntity().noClip = true;
    if (!perspective.isFirstPerson())
        mc.options.setPerspective(Perspective.FIRST_PERSON);
    Vec3d forward = Vec3d.fromPolar(0, yaw);
    Vec3d right = Vec3d.fromPolar(0, yaw + 90);
    double velX = 0;
    double velY = 0;
    double velZ = 0;
    if (rotate.get()) {
        BlockPos crossHairPos;
        Vec3d crossHairPosition;
        if (mc.crosshairTarget instanceof EntityHitResult) {
            crossHairPos = ((EntityHitResult) mc.crosshairTarget).getEntity().getBlockPos();
            Rotations.rotate(Rotations.getYaw(crossHairPos), Rotations.getPitch(crossHairPos), 0, null);
        } else {
            crossHairPosition = mc.crosshairTarget.getPos();
            crossHairPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
            if (!mc.world.getBlockState(crossHairPos).isAir())
                Rotations.rotate(Rotations.getYaw(crossHairPosition), Rotations.getPitch(crossHairPosition), 0, null);
        }
    }
    double s = 0.5;
    if (mc.options.sprintKey.isPressed())
        s = 1;
    boolean a = false;
    if (this.forward) {
        velX += forward.x * s * speedValue;
        velZ += forward.z * s * speedValue;
        a = true;
    }
    if (this.backward) {
        velX -= forward.x * s * speedValue;
        velZ -= forward.z * s * speedValue;
        a = true;
    }
    boolean b = false;
    if (this.right) {
        velX += right.x * s * speedValue;
        velZ += right.z * s * speedValue;
        b = true;
    }
    if (this.left) {
        velX -= right.x * s * speedValue;
        velZ -= right.z * s * speedValue;
        b = true;
    }
    if (a && b) {
        double diagonal = 1 / Math.sqrt(2);
        velX *= diagonal;
        velZ *= diagonal;
    }
    if (this.up)
        velY += s * speedValue;
    if (this.down)
        velY -= s * speedValue;
    prevPos.set(pos);
    pos.set(pos.x + velX, pos.y + velY, pos.z + velZ);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) EntityHitResult(net.minecraft.util.hit.EntityHitResult) EventHandler(mathax.client.eventbus.EventHandler)

Example 15 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project libr-getter by gXLg.

the class LibrGetCommand method runSelector.

private static int runSelector(CommandContext<FabricClientCommandSource> context) {
    if (Worker.getState() != Worker.State.STANDBY) {
        context.getSource().sendFeedback(new LiteralText("LibrGetter is running!").formatted(Formatting.RED));
        return 1;
    }
    MinecraftClient client = MinecraftClient.getInstance();
    ClientWorld world = client.world;
    if (world == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: world == null").formatted(Formatting.RED));
        return 1;
    }
    ClientPlayerEntity player = client.player;
    if (player == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: player == null").formatted(Formatting.RED));
        return 1;
    }
    HitResult hit = client.crosshairTarget;
    if (hit == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: hit == null").formatted(Formatting.RED));
        return 1;
    }
    HitResult.Type hitType = hit.getType();
    if (hitType == HitResult.Type.MISS) {
        context.getSource().sendFeedback(new LiteralText("You are not targeting anything!").formatted(Formatting.RED));
        return 1;
    }
    if (hitType == HitResult.Type.BLOCK) {
        BlockPos blockPos = ((BlockHitResult) hit).getBlockPos();
        if (!world.getBlockState(blockPos).isOf(Blocks.LECTERN)) {
            context.getSource().sendFeedback(new LiteralText("Block is not a lectern!").formatted(Formatting.RED));
            return 1;
        }
        Worker.setBlock(blockPos);
        context.getSource().sendFeedback(new LiteralText("Block selected"));
    } else if (hitType == HitResult.Type.ENTITY) {
        EntityHitResult entityHitResult = (EntityHitResult) hit;
        Entity entity = entityHitResult.getEntity();
        if (!(entity instanceof MerchantEntity)) {
            context.getSource().sendFeedback(new LiteralText("Entity is not a villager!").formatted(Formatting.RED));
            return 1;
        }
        VillagerEntity villager = (VillagerEntity) entity;
        if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) {
            context.getSource().sendFeedback(new LiteralText("Villager is not a librarian!").formatted(Formatting.RED));
            return 1;
        }
        context.getSource().sendFeedback(new LiteralText("Villager selected"));
        Worker.setVillager(villager);
    }
    return 0;
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) Entity(net.minecraft.entity.Entity) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) ClientWorld(net.minecraft.client.world.ClientWorld) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) LiteralText(net.minecraft.text.LiteralText)

Aggregations

EntityHitResult (net.minecraft.util.hit.EntityHitResult)38 Entity (net.minecraft.entity.Entity)22 HitResult (net.minecraft.util.hit.HitResult)18 Vec3d (net.minecraft.util.math.Vec3d)16 BlockHitResult (net.minecraft.util.hit.BlockHitResult)15 BlockPos (net.minecraft.util.math.BlockPos)14 PlayerEntity (net.minecraft.entity.player.PlayerEntity)12 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)7 LivingEntity (net.minecraft.entity.LivingEntity)7 ItemStack (net.minecraft.item.ItemStack)6 TypedActionResult (net.minecraft.util.TypedActionResult)6 RaycastContext (net.minecraft.world.RaycastContext)6 Box (net.minecraft.util.math.Box)5 Inject (org.spongepowered.asm.mixin.injection.Inject)5 Item (net.minecraft.item.Item)4 Subscribe (com.google.common.eventbus.Subscribe)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 EventHandler (mathax.client.eventbus.EventHandler)2