Search in sources :

Example 21 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-crash-addon by AntiCope.

the class ContainerCrash method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (GLFW.glfwGetKey(mc.getWindow().getHandle(), GLFW.GLFW_KEY_ESCAPE) == GLFW.GLFW_PRESS) {
        toggle();
        mc.player.closeHandledScreen();
    }
    BlockIterator.register(4, 4, ((blockPos, blockState) -> {
        Block block = blockState.getBlock();
        if (block instanceof AbstractChestBlock || block instanceof ShulkerBoxBlock) {
            BlockHitResult bhr = new BlockHitResult(new Vec3d(blockPos.getX(), blockPos.getY(), blockPos.getZ()), Direction.DOWN, blockPos, false);
            PlayerInteractBlockC2SPacket openPacket = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, bhr);
            for (int i = 0; i < amount.get(); i++) {
                mc.getNetworkHandler().sendPacket(openPacket);
            }
        }
    }));
}
Also used : BlockIterator(meteordevelopment.meteorclient.utils.world.BlockIterator) Setting(meteordevelopment.meteorclient.settings.Setting) CrashAddon(widecat.meteorcrashaddon.CrashAddon) AbstractInventoryScreen(net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen) GameLeftEvent(meteordevelopment.meteorclient.events.game.GameLeftEvent) PlaySoundEvent(meteordevelopment.meteorclient.events.world.PlaySoundEvent) BlockHitResult(net.minecraft.util.hit.BlockHitResult) IntSetting(meteordevelopment.meteorclient.settings.IntSetting) SettingGroup(meteordevelopment.meteorclient.settings.SettingGroup) GLFW(org.lwjgl.glfw.GLFW) TickEvent(meteordevelopment.meteorclient.events.world.TickEvent) Direction(net.minecraft.util.math.Direction) OpenScreenEvent(meteordevelopment.meteorclient.events.game.OpenScreenEvent) Module(meteordevelopment.meteorclient.systems.modules.Module) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) Vec3d(net.minecraft.util.math.Vec3d) BoolSetting(meteordevelopment.meteorclient.settings.BoolSetting) net.minecraft.block(net.minecraft.block) Hand(net.minecraft.util.Hand) EventHandler(meteordevelopment.orbit.EventHandler) HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) EventHandler(meteordevelopment.orbit.EventHandler)

Example 22 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-crash-addon by AntiCope.

the class TryUseCrash method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    BlockHitResult bhr = new BlockHitResult(new Vec3d(.5, .5, .5), Direction.DOWN, mc.player.getBlockPos(), false);
    net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket packet = new PlayerInteractItemC2SPacket(Hand.MAIN_HAND);
    PlayerInteractBlockC2SPacket packet1 = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, bhr);
    if (mc.getNetworkHandler() == null)
        return;
    for (int i = 0; i < packets.get(); i++) {
        mc.getNetworkHandler().sendPacket(packet);
        mc.getNetworkHandler().sendPacket(packet1);
    }
}
Also used : PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) PlayerInteractItemC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket) EventHandler(meteordevelopment.orbit.EventHandler)

Example 23 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.

the class GhostHand method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (!mc.options.useKey.isPressed() || mc.player.isSneaking())
        return;
    for (BlockEntity blockEntity : Utils.blockEntities()) {
        if (new BlockPos(mc.player.raycast(mc.interactionManager.getReachDistance(), mc.getTickDelta(), false).getPos()).equals(blockEntity.getPos()))
            return;
    }
    Vec3d nextPos = new Vec3d(0, 0, 0.1).rotateX(-(float) Math.toRadians(mc.player.getPitch())).rotateY(-(float) Math.toRadians(mc.player.getYaw()));
    for (int i = 1; i < mc.interactionManager.getReachDistance() * 10; i++) {
        BlockPos curPos = new BlockPos(mc.player.getCameraPosVec(mc.getTickDelta()).add(nextPos.multiply(i)));
        if (posList.contains(curPos))
            continue;
        posList.add(curPos);
        for (BlockEntity blockEntity : Utils.blockEntities()) {
            if (blockEntity.getPos().equals(curPos)) {
                mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, curPos, true));
                return;
            }
        }
    }
    posList.clear();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) BlockEntity(net.minecraft.block.entity.BlockEntity) EventHandler(meteordevelopment.orbit.EventHandler)

Example 24 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.

the class BlockUtils method place.

public static boolean place(BlockPos blockPos, Hand hand, int slot, boolean rotate, int rotationPriority, boolean swingHand, boolean checkEntities, boolean swapBack) {
    if (slot < 0 || slot > 8)
        return false;
    if (!canPlace(blockPos, checkEntities))
        return false;
    ((IVec3d) hitPos).set(blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5);
    BlockPos neighbour;
    Direction side = getPlaceSide(blockPos);
    if (side == null) {
        side = Direction.UP;
        neighbour = blockPos;
    } else {
        neighbour = blockPos.offset(side.getOpposite());
        hitPos.add(side.getOffsetX() * 0.5, side.getOffsetY() * 0.5, side.getOffsetZ() * 0.5);
    }
    Direction s = side;
    if (rotate) {
        Rotations.rotate(Rotations.getYaw(hitPos), Rotations.getPitch(hitPos), rotationPriority, () -> {
            InvUtils.swap(slot, swapBack);
            place(new BlockHitResult(hitPos, s, neighbour, false), hand, swingHand);
            if (swapBack)
                InvUtils.swapBack();
        });
    } else {
        InvUtils.swap(slot, swapBack);
        place(new BlockHitResult(hitPos, s, neighbour, false), hand, swingHand);
        if (swapBack)
            InvUtils.swapBack();
    }
    return true;
}
Also used : IVec3d(meteordevelopment.meteorclient.mixininterface.IVec3d) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction)

Example 25 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.

the class LookingAtHud method getRight.

@Override
protected String getRight() {
    if (isInEditor())
        return position.get() ? "Obsidian (0, 0, 0)" : "Obsidian";
    if (mc.crosshairTarget.getType() == HitResult.Type.BLOCK) {
        BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
        String result = Names.get(mc.world.getBlockState(pos).getBlock());
        if (position.get()) {
            result += String.format(" (%d, %d, %d)", pos.getX(), pos.getY(), pos.getZ());
        }
        if (waterLogged.get() && mc.world.getFluidState(pos).isIn(FluidTags.WATER)) {
            result += " (water logged)";
        }
        return result;
    } else if (mc.crosshairTarget.getType() == HitResult.Type.ENTITY) {
        Entity target = ((EntityHitResult) mc.crosshairTarget).getEntity();
        String result;
        if (target instanceof PlayerEntity)
            result = ((PlayerEntity) target).getGameProfile().getName();
        else
            result = target.getName().getString();
        if (position.get()) {
            result += String.format(" (%d, %d, %d)", target.getBlockX(), target.getBlockY(), target.getBlockZ());
        }
        if (waterLogged.get() && target.isTouchingWater()) {
            result += " (in water)";
        }
        return result;
    }
    return "";
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

BlockHitResult (net.minecraft.util.hit.BlockHitResult)83 BlockPos (net.minecraft.util.math.BlockPos)45 Vec3d (net.minecraft.util.math.Vec3d)36 Direction (net.minecraft.util.math.Direction)20 Hand (net.minecraft.util.Hand)17 BlockState (net.minecraft.block.BlockState)15 HitResult (net.minecraft.util.hit.HitResult)14 RaycastContext (net.minecraft.world.RaycastContext)13 BlockEntity (net.minecraft.block.entity.BlockEntity)12 ItemStack (net.minecraft.item.ItemStack)11 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Box (net.minecraft.util.math.Box)10 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)9 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)9 List (java.util.List)8 EventHandler (meteordevelopment.orbit.EventHandler)8 Entity (net.minecraft.entity.Entity)8 World (net.minecraft.world.World)6 ArrayList (java.util.ArrayList)5