Search in sources :

Example 6 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 7 with RaycastContext

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;
}
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 8 with RaycastContext

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;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) IRaycastContext(meteordevelopment.meteorclient.mixininterface.IRaycastContext) IVec3d(meteordevelopment.meteorclient.mixininterface.IVec3d)

Example 9 with RaycastContext

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);
        }
    }
}
Also used : BlockUtils(meteordevelopment.meteorclient.utils.world.BlockUtils) Setting(meteordevelopment.meteorclient.settings.Setting) TickEvent(meteordevelopment.meteorclient.events.world.TickEvent) Module(meteordevelopment.meteorclient.systems.modules.Module) PlayerUtils(meteordevelopment.meteorclient.utils.player.PlayerUtils) BoolSetting(meteordevelopment.meteorclient.settings.BoolSetting) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) InvUtils(meteordevelopment.meteorclient.utils.player.InvUtils) Modules(meteordevelopment.meteorclient.systems.modules.Modules) RaycastContext(net.minecraft.world.RaycastContext) Hand(net.minecraft.util.Hand) Rotations(meteordevelopment.meteorclient.utils.player.Rotations) Fluids(net.minecraft.fluid.Fluids) BaritoneAPI(baritone.api.BaritoneAPI) PlayerMoveC2SPacketAccessor(meteordevelopment.meteorclient.mixin.PlayerMoveC2SPacketAccessor) EntityUtils(meteordevelopment.meteorclient.utils.entity.EntityUtils) Predicate(java.util.function.Predicate) Categories(meteordevelopment.meteorclient.systems.modules.Categories) BlockHitResult(net.minecraft.util.hit.BlockHitResult) IPlayerMoveC2SPacket(meteordevelopment.meteorclient.mixininterface.IPlayerMoveC2SPacket) SettingGroup(meteordevelopment.meteorclient.settings.SettingGroup) Items(net.minecraft.item.Items) PacketEvent(meteordevelopment.meteorclient.events.packets.PacketEvent) HitResult(net.minecraft.util.hit.HitResult) BlockItem(net.minecraft.item.BlockItem) IVec3d(meteordevelopment.meteorclient.mixininterface.IVec3d) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) EnumSetting(meteordevelopment.meteorclient.settings.EnumSetting) EventHandler(meteordevelopment.orbit.EventHandler) IVec3d(meteordevelopment.meteorclient.mixininterface.IVec3d) RaycastContext(net.minecraft.world.RaycastContext) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockItem(net.minecraft.item.BlockItem) EventHandler(meteordevelopment.orbit.EventHandler)

Example 10 with RaycastContext

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));
    }
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) NbtCompound(net.minecraft.nbt.NbtCompound) Vec3d(net.minecraft.util.math.Vec3d) Iterator(java.util.Iterator) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockEntity(net.minecraft.block.entity.BlockEntity) FallingBlockEntity(net.minecraft.entity.FallingBlockEntity)

Aggregations

RaycastContext (net.minecraft.world.RaycastContext)16 BlockHitResult (net.minecraft.util.hit.BlockHitResult)12 Vec3d (net.minecraft.util.math.Vec3d)11 HitResult (net.minecraft.util.hit.HitResult)4 BlockPos (net.minecraft.util.math.BlockPos)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 List (java.util.List)2 IVec3d (meteordevelopment.meteorclient.mixininterface.IVec3d)2 EventHandler (meteordevelopment.orbit.EventHandler)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 Entity (net.minecraft.entity.Entity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Hand (net.minecraft.util.Hand)2 Box (net.minecraft.util.math.Box)2 Direction (net.minecraft.util.math.Direction)2 BaritoneAPI (baritone.api.BaritoneAPI)1 FloatingBlock (com.aether.blocks.FloatingBlock)1 AetherNonLivingEntity (com.aether.entities.AetherNonLivingEntity)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1