Search in sources :

Example 16 with RaycastContext

use of net.minecraft.world.RaycastContext in project Client by MatHax.

the class Notebot method rayTraceCheck.

// Stolen from crystal aura :)
private Direction rayTraceCheck(BlockPos pos) {
    Vec3d eyesPos = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
    for (Direction direction : Direction.values()) {
        RaycastContext raycastContext = new RaycastContext(eyesPos, new Vec3d(pos.getX() + 0.5 + direction.getVector().getX() * 0.5, pos.getY() + 0.5 + direction.getVector().getY() * 0.5, pos.getZ() + 0.5 + direction.getVector().getZ() * 0.5), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
        BlockHitResult result = mc.world.raycast(raycastContext);
        if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(pos))
            return direction;
    }
    if (pos.getY() > eyesPos.y)
        return Direction.DOWN;
    return Direction.UP;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 17 with RaycastContext

use of net.minecraft.world.RaycastContext in project Client by MatHax.

the class BlockUtils method rayTraceCheck.

public static Direction rayTraceCheck(BlockPos blockPos, boolean bl) {
    Vec3d vec3d = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
    for (Direction direction : Direction.values()) {
        RaycastContext raycastContext = new RaycastContext(vec3d, new Vec3d((double) blockPos.getX() + 0.5 + (double) direction.getVector().getX() * 0.5, (double) blockPos.getY() + 0.5 + (double) direction.getVector().getY() * 0.5, (double) blockPos.getZ() + 0.5 + (double) direction.getVector().getZ() * 0.5), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
        BlockHitResult blockHitResult = mc.world.raycast(raycastContext);
        if (blockHitResult == null || blockHitResult.getType() != HitResult.Type.BLOCK || !blockHitResult.getBlockPos().equals(blockPos))
            continue;
        return direction;
    }
    if (bl) {
        if ((double) blockPos.getY() > vec3d.y)
            return Direction.DOWN;
        return Direction.UP;
    }
    return null;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) IVec3d(mathax.client.mixininterface.IVec3d)

Example 18 with RaycastContext

use of net.minecraft.world.RaycastContext in project Essential-Commands by John-Paul-R.

the class RandomTeleportCommand method exec.

private static int exec(ServerPlayerEntity player, ServerWorld world, MinecraftLocation center, int timesRun) {
    if (timesRun > CONFIG.RTP_MAX_ATTEMPTS.getValue()) {
        return -1;
    }
    // Calculate position on circle perimeter
    int r = CONFIG.RTP_RADIUS.getValue();
    double angle = (new Random()).nextDouble() * 2 * Math.PI;
    double delta_x = r * Math.cos(angle);
    double delta_z = r * Math.sin(angle);
    double new_x = center.pos.x + delta_x;
    double new_z = center.pos.z + delta_z;
    // Search for a valid y-level (not in a block, underwater, out of the world, etc.)
    // TODO Can maybe run a loop that checks every-other block? (player is 2 blocks high)
    int new_y;
    Stopwatch timer = Stopwatch.createStarted();
    BlockHitResult blockHitResult = world.raycast(new RaycastContext(new Vec3d(new_x, world.getHeight(), new_z), new Vec3d(new_x, 1, new_z), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.SOURCE_ONLY, player));
    new_y = blockHitResult.getBlockPos().getY() + 1;
    EssentialCommands.LOGGER.info(ECText.getInstance().getText("cmd.rtp.log.location_validate_time", timer.stop()).getString());
    // Addressed by adding timesRun limit.
    if (world.isWater(new BlockPos(new_x, new_y - 2, new_z))) {
        return exec(player, world, center, timesRun + 1);
    }
    // Teleport the player
    PlayerTeleporter.requestTeleport(player, new MinecraftLocation(world.getRegistryKey(), new_x, new_y, new_z, 0, 0), ECText.getInstance().getText("cmd.rtp.location_name"));
    return 1;
}
Also used : MinecraftLocation(com.fibermc.essentialcommands.types.MinecraftLocation) Random(java.util.Random) RaycastContext(net.minecraft.world.RaycastContext) Stopwatch(com.google.common.base.Stopwatch) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 19 with RaycastContext

use of net.minecraft.world.RaycastContext in project Miskatonic-Mysteries-Fabric by cybercat5555.

the class VisionSpellMedium method cast.

@Override
public boolean cast(World world, LivingEntity caster, SpellEffect effect, int intensity) {
    Vec3d vec3d = caster.getCameraPosVec(1);
    Vec3d vec3d2 = caster.getRotationVec(1);
    Vec3d vec3d3 = vec3d.add(vec3d2.x * getMaxDistance(), vec3d2.y * getMaxDistance(), vec3d2.z * getMaxDistance());
    double distance = Math.pow(getMaxDistance(), 2);
    EntityHitResult hit = ProjectileUtil.getEntityCollision(world, caster, vec3d, vec3d3, caster.getBoundingBox().stretch(vec3d2.multiply(distance)).expand(1.0D, 1.0D, 1.0D), (target) -> !target.isSpectator() && target.collides());
    if (hit != null && caster.canSee(hit.getEntity())) {
        return effect.effect(world, caster, hit.getEntity(), hit.getPos(), this, intensity, caster);
    } else {
        HitResult blockHit = world.raycast(new RaycastContext(vec3d, vec3d3, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, caster));
        return effect.effect(world, caster, null, blockHit.getPos(), this, intensity, caster);
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) RaycastContext(net.minecraft.world.RaycastContext) Vec3d(net.minecraft.util.math.Vec3d) EntityHitResult(net.minecraft.util.hit.EntityHitResult)

Example 20 with RaycastContext

use of net.minecraft.world.RaycastContext in project pick-block-pro by Sjouwer.

the class Raycast method getHit.

public static HitResult getHit(int range, RaycastContext.FluidHandling fluidHandling, boolean ignoreEntities) {
    Entity player = client.cameraEntity;
    Vec3d vector = player.getRotationVec(client.getTickDelta());
    Vec3d rayStart = player.getCameraPosVec(client.getTickDelta());
    Vec3d rayEnd = rayStart.add(vector.multiply(range));
    BlockHitResult blockHit = client.world.raycast(new RaycastContext(rayStart, rayEnd, RaycastContext.ShapeType.OUTLINE, fluidHandling, player));
    if (ignoreEntities) {
        return blockHit;
    }
    Box box = player.getBoundingBox().stretch(vector.multiply(range));
    int range2 = range * range;
    EntityHitResult entityHit = ProjectileUtil.raycast(player, rayStart, rayEnd, box, entityX -> !entityX.isSpectator() && entityX.collides(), range2);
    if (entityHit == null) {
        return blockHit;
    }
    if (blockHit.getPos().squaredDistanceTo(player.getPos()) < entityHit.getPos().squaredDistanceTo(player.getPos())) {
        return blockHit;
    }
    return entityHit;
}
Also used : Entity(net.minecraft.entity.Entity) RaycastContext(net.minecraft.world.RaycastContext) Box(net.minecraft.util.math.Box) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

RaycastContext (net.minecraft.world.RaycastContext)46 Vec3d (net.minecraft.util.math.Vec3d)39 BlockHitResult (net.minecraft.util.hit.BlockHitResult)22 BlockPos (net.minecraft.util.math.BlockPos)13 HitResult (net.minecraft.util.hit.HitResult)11 Direction (net.minecraft.util.math.Direction)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Entity (net.minecraft.entity.Entity)9 Box (net.minecraft.util.math.Box)7 EntityHitResult (net.minecraft.util.hit.EntityHitResult)6 ArrayList (java.util.ArrayList)5 LivingEntity (net.minecraft.entity.LivingEntity)5 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)5 Hand (net.minecraft.util.Hand)5 Collectors (java.util.stream.Collectors)4 Item (net.minecraft.item.Item)4 ItemStack (net.minecraft.item.ItemStack)4 List (java.util.List)3 Predicate (java.util.function.Predicate)3 BlockEntity (net.minecraft.block.entity.BlockEntity)3