Search in sources :

Example 26 with BlockHitResult

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

the class AnchorAura method breakAnchor.

private void breakAnchor(BlockPos pos, FindItemResult anchor, FindItemResult glowStone) {
    if (pos == null || mc.world.getBlockState(pos).getBlock() != Blocks.RESPAWN_ANCHOR)
        return;
    mc.player.setSneaking(false);
    if (glowStone.isOffhand()) {
        mc.interactionManager.interactBlock(mc.player, mc.world, Hand.OFF_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
    } else {
        InvUtils.swap(glowStone.slot(), true);
        mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
    }
    if (anchor.isOffhand()) {
        mc.interactionManager.interactBlock(mc.player, mc.world, Hand.OFF_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
    } else {
        InvUtils.swap(anchor.slot(), true);
        mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
    }
    InvUtils.swapBack();
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 27 with BlockHitResult

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

the class CrystalAura method getPlaceInfo.

private BlockHitResult getPlaceInfo(BlockPos blockPos) {
    ((IVec3d) vec3d).set(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
    for (Direction side : Direction.values()) {
        ((IVec3d) vec3dRayTraceEnd).set(blockPos.getX() + 0.5 + side.getVector().getX() * 0.5, blockPos.getY() + 0.5 + side.getVector().getY() * 0.5, blockPos.getZ() + 0.5 + side.getVector().getZ() * 0.5);
        ((IRaycastContext) raycastContext).set(vec3d, vec3dRayTraceEnd, 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(blockPos)) {
            return result;
        }
    }
    Direction side = blockPos.getY() > vec3d.y ? Direction.DOWN : Direction.UP;
    return new BlockHitResult(vec3d, side, blockPos, false);
}
Also used : IVec3d(meteordevelopment.meteorclient.mixininterface.IVec3d) IRaycastContext(meteordevelopment.meteorclient.mixininterface.IRaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 28 with BlockHitResult

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

the class EChestFarmer method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    // Finding target pos
    if (target == null) {
        if (mc.crosshairTarget == null || mc.crosshairTarget.getType() != HitResult.Type.BLOCK)
            return;
        BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
        BlockState state = mc.world.getBlockState(pos);
        if (state.getMaterial().isReplaceable() || state.getBlock() == Blocks.ENDER_CHEST) {
            target = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
        } else
            return;
    }
    // Disable if the block is too far away
    if (PlayerUtils.distanceTo(target) > mc.interactionManager.getReachDistance()) {
        error("Target block pos out of reach.");
        target = null;
        return;
    }
    // Toggle if obby amount reached
    if (selfToggle.get() && InvUtils.find(Items.OBSIDIAN).count() - (ignoreExisting.get() ? startCount : 0) >= amount.get()) {
        InvUtils.swapBack();
        toggle();
        return;
    }
    // Break existing echest at target pos
    if (mc.world.getBlockState(target).getBlock() == Blocks.ENDER_CHEST) {
        double bestScore = -1;
        int bestSlot = -1;
        for (int i = 0; i < 9; i++) {
            ItemStack itemStack = mc.player.getInventory().getStack(i);
            if (EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, itemStack) > 0)
                continue;
            double score = itemStack.getMiningSpeedMultiplier(Blocks.ENDER_CHEST.getDefaultState());
            if (score > bestScore) {
                bestScore = score;
                bestSlot = i;
            }
        }
        if (bestSlot == -1)
            return;
        InvUtils.swap(bestSlot, true);
        BlockUtils.breakBlock(target, swingHand.get());
    }
    // Place echest if the target pos is empty
    if (mc.world.getBlockState(target).getMaterial().isReplaceable()) {
        FindItemResult echest = InvUtils.findInHotbar(Items.ENDER_CHEST);
        if (!echest.found()) {
            error("No Echests in hotbar, disabling");
            toggle();
            return;
        }
        BlockUtils.place(target, echest, true, 0, true);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack) EventHandler(meteordevelopment.orbit.EventHandler)

Example 29 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project tweakermore by Fallen-Breath.

the class SignTextCopier method copySignText.

public static boolean copySignText(KeyAction action, IKeybind key) {
    MinecraftClient mc = MinecraftClient.getInstance();
    if (mc.world != null && mc.crosshairTarget != null && mc.crosshairTarget.getType() == HitResult.Type.BLOCK) {
        BlockPos blockPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
        BlockState blockState = mc.world.getBlockState(blockPos);
        if (blockState.getBlock() instanceof AbstractSignBlock) {
            BlockEntity blockEntity = mc.world.getBlockEntity(blockPos);
            if (blockEntity instanceof SignBlockEntity) {
                String text = Joiner.on("\n").join(Arrays.stream(((SignBlockEntity) blockEntity).text).map(Text::getString).collect(Collectors.toList()));
                text = StringUtils.strip(text);
                if (!text.isEmpty()) {
                    mc.keyboard.setClipboard(text);
                    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.sign_copied", blockState.getBlock().getName());
                } else {
                    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.empty_sign", blockState.getBlock().getName());
                }
                return true;
            }
        }
    }
    InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.no_sign");
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) SignBlockEntity(net.minecraft.block.entity.SignBlockEntity) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) Text(net.minecraft.text.Text) BlockHitResult(net.minecraft.util.hit.BlockHitResult) AbstractSignBlock(net.minecraft.block.AbstractSignBlock) BlockEntity(net.minecraft.block.entity.BlockEntity) SignBlockEntity(net.minecraft.block.entity.SignBlockEntity)

Example 30 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project tweakermore by Fallen-Breath.

the class PlacementTweaksMixin method tweakmAutoPickSchematicBlock.

@Inject(method = "tryPlaceBlock", at = @At("HEAD"), remap = false)
private static void tweakmAutoPickSchematicBlock(ClientPlayerInteractionManager controller, ClientPlayerEntity player, ClientWorld world, BlockPos posIn, Direction sideIn, Direction sideRotatedIn, float playerYaw, Vec3d hitVec, Hand hand, PositionUtils.HitPart hitPart, boolean isFirstClick, CallbackInfoReturnable<ActionResult> cir) {
    MinecraftClient mc = MinecraftClient.getInstance();
    if (mc.player != null) {
        if (DataManager.getToolMode() != ToolMode.REBUILD && !Configs.Generic.EASY_PLACE_MODE.getBooleanValue()) {
            if (TweakerMoreConfigs.TWEAKM_AUTO_PICK_SCHEMATIC_BLOCK.getBooleanValue() && EntityUtils.shouldPickBlock(mc.player)) {
                BlockHitResult hitResult = new BlockHitResult(hitVec, sideIn, posIn, false);
                ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hitResult));
                doSchematicWorldPickBlock(mc, ctx.getBlockPos(), hand);
            }
        }
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) ItemUsageContext(net.minecraft.item.ItemUsageContext) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

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