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 meteor-client by MeteorDevelopment.
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 meteor-client by MeteorDevelopment.
the class CrystalAura method onActivate.
@Override
public void onActivate() {
breakTimer = 0;
placeTimer = 0;
ticksPassed = 0;
raycastContext = new RaycastContext(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
placing = false;
placingTimer = 0;
attacks = 0;
serverYaw = mc.player.getYaw();
bestTargetDamage = 0;
bestTargetTimer = 0;
lastRotationTimer = getLastRotationStopDelay();
renderTimer = 0;
breakRenderTimer = 0;
}
use of net.minecraft.world.RaycastContext in project meteor-client by MeteorDevelopment.
the class NoFall method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
if (mc.player.getAbilities().creativeMode)
return;
// Airplace mode
if (mode.get() == Mode.AirPlace) {
// Test if fall damage setting is valid
if (!airPlaceMode.get().test(mc.player.fallDistance))
return;
// Center and place block
if (anchor.get())
PlayerUtils.centerPlayer();
Rotations.rotate(mc.player.getYaw(), 90, Integer.MAX_VALUE, () -> {
double preY = mc.player.getVelocity().y;
((IVec3d) mc.player.getVelocity()).setY(0);
BlockUtils.place(mc.player.getBlockPos().down(), InvUtils.findInHotbar(itemStack -> itemStack.getItem() instanceof BlockItem), false, 0, true);
((IVec3d) mc.player.getVelocity()).setY(preY);
});
}
// Bucket mode
if (mode.get() == Mode.Bucket) {
if (mc.player.fallDistance > 3 && !EntityUtils.isAboveWater(mc.player)) {
// Place water
FindItemResult waterBucket = InvUtils.findInHotbar(Items.WATER_BUCKET);
if (!waterBucket.found())
return;
// Center player
if (anchor.get())
PlayerUtils.centerPlayer();
// Check if there is a block within 5 blocks
BlockHitResult result = mc.world.raycast(new RaycastContext(mc.player.getPos(), mc.player.getPos().subtract(0, 5, 0), RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, mc.player));
// Place water
if (result != null && result.getType() == HitResult.Type.BLOCK) {
useBucket(waterBucket, true);
}
}
// Remove water
if (placedWater && mc.player.getBlockStateAtPos().getFluidState().getFluid() == Fluids.WATER) {
useBucket(InvUtils.findInHotbar(Items.BUCKET), false);
}
}
}
use of net.minecraft.world.RaycastContext in project Primeval by devs-immortal.
the class CollapsingBlockEntity method tick.
@Override
public void tick() {
if (this.block.isAir()) {
this.discard();
} else {
Block block = this.block.getBlock();
Block source = this.sourceBlock.getBlock();
BlockPos blockPos2;
if (this.timeFalling++ == 0) {
blockPos2 = this.origin;
if (this.world.getBlockState(blockPos2).isOf(block) || this.world.getBlockState(blockPos2).isOf(source)) {
this.world.removeBlock(blockPos2, false);
} else if (!this.world.isClient) {
this.discard();
return;
}
}
if (!this.hasNoGravity()) {
this.setVelocity(this.getVelocity().add(0.0D, -0.04D, 0.0D));
}
this.move(MovementType.SELF, this.getVelocity());
if (!this.world.isClient) {
blockPos2 = this.getBlockPos();
boolean bl = this.block.getBlock() instanceof ConcretePowderBlock;
boolean bl2 = bl && this.world.getFluidState(blockPos2).isIn(FluidTags.WATER);
double d = this.getVelocity().lengthSquared();
if (bl && d > 1.0D) {
BlockHitResult blockHitResult = this.world.raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), this.getPos(), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.SOURCE_ONLY, this));
if (blockHitResult.getType() != HitResult.Type.MISS && this.world.getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) {
blockPos2 = blockHitResult.getBlockPos();
bl2 = true;
}
}
if (!this.onGround && !bl2) {
if (!this.world.isClient && (this.timeFalling > 100 && (blockPos2.getY() < 1 || blockPos2.getY() > 256) || this.timeFalling > 600)) {
if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
this.discard();
}
} else {
BlockState blockState = this.world.getBlockState(blockPos2);
this.setVelocity(this.getVelocity().multiply(0.7D, -0.5D, 0.7D));
if (!blockState.isOf(Blocks.MOVING_PISTON)) {
this.discard();
// !destroyedOnLanding
if (this.block.contains(Properties.WATERLOGGED) && this.world.getFluidState(blockPos2).getFluid() == Fluids.WATER) {
this.block = this.block.with(Properties.WATERLOGGED, true);
}
if (this.world.setBlockState(blockPos2, this.block, 3)) {
if (block instanceof FallingBlock) {
((FallingBlock) block).onLanding(this.world, blockPos2, this.block, blockState, this);
}
if (this.blockEntityData != null && this.block.hasBlockEntity()) {
BlockEntity $$11 = this.world.getBlockEntity(blockPos2);
if ($$11 != null) {
NbtCompound $$12 = $$11.createNbt();
Iterator var13 = this.blockEntityData.getKeys().iterator();
while (var13.hasNext()) {
String $$13 = (String) var13.next();
$$12.put($$13, this.blockEntityData.get($$13).copy());
}
try {
$$11.readNbt($$12);
} catch (Exception var15) {
}
$$11.markDirty();
}
}
} else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
}
}
}
this.setVelocity(this.getVelocity().multiply(0.98D));
}
}
Aggregations