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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations