Search in sources :

Example 1 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project BleachHack by BleachDrinker420.

the class CmdNBT method getNbt.

private NbtCompound getNbt(String arg) {
    if (arg.equalsIgnoreCase("hand")) {
        return mc.player.getMainHandStack().getOrCreateNbt();
    } else if (arg.equalsIgnoreCase("block")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) target).getBlockPos();
            BlockEntity be = mc.world.getBlockEntity(pos);
            if (be != null) {
                return be.writeNbt(new NbtCompound());
            } else {
                return new NbtCompound();
            }
        }
        BleachLogger.error("Not looking at a block.");
        return null;
    } else if (arg.equalsIgnoreCase("entity")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.ENTITY) {
            return ((EntityHitResult) target).getEntity().writeNbt(new NbtCompound());
        }
        BleachLogger.error("Not looking at an entity.");
        return null;
    }
    throw new CmdSyntaxException();
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) NbtCompound(net.minecraft.nbt.NbtCompound) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 2 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project fabric by FabricMC.

the class MixinServerPlayNetworkHandler method onPlayerInteractEntity.

@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
    World world = player.getEntityWorld();
    Entity entity = packet.getEntity(world);
    if (entity != null) {
        EntityHitResult hitResult = new EntityHitResult(entity, packet.getHitPosition().add(entity.x, entity.y, entity.z));
        ActionResult result = UseEntityCallback.EVENT.invoker().interact(player, world, packet.getHand(), entity, hitResult);
        if (result != ActionResult.PASS) {
            info.cancel();
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ActionResult(net.minecraft.util.ActionResult) World(net.minecraft.world.World) EntityHitResult(net.minecraft.util.hit.EntityHitResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 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 4 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 5 with EntityHitResult

use of net.minecraft.util.hit.EntityHitResult in project Hypnotic-Client by Hypnotic-Development.

the class Freecam method onTick.

@Override
public void onTick() {
    perspective = mc.options.getPerspective();
    if (mc.cameraEntity.isInsideWall())
        mc.getCameraEntity().noClip = true;
    if (!perspective.isFirstPerson())
        mc.options.setPerspective(Perspective.FIRST_PERSON);
    if (mc.currentScreen != null)
        return;
    yaw = mc.cameraEntity.getYaw();
    Vec3d forward = Vec3d.fromPolar(0, yaw);
    Vec3d right = Vec3d.fromPolar(0, yaw + 90);
    double velX = 0;
    double velY = 0;
    double velZ = 0;
    BlockPos crossHairPos;
    Vec3d crossHairPosition;
    if (mc.crosshairTarget instanceof EntityHitResult) {
        crossHairPos = ((EntityHitResult) mc.crosshairTarget).getEntity().getBlockPos();
        RotationUtils.rotate(RotationUtils.getYaw(crossHairPos), RotationUtils.getPitch(crossHairPos), 0, null);
    } else {
        crossHairPosition = mc.crosshairTarget.getPos();
        crossHairPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
        if (!mc.world.getBlockState(crossHairPos).isAir()) {
            RotationUtils.rotate(RotationUtils.getYaw(crossHairPosition), RotationUtils.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 * speed.getValue();
        velZ += forward.z * s * speed.getValue();
        a = true;
    }
    if (this.backward) {
        velX -= forward.x * s * speed.getValue();
        velZ -= forward.z * s * speed.getValue();
        a = true;
    }
    boolean b = false;
    if (this.right) {
        velX += right.x * s * speed.getValue();
        velZ += right.z * s * speed.getValue();
        b = true;
    }
    if (this.left) {
        velX -= right.x * s * speed.getValue();
        velZ -= right.z * s * speed.getValue();
        b = true;
    }
    if (a && b) {
        double diagonal = 1 / Math.sqrt(2);
        velX *= diagonal;
        velZ *= diagonal;
    }
    if (this.up) {
        velY += s * speed.getValue();
    }
    if (this.down) {
        velY -= s * speed.getValue();
    }
    prevPos.set(pos);
    pos.set(pos.x + velX, pos.y + velY, pos.z + velZ);
    super.onTick();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) EntityHitResult(net.minecraft.util.hit.EntityHitResult)

Aggregations

EntityHitResult (net.minecraft.util.hit.EntityHitResult)12 HitResult (net.minecraft.util.hit.HitResult)6 BlockPos (net.minecraft.util.math.BlockPos)6 Vec3d (net.minecraft.util.math.Vec3d)5 Entity (net.minecraft.entity.Entity)4 BlockHitResult (net.minecraft.util.hit.BlockHitResult)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 ItemStack (net.minecraft.item.ItemStack)3 EventHandler (mathax.client.eventbus.EventHandler)2 EventHandler (meteordevelopment.orbit.EventHandler)2 BlockState (net.minecraft.block.BlockState)2 Item (net.minecraft.item.Item)2 Box (net.minecraft.util.math.Box)2 Direction (net.minecraft.util.math.Direction)2 VoxelShape (net.minecraft.util.shape.VoxelShape)2 World (net.minecraft.world.World)2 IOffhandAttack (chronosacaria.mcdw.api.interfaces.IOffhandAttack)1 Subscribe (com.google.common.eventbus.Subscribe)1 Friend (dev.hypnotic.config.friends.Friend)1 EventTarget (dev.hypnotic.event.EventTarget)1