Search in sources :

Example 11 with HitResult

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

the class ClickTP method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    if (mc.player.isUsingItem())
        return;
    if (mc.options.useKey.isPressed()) {
        HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);
        if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS)
            return;
        if (hitResult.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
            Direction side = ((BlockHitResult) hitResult).getSide();
            if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS)
                return;
            BlockState state = mc.world.getBlockState(pos);
            VoxelShape shape = state.getCollisionShape(mc.world, pos);
            if (shape.isEmpty())
                shape = state.getOutlineShape(mc.world, pos);
            double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y);
            mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ());
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.shape.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) EventHandler(meteordevelopment.orbit.EventHandler)

Example 12 with HitResult

use of net.minecraft.util.hit.HitResult in project MasaGadget by plusls.

the class MixinWorldRenderer method postRender.

@Inject(method = "render", at = @At(value = "RETURN"))
private void postRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
    MinecraftClient mc = MinecraftClient.getInstance();
    World world = WorldUtils.getBestWorld(mc);
    if (world == null || mc.player == null) {
        return;
    }
    Entity cameraEntity = world.getPlayerByUuid(mc.player.getUuid());
    if (cameraEntity == null) {
        cameraEntity = mc.player;
    }
    if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) {
        cameraEntity = mc.getCameraEntity();
    }
    if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || !Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_COMPARATOR.getBooleanValue() || cameraEntity == null) {
        return;
    }
    MatrixStack matrixStack = RenderSystem.getModelViewStack();
    matrixStack.push();
    matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix());
    RenderSystem.applyModelViewMatrix();
    // 开始渲染
    HitResult trace = RayTraceUtils.getRayTraceFromEntity(world, cameraEntity, false);
    if (trace.getType() == HitResult.Type.BLOCK) {
        BlockPos pos = ((BlockHitResult) trace).getBlockPos();
        // 绕过线程检查
        BlockEntity blockEntity = world.getWorldChunk(pos).getBlockEntity(pos);
        if (blockEntity instanceof ComparatorBlockEntity) {
            LiteralText literalText = new LiteralText(((ComparatorBlockEntity) blockEntity).getOutputSignal() + "");
            literalText.formatted(Formatting.GREEN);
            // literalText.formatted(Formatting.);
            VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
            // 不加 1.17 渲染会有问题
            RenderSystem.disableDepthTest();
            matrixStack.push();
            matrixStack.translate(pos.getX() + 0.5 - camera.getPos().getX(), pos.getY() + 0.6 - camera.getPos().getY(), pos.getZ() + 0.5 - camera.getPos().getZ());
            matrixStack.multiplyPositionMatrix(new Matrix4f(camera.getRotation()));
            matrixStack.scale(-0.04F, -0.04F, -0.04F);
            RenderSystem.applyModelViewMatrix();
            Matrix4f lv = AffineTransformation.identity().getMatrix();
            float xOffset = (float) (-mc.textRenderer.getWidth(literalText) / 2);
            float g = mc.options.getTextBackgroundOpacity(0.25F);
            int k = (int) (g * 255.0F) << 24;
            mc.textRenderer.draw(literalText, xOffset, 0, 553648127, false, lv, immediate, true, k, 0xf00000);
            immediate.draw();
            mc.textRenderer.draw(literalText, xOffset, 0, -1, false, lv, immediate, true, 0, 0xf00000);
            immediate.draw();
            matrixStack.pop();
            RenderSystem.applyModelViewMatrix();
            RenderSystem.enableDepthTest();
        }
    }
    // 结束渲染
    matrixStack.pop();
    RenderSystem.applyModelViewMatrix();
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) Entity(net.minecraft.entity.Entity) MatrixStack(net.minecraft.client.util.math.MatrixStack) World(net.minecraft.world.World) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) BlockEntity(net.minecraft.block.entity.BlockEntity) ComparatorBlockEntity(net.minecraft.block.entity.ComparatorBlockEntity) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 13 with HitResult

use of net.minecraft.util.hit.HitResult in project Biome-Makeover by Lemonszz.

the class BMBoatItem method use.

public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    ItemStack itemStack = user.getStackInHand(hand);
    HitResult hitResult = Item.raycast(world, user, RaycastContext.FluidHandling.ANY);
    if (hitResult.getType() == HitResult.Type.MISS) {
        return TypedActionResult.pass(itemStack);
    } else {
        Vec3d vec3d = user.getRotationVec(1.0F);
        List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), EntityPredicates.EXCEPT_SPECTATOR.and(Entity::collides));
        if (!list.isEmpty()) {
            Vec3d cameraPosVec = user.getCameraPosVec(1.0F);
            for (Entity entity : list) {
                Box box = entity.getBoundingBox().expand(entity.getTargetingMargin());
                if (box.contains(cameraPosVec)) {
                    return TypedActionResult.pass(itemStack);
                }
            }
        }
        if (hitResult.getType() == HitResult.Type.BLOCK) {
            BMBoatEntity boatEntity = createBoat(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z, user.yaw);
            if (!world.isSpaceEmpty(boatEntity, boatEntity.getBoundingBox().expand(-0.1D))) {
                return TypedActionResult.fail(itemStack);
            } else {
                if (!world.isClient) {
                    world.spawnEntity(boatEntity);
                    if (!user.abilities.creativeMode) {
                        itemStack.decrement(1);
                    }
                }
                user.incrementStat(Stats.USED.getOrCreateStat(this));
                return TypedActionResult.success(itemStack);
            }
        } else {
            return TypedActionResult.pass(itemStack);
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BMBoatEntity(party.lemons.biomemakeover.entity.BMBoatEntity) BMBoatEntity(party.lemons.biomemakeover.entity.BMBoatEntity) Box(net.minecraft.util.math.Box) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 14 with HitResult

use of net.minecraft.util.hit.HitResult in project Hypnotic-Client by Hypnotic-Development.

the class MiddleClickFriend method mouseClicked.

@EventTarget
public void mouseClicked(EventMouseButton event) {
    if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_MIDDLE && event.getClickType() == EventMouseButton.ClickType.IN_GAME) {
        HitResult hitResult = mc.crosshairTarget;
        if (hitResult != null && hitResult.getType() == HitResult.Type.ENTITY) {
            PlayerEntity player = (PlayerEntity) ((EntityHitResult) hitResult).getEntity();
            if (!FriendManager.INSTANCE.isFriend(player) && !mc.options.sneakKey.isPressed()) {
                FriendManager.INSTANCE.add(new Friend(player.getName().asString()));
                ChatUtils.tellPlayer("Added " + ColorUtils.green + player.getName().asString() + ColorUtils.white + " to your friends list");
            }
            if (mc.options.sneakKey.isPressed() && FriendManager.INSTANCE.isFriend(player)) {
                for (Friend friend : FriendManager.INSTANCE.friends) {
                    if (friend.name == player.getName().asString()) {
                        FriendManager.INSTANCE.friends.remove(friend);
                        ChatUtils.tellPlayer("Removed " + ColorUtils.red + friend.name + ColorUtils.white + " from your friends list");
                    }
                }
            }
        }
    }
}
Also used : HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) Friend(dev.hypnotic.config.friends.Friend) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EventTarget(dev.hypnotic.event.EventTarget)

Example 15 with HitResult

use of net.minecraft.util.hit.HitResult in project Hypnotic-Client by Hypnotic-Development.

the class BlockOutline method render3d.

@EventTarget
public void render3d(EventRender3D event) {
    HitResult target = mc.crosshairTarget;
    if (target != null) {
        if (target.getType() == Type.BLOCK) {
            BlockPos pos = (BlockPos) ((BlockHitResult) target).getBlockPos();
            float[] c = color.getRGBFloat();
            switch(mode.getSelected()) {
                case "Box":
                    RenderUtils.drawBoxOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue());
                    break;
                case "Box-Fill":
                    RenderUtils.drawBoxOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue());
                    RenderUtils.drawBoxFill(pos, QuadColor.single(c[0], c[1], c[2], 0.4f));
                    break;
                case "Face":
                    RenderUtils.drawFaceOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue(), (Direction) ((BlockHitResult) target).getSide());
                    break;
                case "Face-Fill":
                    RenderUtils.drawFaceFill(pos, QuadColor.single(c[0], c[1], c[2], 0.4f), (Direction) ((BlockHitResult) target).getSide());
                    RenderUtils.drawFaceOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue(), (Direction) ((BlockHitResult) target).getSide());
                    break;
            }
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) EventTarget(dev.hypnotic.event.EventTarget)

Aggregations

HitResult (net.minecraft.util.hit.HitResult)15 BlockPos (net.minecraft.util.math.BlockPos)10 BlockHitResult (net.minecraft.util.hit.BlockHitResult)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 ItemStack (net.minecraft.item.ItemStack)5 EntityHitResult (net.minecraft.util.hit.EntityHitResult)5 Entity (net.minecraft.entity.Entity)4 Vec3d (net.minecraft.util.math.Vec3d)4 BlockState (net.minecraft.block.BlockState)3 MinecraftClient (net.minecraft.client.MinecraftClient)3 Box (net.minecraft.util.math.Box)3 EventTarget (dev.hypnotic.event.EventTarget)2 Iterator (java.util.Iterator)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 LiteralText (net.minecraft.text.LiteralText)2 Direction (net.minecraft.util.math.Direction)2 VoxelShape (net.minecraft.util.shape.VoxelShape)2 World (net.minecraft.world.World)2 IOffhandAttack (chronosacaria.mcdw.api.interfaces.IOffhandAttack)1 DataFixUtils (com.mojang.datafixers.DataFixUtils)1