Crosshair module

Crosshair: Minecraft 26.3 cheat module, full source for every implementation (3 clients: Combatant, Nicotine, LiquidBounce (Kotlin)).

3 implementationsVISUALSRenderRENDER

Full module source: 3 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/Crosshair.javaJava · 903 lines · 37.1 KB
SettingscrosshairTypecrosshairOrbizMotioncrosshairOutlinecrosshairDynamicGapcrosshairHighlightTargetcrosshairThicknesscrosshairLengthcrosshairBaseGapcrosshairMaxGapIncreasecrosshairOrbizRadiuscrosshairOrbizThicknesscrosshairOrbizSoftnesscrosshairOrbizGlowcrosshairOrbizGlowStrengthcrosshairOrbizCooldownMultipliercrosshairOrbizTrackAlphacrosshairOrbizBodyAlphacrosshairOrbizHeadBoostcrosshairOrbizAngularCyclescrosshairOrbizColorModecrosshairOrbizColorSpeedcrosshairOrbizColorcrosshairOrbizColor2crosshairOrbizCenterAnchorcrosshairOrbizLookMultipliercrosshairOrbizMoveMultipliercrosshairOrbizMotionLimitcrosshairOrbizMotionSmoothingcrosshairVulcanReachDisplaycrosshairVulcanReachLookMscrosshairVulcanReachAttackMs
Crosshair.javaJava · Minecraft 26.2 · 903 lines · 37.1 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.visuals;
9
10
import combatant.client.render.engine.text.BuiltinFontCatalog;
11
import combatant.client.features.module.*;
12
import combatant.client.features.module.Module;
13
import combatant.client.render.engine.core.ViewportContext;
14
import combatant.client.util.item.FoodUtil;
15
import net.minecraft.client.Minecraft;
16
import net.minecraft.client.gui.GuiGraphicsExtractor;
17
import net.minecraft.core.BlockPos;
18
import net.minecraft.core.component.DataComponents;
19
import net.minecraft.core.registries.BuiltInRegistries;
20
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
21
import net.minecraft.util.Mth;
22
import net.minecraft.world.entity.Entity;
23
import net.minecraft.world.entity.EquipmentSlot;
24
import net.minecraft.world.entity.MobCategory;
25
import net.minecraft.world.entity.ai.attributes.Attributes;
26
import net.minecraft.world.entity.player.Player;
27
import net.minecraft.world.item.*;
28
import net.minecraft.world.item.enchantment.Enchantments;
29
import net.minecraft.world.item.enchantment.ItemEnchantments;
30
import net.minecraft.world.item.equipment.Equippable;
31
import net.minecraft.world.level.Level;
32
import net.minecraft.world.phys.EntityHitResult;
33
import net.minecraft.world.phys.HitResult;
34
import combatant.client.config.values.BooleanValue;
35
import combatant.client.config.values.EnumValue;
36
import combatant.client.config.values.NumberValue;
37
import combatant.client.config.values.RGBAColorValue;
38
import combatant.client.config.common.CommonSettingSchemas;
39
import combatant.client.events.EventHandler;
40
import combatant.client.events.impl.AttackEntityEvent;
41
import combatant.client.events.impl.PacketEvent;
42
import combatant.client.features.gui.hud.HudRenderUtil;
43
import combatant.client.features.gui.hud.draggable.impl.Itemizer;
44
import combatant.client.features.module.*;
45
import combatant.client.features.module.modules.combat.KillAura;
46
import combatant.client.features.module.modules.combat.Reach;
47
import combatant.client.features.relations.CategoryService;
48
import combatant.client.features.relations.EntityFilters;
49
import combatant.client.features.relations.PlayerRelations;
50
import combatant.client.mixininterface.IPlayerAttackCooldown;
51
import combatant.client.render.engine.animation.AnimatedRenderColors;
52
import combatant.client.render.engine.animation.AnimationUtility;
53
import combatant.client.render.engine.color.RenderColor;
54
import combatant.client.render.engine.math.ColorMath;
55
import combatant.client.render.engine.renderer.Renderer2D;
56
import combatant.client.render.engine.text.TextRenderer;
57
import combatant.client.util.combat.VulcanReachController;
58
59
import java.util.List;
60
import java.util.Locale;
61
62
//todo Description
63
@ModuleInfo(
64
        id = "crosshair",
65
        displayName = "Crosshair",
66
        category = ModuleCategory.VISUALS
67
)
68
public class Crosshair extends Module {
69
70
    private static final int DEFAULT_COLOR = 0xFFFFFFFF;
71
    private static final int OUTLINE_COLOR = 0xFF000000;
72
    private static final int RIPTIDE_BLOCK_COLOR = 0xFFFF3B3B;
73
    private static final float OUTLINE_EXPAND = 0.5f;
74
    private static final float GAP_SMOOTHING = 0.15f;
75
    private static final float COLOR_SMOOTH_SPEED = 14.0f;
76
    private static final float ORBIZ_PROGRESS_SMOOTH_SPEED = 22.0f;
77
    private static final float ORBIZ_PROGRESS_RESET_SMOOTH_SPEED = 30.0f;
78
    private static final float COOLDOWN_LEAD = 0.06f;
79
    private static final float RIPTIDE_CROSS_LENGTH_FACTOR = 0.65f;
80
    private static final float VULCAN_REACH_FONT_SIZE = 14.0f;
81
    private static final int VULCAN_REACH_PRIMARY = 0xF2FFFFFF;
82
    private static final int VULCAN_REACH_SECONDARY = 0xD8D7DEE8;
83
    private final Minecraft mc = Minecraft.getInstance();
84
    private final EnumValue<CrosshairType> crosshairType =
85
            enumSetting("crosshairType", "type", CrosshairType.CLASSIC);
86
    private final EnumValue<OrbizMotionMode> orbizMotion =
87
            visibleWhen(enumSetting("crosshairOrbizMotion", "orbiz_motion", OrbizMotionMode.DYNAMIC), this::isOrbiz);
88
    private final BooleanValue showOutline = visibleWhen(
89
            bool("crosshairOutline", "outline", true),
90
            this::isClassicCrosshair
91
    );
92
    private final BooleanValue dynamicGap = visibleWhen(
93
            bool("crosshairDynamicGap", "dynamic_gap", true),
94
            this::isClassicCrosshair
95
    );
96
    private final BooleanValue highlightTarget = bool("crosshairHighlightTarget", "highlight_target", true);
97
    private final NumberValue<Double> thickness = visibleWhen(
98
            num("crosshairThickness", "thickness", 0.5, 0.5, 1.0),
99
            this::isClassicCrosshair
100
    );
101
    private final NumberValue<Double> length = visibleWhen(
102
            num("crosshairLength", "length", 3.0, 1.0, 10.0),
103
            this::isClassicCrosshair
104
    );
105
    private final NumberValue<Double> baseGap = visibleWhen(
106
            num("crosshairBaseGap", "base_gap", 4.0, 0.0, 10.0),
107
            this::isClassicCrosshair
108
    );
109
    private final NumberValue<Double> maxGapIncrease = visibleWhen(
110
            num("crosshairMaxGapIncrease", "max_gap_increase", 7.0, 0.0, 15.0),
111
            () -> isClassicCrosshair() && dynamicGap.get()
112
    );
113
    private final NumberValue<Double> orbizRadius = visibleWhen(
114
            num("crosshairOrbizRadius", "orbiz_radius", 5.0, 2.0, 5.0),
115
            this::isOrbiz
116
    );
117
    private final NumberValue<Double> orbizThickness = visibleWhen(
118
            num("crosshairOrbizThickness", "orbiz_thickness", 1.35, 0.5, 5.0),
119
            this::isOrbiz
120
    );
121
    private final NumberValue<Double> orbizSoftness = visibleWhen(
122
            num("crosshairOrbizSoftness", "orbiz_softness", 0.35, 0.0, 2.0),
123
            this::isOrbiz
124
    );
125
    private final NumberValue<Double> orbizGlow = visibleWhen(
126
            num("crosshairOrbizGlow", "orbiz_glow", 5.5, 0.0, 20.0),
127
            this::isOrbiz
128
    );
129
    private final NumberValue<Double> orbizGlowStrength = visibleWhen(
130
            num("crosshairOrbizGlowStrength", "orbiz_glow_strength", 0.72, 0.0, 2.0),
131
            this::isOrbiz
132
    );
133
    private final NumberValue<Double> orbizCooldownMultiplier = visibleWhen(
134
            num("crosshairOrbizCooldownMultiplier", "orbiz_cooldown_multiplier", 1.0, 0.1, 1.5),
135
            this::isOrbiz
136
    );
137
    private final NumberValue<Double> orbizTrackAlpha = visibleWhen(
138
            num("crosshairOrbizTrackAlpha", "orbiz_track_alpha", 0.24, 0.0, 1.0),
139
            this::isOrbiz
140
    );
141
    private final NumberValue<Double> orbizBodyAlpha = visibleWhen(
142
            num("crosshairOrbizBodyAlpha", "orbiz_body_alpha", 0.92, 0.0, 1.0),
143
            this::isOrbiz
144
    );
145
    private final NumberValue<Double> orbizHeadBoost = visibleWhen(
146
            num("crosshairOrbizHeadBoost", "orbiz_head_boost", 0.30, 0.0, 1.0),
147
            this::isOrbiz
148
    );
149
    private final NumberValue<Double> orbizAngularCycles = visibleWhen(
150
            num("crosshairOrbizAngularCycles", "orbiz_angular_cycles", 1.0, 0.25, 4.0),
151
            this::isOrbiz
152
    );
153
    private final EnumValue<AnimatedRenderColors.Mode> orbizColorMode = visibleWhen(
154
            common(enumSetting(
155
                    "crosshairOrbizColorMode",
156
                    "orbiz_color_mode",
157
                    AnimatedRenderColors.Mode.RAINBOW,
158
                    AnimatedRenderColors.Mode.STATIC,
159
                    AnimatedRenderColors.Mode.RAINBOW,
160
                    AnimatedRenderColors.Mode.LIGHT_RAINBOW,
161
                    AnimatedRenderColors.Mode.SKY,
162
                    AnimatedRenderColors.Mode.FADE,
163
                    AnimatedRenderColors.Mode.DOUBLE_COLOR,
164
                    AnimatedRenderColors.Mode.ANALOGOUS,
165
                    AnimatedRenderColors.Mode.THEME
166
            ), CommonSettingSchemas.RENDER_COLOR_MODE.commonI18nKey()),
167
            this::isOrbiz
168
    );
169
    private final NumberValue<Integer> orbizColorSpeed = visibleWhen(
170
            common(num("crosshairOrbizColorSpeed", "orbiz_color_speed", 18, 2, 54),
171
                    CommonSettingSchemas.RENDER_COLOR_SPEED.commonI18nKey()),
172
            () -> isOrbiz() && AnimatedRenderColors.animated(orbizColorMode.get())
173
    );
174
    private final RGBAColorValue orbizColor = visibleWhen(
175
            common(color("crosshairOrbizColor", "orbiz_color", "#EEFFFFFF"),
176
                    CommonSettingSchemas.RENDER_PRIMARY_COLOR.commonI18nKey()),
177
            this::isOrbiz
178
    );
179
    private final RGBAColorValue orbizColor2 = visibleWhen(
180
            common(color("crosshairOrbizColor2", "orbiz_color2", "#EE55FFFF"),
181
                    CommonSettingSchemas.RENDER_SECONDARY_COLOR.commonI18nKey()),
182
            () -> isOrbiz() && AnimatedRenderColors.usesSecondary(orbizColorMode.get())
183
    );
184
    private final BooleanValue orbizCenterAnchor = visibleWhen(
185
            bool("crosshairOrbizCenterAnchor", "orbiz_center_anchor", true),
186
            this::isOrbiz
187
    );
188
    private final NumberValue<Double> orbizLookMultiplier = visibleWhen(
189
            num("crosshairOrbizLookMultiplier", "orbiz_look_multiplier", 0.45, 0.0, 2.5),
190
            () -> isOrbiz() && isOrbizMotionDynamic()
191
    );
192
    private final NumberValue<Double> orbizMoveMultiplier = visibleWhen(
193
            num("crosshairOrbizMoveMultiplier", "orbiz_move_multiplier", 2.0, 0.0, 10.0),
194
            () -> isOrbiz() && isOrbizMotionDynamic()
195
    );
196
    private final NumberValue<Double> orbizMotionLimit = visibleWhen(
197
            num("crosshairOrbizMotionLimit", "orbiz_motion_limit", 8.0, 0.0, 24.0),
198
            () -> isOrbiz() && isOrbizMotionDynamic()
199
    );
200
    private final NumberValue<Double> orbizMotionSmoothing = visibleWhen(
201
            num("crosshairOrbizMotionSmoothing", "orbiz_motion_smoothing", 12.0, 1.0, 30.0),
202
            () -> isOrbiz() && isOrbizMotionDynamic()
203
    );
204
    private final EnumValue<VulcanReachDisplay> vulcanReachDisplay =
205
            enumSetting("crosshairVulcanReachDisplay", "vulcan_reach_display",
206
                    VulcanReachDisplay.TIMED, VulcanReachDisplay.values());
207
    private final NumberValue<Integer> vulcanReachLookMs =
208
            visibleWhen(num("crosshairVulcanReachLookMs", "vulcan_reach_look_ms", 1200, 0, 3000),
209
                    () -> vulcanReachDisplay.get() == VulcanReachDisplay.TIMED);
210
    private final NumberValue<Integer> vulcanReachAttackMs =
211
            visibleWhen(num("crosshairVulcanReachAttackMs", "vulcan_reach_attack_ms", 2500, 0, 6000),
212
                    () -> vulcanReachDisplay.get() == VulcanReachDisplay.TIMED);
213
    private float animatedGap;
214
    private int animatedColor = DEFAULT_COLOR;
215
    private float animatedOrbizProgress = 1.0f;
216
    private boolean orbizProgressInitialized;
217
    private float orbizOffsetX;
218
    private float orbizOffsetY;
219
    private float lastOrbizYaw;
220
    private float lastOrbizPitch;
221
    private boolean orbizMotionInitialized;
222
    private boolean colorInitialized;
223
    private boolean chestInit;
224
    private boolean lastSwapCandidate;
225
    private boolean lastChestWasElytra;
226
    private ItemStack lastChestStack = ItemStack.EMPTY;
227
    private long lastVulcanReachLookMs;
228
    private long lastVulcanReachAttackMs;
229
    private Player lastVulcanReachTarget;
230
231
    private static int colorDistance(int a, int b) {
232
        int dr = Math.abs(((a >>> 16) & 0xFF) - ((b >>> 16) & 0xFF));
233
        int dg = Math.abs(((a >>> 8) & 0xFF) - ((b >>> 8) & 0xFF));
234
        int db = Math.abs((a & 0xFF) - (b & 0xFF));
235
        int da = Math.abs(((a >>> 24) & 0xFF) - ((b >>> 24) & 0xFF));
236
        return dr + dg + db + da;
237
    }
238
239
    public static boolean isRiptideBlocked(Player player, ItemStack stack) {
240
        if (player == null || stack == null || stack.isEmpty()) return false;
241
        if (!stack.is(Items.TRIDENT)) return false;
242
        if (!hasRiptide(stack)) return false;
243
        return !isTouchingWaterOrServerRain(player);
244
    }
245
246
    private static boolean hasRiptide(ItemStack stack) {
247
        ItemEnchantments ench = stack.getOrDefault(
248
                DataComponents.ENCHANTMENTS,
249
                ItemEnchantments.EMPTY
250
        );
251
        return ench.keySet().stream().anyMatch(entry -> {
252
            var keyOpt = entry.unwrapKey();
253
            return keyOpt.isPresent() && keyOpt.get().identifier().equals(Enchantments.RIPTIDE.identifier());
254
        });
255
    }
256
257
    private static boolean isTouchingWaterOrServerRain(Player player) {
258
        if (player == null) return false;
259
        if (player.isInWater()) return true;
260
        Level world = player.level();
261
        BlockPos pos = player.blockPosition();
262
        if (WorldTweaks.hasServerRainAt(world, pos)) return true;
263
        BlockPos top = BlockPos.containing(pos.getX(), player.getBoundingBox().maxY, pos.getZ());
264
        return WorldTweaks.hasServerRainAt(world, top);
265
    }
266
267
    @Override
268
    public HudPhase getHudPhase() {
269
        return HudPhase.LAST;
270
    }
271
272
    public boolean shouldHideVanilla() {
273
        return isEnabled()
274
                && mc.player != null
275
                && mc.level != null
276
                && mc.options.getCameraType().isFirstPerson();
277
    }
278
279
    @Override
280
    public void onEnable() {
281
        resetSwapDetector();
282
        resetOrbizState();
283
        colorInitialized = false;
284
    }
285
286
    @Override
287
    public void onDisable() {
288
        resetSwapDetector();
289
        resetOrbizState();
290
        Itemizer.hideElytraSwap();
291
    }
292
293
    @Override
294
    public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, GuiGraphicsExtractor ctx, float tickDelta) {
295
        if (!isEnabled() || mc.player == null || mc.level == null) return;
296
        if (!mc.options.getCameraType().isFirstPerson()) return;
297
298
        float scale = ViewportContext.getScaleFactor();
299
        float centerX = mc.getWindow().getWidth() * 0.5f;
300
        float centerY = mc.getWindow().getHeight() * 0.5f;
301
302
        float thicknessPx = (float) (thickness.get() * scale);
303
        float lengthPx = (float) (length.get() * scale);
304
        float outlinePx = OUTLINE_EXPAND * scale;
305
306
        float cooldown = 0.0f;
307
        if (dynamicGap.get()) {
308
            float charge = getChargeProgress(mc.player);
309
            if (charge >= 0.0f) {
310
                cooldown = 1.0f - charge;
311
            } else {
312
                float progress = getAttackCooldownProgress();
313
                progress = Mth.clamp(progress + COOLDOWN_LEAD, 0.0f, 1.0f);
314
                cooldown = 1.0f - progress;
315
            }
316
        }
317
318
        float targetGap = (float) (baseGap.get() + maxGapIncrease.get() * cooldown);
319
        animatedGap += (targetGap - animatedGap) * GAP_SMOOTHING;
320
        float gapPx = animatedGap * scale;
321
322
        updateSwapDetector(mc.player);
323
324
        if (crosshairType.get() == CrosshairType.ORBIZ) {
325
            renderOrbiz(renderer, centerX, centerY, scale);
326
            float infoGapPx = (float) (orbizRadius.get() * scale);
327
            float infoLengthPx = (float) ((orbizGlow.get() + orbizThickness.get()) * scale);
328
            renderVulcanReachInfo(textRenderer, centerX, centerY, infoGapPx, infoLengthPx);
329
            return;
330
        }
331
332
        boolean outline = showOutline.get();
333
        if (shouldShowRiptideBlocked(mc.player) || shouldShowCooldownCross(mc.player)) {
334
            int dangerColor = smoothCrosshairColor(RIPTIDE_BLOCK_COLOR);
335
            renderRiptideBlockedCross(renderer, centerX, centerY, thicknessPx, lengthPx, outline, outlinePx, dangerColor);
336
            return;
337
        }
338
339
        int color = smoothCrosshairColor(resolveCrosshairTargetColor());
340
        boolean tClassic = crosshairType.get() == CrosshairType.T_CLASSIC;
341
342
        if (tClassic) {
343
            double barX = centerX - lengthPx;
344
            double barY = centerY - thicknessPx * 0.5f;
345
            double barW = lengthPx * 2.0f;
346
            double stemX = centerX - thicknessPx * 0.5f;
347
            double stemH = lengthPx + gapPx;
348
            drawSegment(renderer, barX, barY, barW, thicknessPx, color, outline, outlinePx);
349
            drawSegment(renderer, stemX, centerY, thicknessPx, stemH, color, outline, outlinePx);
350
            renderVulcanReachInfo(textRenderer, centerX, centerY, gapPx, lengthPx);
351
            return;
352
        }
353
354
        double topX = centerX - thicknessPx * 0.5f;
355
        double topY = centerY - gapPx - lengthPx;
356
        double bottomX = centerX - thicknessPx * 0.5f;
357
        double bottomY = centerY + gapPx;
358
        double leftX = centerX - gapPx - lengthPx;
359
        double leftY = centerY - thicknessPx * 0.5f;
360
        double rightX = centerX + gapPx;
361
        double rightY = centerY - thicknessPx * 0.5f;
362
363
        drawSegment(renderer, topX, topY, thicknessPx, lengthPx, color, outline, outlinePx);
364
        drawSegment(renderer, bottomX, bottomY, thicknessPx, lengthPx, color, outline, outlinePx);
365
        drawSegment(renderer, leftX, leftY, lengthPx, thicknessPx, color, outline, outlinePx);
366
        drawSegment(renderer, rightX, rightY, lengthPx, thicknessPx, color, outline, outlinePx);
367
        renderVulcanReachInfo(textRenderer, centerX, centerY, gapPx, lengthPx);
368
    }
369
370
    @EventHandler
371
    private void onAttackEntity(AttackEntityEvent event) {
372
        if (!isVulcanReachActive()) {
373
            return;
374
        }
375
        if (event.getPlayer() != mc.player || !(event.getTarget() instanceof Player player)) {
376
            return;
377
        }
378
        lastVulcanReachAttackMs = System.currentTimeMillis();
379
        lastVulcanReachTarget = player;
380
    }
381
382
    @EventHandler
383
    private void onPacketSendPost(PacketEvent.SendPost event) {
384
        if (!isVulcanReachActive() || mc.level == null) {
385
            return;
386
        }
387
        if (!(event.getPacket() instanceof ServerboundInteractPacket packet) || !isAttackPacket(packet)) {
388
            return;
389
        }
390
391
        Entity target = mc.level.getEntity(packet.entityId());
392
        if (target instanceof Player player) {
393
            lastVulcanReachAttackMs = System.currentTimeMillis();
394
            lastVulcanReachTarget = player;
395
        }
396
    }
397
398
    private float getAttackCooldownProgress() {
399
        if (mc.player instanceof IPlayerAttackCooldown cooldown) {
400
            return cooldown.combatant$getAttackCooldownProgress(0.0f);
401
        }
402
        return mc.player.getAttackStrengthScale(0.0f);
403
    }
404
405
    private float getChargeProgress(Player player) {
406
        if (player == null || !player.isUsingItem()) return -1.0f;
407
        ItemStack stack = player.getUseItem();
408
        if (stack == null || stack.isEmpty()) return -1.0f;
409
410
        int useTicks = player.getTicksUsingItem();
411
        Item item = stack.getItem();
412
413
        if (item instanceof BowItem) {
414
            return Mth.clamp(BowItem.getPowerForTime(useTicks), 0.0f, 1.0f);
415
        }
416
        if (item instanceof CrossbowItem) {
417
            int pullTime = CrossbowItem.getChargeDuration(stack, player);
418
            if (pullTime <= 0) return 1.0f;
419
            return Mth.clamp(useTicks / (float) pullTime, 0.0f, 1.0f);
420
        }
421
        if (stack.is(Items.TRIDENT)) {
422
            return Mth.clamp(useTicks / 10.0f, 0.0f, 1.0f);
423
        }
424
425
        return -1.0f;
426
    }
427
428
    private void renderOrbiz(Renderer2D renderer, float centerX, float centerY, float scale) {
429
        boolean danger = shouldShowRiptideBlocked(mc.player) || shouldShowCooldownCross(mc.player);
430
        float progress = danger ? 1.0f : resolveOrbizProgress();
431
        float targetProgress = Mth.clamp(progress * orbizCooldownMultiplier.get().floatValue(), 0.0f, 1.0f);
432
        if (!orbizProgressInitialized) {
433
            animatedOrbizProgress = targetProgress;
434
            orbizProgressInitialized = true;
435
        } else {
436
            float progressSpeed = targetProgress < animatedOrbizProgress
437
                    ? ORBIZ_PROGRESS_RESET_SMOOTH_SPEED
438
                    : ORBIZ_PROGRESS_SMOOTH_SPEED;
439
            float progressT = exponentialSmoothing(progressSpeed);
440
            animatedOrbizProgress = AnimationUtility.lerp(animatedOrbizProgress, targetProgress, progressT);
441
            if (Math.abs(animatedOrbizProgress - targetProgress) <= 0.001f) {
442
                animatedOrbizProgress = targetProgress;
443
            }
444
        }
445
446
        updateOrbizMotion();
447
448
        AnimatedRenderColors.Mode mode = danger ? AnimatedRenderColors.Mode.STATIC : orbizColorMode.get();
449
        int configured = orbizColor.getArgb();
450
        int targetAware = highlightTarget.get()
451
                ? colorWithConfigAlpha(smoothCrosshairColor(resolveCrosshairTargetColor()), configured)
452
                : configured;
453
        int primary = danger
454
                ? colorWithConfigAlpha(RIPTIDE_BLOCK_COLOR, configured)
455
                : mode == AnimatedRenderColors.Mode.STATIC ? targetAware : configured;
456
        int secondary;
457
        if (danger) {
458
            secondary = primary;
459
        } else if (mode == AnimatedRenderColors.Mode.THEME) {
460
            HudRenderUtil.ThemeGradient themeGradient = HudRenderUtil.themeAccentGradient((configured >>> 24) & 0xFF);
461
            primary = themeGradient.start();
462
            secondary = themeGradient.end();
463
        } else {
464
            secondary = AnimatedRenderColors.angularSecondaryColor(mode, primary, orbizColor2.getArgb());
465
            primary = AnimatedRenderColors.angularPrimaryColor(mode, primary);
466
        }
467
        int anchorColor = resolveOrbizAnchorColor(mode, danger, targetAware, primary, secondary);
468
469
        float radiusPx = (float) (orbizRadius.get() * scale);
470
        float thicknessPx = (float) (orbizThickness.get() * scale);
471
        float softnessPx = (float) (orbizSoftness.get() * scale);
472
        float glowPx = (float) (orbizGlow.get() * scale);
473
        float sweep = animatedOrbizProgress * 360.0f;
474
        float trackGlow = glowPx > 0.0f ? 1.0f : 0.0f;
475
476
        renderer.orbizRing(
477
                centerX + orbizOffsetX * scale,
478
                centerY + orbizOffsetY * scale,
479
                radiusPx,
480
                thicknessPx,
481
                0.0f,
482
                sweep,
483
                softnessPx,
484
                glowPx,
485
                orbizGlowStrength.get().floatValue(),
486
                primary,
487
                secondary,
488
                AnimatedRenderColors.shaderMode(mode),
489
                AnimatedRenderColors.angularOffset01(mode, orbizColorSpeed.get()),
490
                orbizAngularCycles.get().floatValue(),
491
                orbizTrackAlpha.get().floatValue(),
492
                orbizBodyAlpha.get().floatValue(),
493
                orbizHeadBoost.get().floatValue(),
494
                trackGlow,
495
                true
496
        );
497
498
        if (orbizCenterAnchor.get()) {
499
            // Dynamic ring motion communicates movement without moving the actual aim reference.
500
            // The anchor stays at the true screen center and follows the selected color animation.
501
            float anchorRadius = Math.max(0.70f * scale, Math.min(1.15f * scale, thicknessPx * 0.42f));
502
            float anchorSoftness = Math.max(0.20f * scale, softnessPx * 0.45f);
503
            renderer.circle(centerX, centerY, anchorRadius, anchorSoftness, anchorColor);
504
        }
505
    }
506
507
    private int resolveOrbizAnchorColor(AnimatedRenderColors.Mode mode,
508
                                        boolean danger,
509
                                        int targetAware,
510
                                        int primary,
511
                                        int secondary) {
512
        if (danger) return primary;
513
        if (mode == AnimatedRenderColors.Mode.STATIC) return targetAware;
514
515
        int configured = orbizColor.getArgb();
516
        if (mode == AnimatedRenderColors.Mode.THEME) {
517
            float phase = AnimatedRenderColors.angularOffset01(mode, orbizColorSpeed.get());
518
            float triangular = phase < 0.5f ? phase * 2.0f : (1.0f - phase) * 2.0f;
519
            return AnimatedRenderColors.mixArgb(primary, secondary, triangular);
520
        }
521
        return AnimatedRenderColors.resolve(
522
                mode,
523
                orbizColorSpeed.get(),
524
                0,
525
                configured,
526
                orbizColor2.getArgb(),
527
                true
528
        );
529
    }
530
531
    private static float exponentialSmoothing(float speed) {
532
        float dt = Math.max(0.0f, AnimationUtility.deltaTime());
533
        return AnimationUtility.clamp01(1.0f - (float) Math.exp(-Math.max(0.0f, speed) * dt));
534
    }
535
536
    private float resolveOrbizProgress() {
537
        float charge = getChargeProgress(mc.player);
538
        if (charge >= 0.0f) {
539
            return Mth.clamp(charge, 0.0f, 1.0f);
540
        }
541
        return Mth.clamp(getAttackCooldownProgress() + COOLDOWN_LEAD, 0.0f, 1.0f);
542
    }
543
544
    private void updateOrbizMotion() {
545
        if (mc.player == null) {
546
            orbizOffsetX = AnimationUtility.fast(orbizOffsetX, 0.0f, 10.0f);
547
            orbizOffsetY = AnimationUtility.fast(orbizOffsetY, 0.0f, 10.0f);
548
            orbizMotionInitialized = false;
549
            return;
550
        }
551
552
        float yaw = mc.player.getYRot();
553
        float pitch = mc.player.getXRot();
554
        if (!orbizMotionInitialized) {
555
            lastOrbizYaw = yaw;
556
            lastOrbizPitch = pitch;
557
            orbizMotionInitialized = true;
558
        }
559
560
        float targetX = 0.0f;
561
        float targetY = 0.0f;
562
        if (isOrbizMotionDynamic()) {
563
            float look = orbizLookMultiplier.get().floatValue();
564
            float move = orbizMoveMultiplier.get().floatValue();
565
            targetX = Mth.wrapDegrees(lastOrbizYaw - yaw) * look + mc.player.xxa * move;
566
            targetY = (lastOrbizPitch - pitch) * look + mc.player.zza * move;
567
            float limit = orbizMotionLimit.get().floatValue();
568
            targetX = Mth.clamp(targetX, -limit, limit);
569
            targetY = Mth.clamp(targetY, -limit, limit);
570
        }
571
572
        float t = AnimationUtility.clamp01(AnimationUtility.deltaTime() * orbizMotionSmoothing.get().floatValue());
573
        orbizOffsetX = AnimationUtility.lerp(orbizOffsetX, targetX, t);
574
        orbizOffsetY = AnimationUtility.lerp(orbizOffsetY, targetY, t);
575
        lastOrbizYaw = yaw;
576
        lastOrbizPitch = pitch;
577
    }
578
579
    private int colorWithConfigAlpha(int rgbSource, int alphaSource) {
580
        return ColorMath.colorWithAlpha(rgbSource, (alphaSource >>> 24) & 0xFF);
581
    }
582
583
    private boolean isOrbiz() {
584
        return crosshairType.get() == CrosshairType.ORBIZ;
585
    }
586
587
    private boolean isClassicCrosshair() {
588
        return crosshairType.get() != CrosshairType.ORBIZ;
589
    }
590
591
    private boolean isOrbizMotionDynamic() {
592
        return orbizMotion.get() == OrbizMotionMode.DYNAMIC;
593
    }
594
595
    private void resetOrbizState() {
596
        animatedOrbizProgress = 1.0f;
597
        orbizProgressInitialized = false;
598
        orbizOffsetX = 0.0f;
599
        orbizOffsetY = 0.0f;
600
        lastOrbizYaw = 0.0f;
601
        lastOrbizPitch = 0.0f;
602
        orbizMotionInitialized = false;
603
    }
604
605
    private int resolveCrosshairTargetColor() {
606
        if (!highlightTarget.get()) return DEFAULT_COLOR;
607
        HitResult hit = mc.hitResult;
608
        if (!(hit instanceof EntityHitResult ehr)) return DEFAULT_COLOR;
609
        Entity entity = ehr.getEntity();
610
        if (entity == null) return DEFAULT_COLOR;
611
        return resolveEntityColor(entity);
612
    }
613
614
    private void renderVulcanReachInfo(TextRenderer fallback, float centerX, float centerY, float gapPx, float lengthPx) {
615
        if (!isVulcanReachActive()) {
616
            return;
617
        }
618
619
        Player target = resolveVulcanReachTarget();
620
        double requestedReach = resolveVulcanRequestedReach(target);
621
        VulcanReachController.HudSnapshot snapshot = target != null && target.isAlive()
622
                ? VulcanReachController.INSTANCE.hudSnapshot(target, requestedReach)
623
                : vulcanReachDisplay.get() == VulcanReachDisplay.ALWAYS
624
                ? VulcanReachController.INSTANCE.hudSnapshot(requestedReach)
625
                : null;
626
        if (snapshot == null) {
627
            return;
628
        }
629
630
        String reachText = String.format(Locale.ROOT, "%.1f", snapshot.displayReach());
631
        String hitsText = Integer.toString(snapshot.longHitsRemaining());
632
633
        TextRenderer font = BuiltinFontCatalog.MONSTERRAT.renderer(fallback);
634
        float textScale = VULCAN_REACH_FONT_SIZE / 18.0f;
635
        float x = centerX + gapPx + lengthPx + 7.0f;
636
        float y = centerY - VULCAN_REACH_FONT_SIZE * 0.95f;
637
        float lineHeight = VULCAN_REACH_FONT_SIZE * 0.92f;
638
639
        font.begin(textScale, false, false);
640
        font.render(reachText, x, y, new RenderColor(VULCAN_REACH_PRIMARY), true);
641
        font.render(hitsText, x, y + lineHeight, new RenderColor(VULCAN_REACH_SECONDARY), true);
642
        font.end();
643
    }
644
645
    private boolean isVulcanReachActive() {
646
        Reach reach = Modules.get(Reach.class);
647
        if (reach != null && reach.isEnabled() && reach.isVulcan297Mode()) {
648
            return true;
649
        }
650
651
        KillAura killAura = Modules.get(KillAura.class);
652
        return killAura != null && killAura.isEnabled() && killAura.usesDynamicReach();
653
    }
654
655
    private double resolveVulcanRequestedReach(Player target) {
656
        Reach reach = Modules.get(Reach.class);
657
        if (reach != null && reach.isEnabled() && reach.isVulcan297Mode()) {
658
            return reach.getConfiguredDistance();
659
        }
660
661
        KillAura killAura = Modules.get(KillAura.class);
662
        if (killAura != null && killAura.isEnabled() && killAura.usesDynamicReach()) {
663
            return killAura.getRange();
664
        }
665
666
        return 3.0;
667
    }
668
669
    private Player resolveVulcanReachTarget() {
670
        long now = System.currentTimeMillis();
671
        HitResult hit = mc.hitResult;
672
        if (hit instanceof EntityHitResult entityHit
673
                && entityHit.getEntity() instanceof Player player
674
                && player.isAlive()) {
675
            lastVulcanReachLookMs = now;
676
            lastVulcanReachTarget = player;
677
            return player;
678
        }
679
680
        KillAura killAura = Modules.get(KillAura.class);
681
        if (killAura != null
682
                && killAura.isEnabled()
683
                && killAura.usesDynamicReach()
684
                && killAura.getCurrentTarget() instanceof Player auraTarget
685
                && auraTarget.isAlive()) {
686
            lastVulcanReachTarget = auraTarget;
687
            return auraTarget;
688
        }
689
690
        if (lastVulcanReachTarget != null && !lastVulcanReachTarget.isAlive()) {
691
            lastVulcanReachTarget = null;
692
        }
693
694
        if (vulcanReachDisplay.get() == VulcanReachDisplay.ALWAYS) {
695
            return lastVulcanReachTarget;
696
        }
697
698
        if (lastVulcanReachTarget == null) {
699
            return null;
700
        }
701
702
        long lookWindow = Math.max(0, vulcanReachLookMs.get());
703
        long attackWindow = Math.max(0, vulcanReachAttackMs.get());
704
        boolean recentLook = lookWindow > 0 && now - lastVulcanReachLookMs <= lookWindow;
705
        boolean recentAttack = attackWindow > 0 && now - lastVulcanReachAttackMs <= attackWindow;
706
        return recentLook || recentAttack ? lastVulcanReachTarget : null;
707
    }
708
709
    private boolean isAttackPacket(ServerboundInteractPacket packet) {
710
        return packet.hand() == null && packet.location() == null;
711
    }
712
713
    private int smoothCrosshairColor(int targetColor) {
714
        if (!colorInitialized) {
715
            animatedColor = targetColor;
716
            colorInitialized = true;
717
            return animatedColor;
718
        }
719
        float t = AnimationUtility.clamp01(AnimationUtility.deltaTime() * COLOR_SMOOTH_SPEED);
720
        animatedColor = HudRenderUtil.mixColor(animatedColor, targetColor, t);
721
        if (colorDistance(animatedColor, targetColor) <= 2) {
722
            animatedColor = targetColor;
723
        }
724
        return animatedColor;
725
    }
726
727
    private int resolveEntityColor(Entity entity) {
728
        if (entity instanceof Player player) {
729
            return CategoryService.getColor(player);
730
        }
731
732
        PlayerRelations rel = PlayerRelations.get();
733
        boolean friendly = isFriendlyEntity(entity);
734
        return friendly ? rel.colorFriend() : rel.colorEnemy();
735
    }
736
737
    private boolean isFriendlyEntity(Entity entity) {
738
        var id = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
739
        if (id != null && EntityFilters.get().isIgnoredEntity(id.toString())) {
740
            return true;
741
        }
742
        return entity.getType().getCategory() != MobCategory.MONSTER;
743
    }
744
745
    private boolean shouldShowRiptideBlocked(Player player) {
746
        if (player == null) return false;
747
        ItemStack main = player.getMainHandItem();
748
        if (isRiptideBlocked(player, main)) return true;
749
        if (!isHandLikeItem(main)) return false;
750
        return isRiptideBlocked(player, player.getOffhandItem());
751
    }
752
753
    private boolean shouldShowCooldownCross(Player player) {
754
        if (player == null) return false;
755
        ItemStack main = player.getMainHandItem();
756
        if (isCooldownCrossItem(main) && player.getCooldowns().isOnCooldown(main)) return true;
757
        if (shouldSuppressOffhandCooldown(main)) return false;
758
        ItemStack off = player.getOffhandItem();
759
        return isCooldownCrossItem(off) && player.getCooldowns().isOnCooldown(off);
760
    }
761
762
    private boolean isCooldownCrossItem(ItemStack stack) {
763
        return stack != null && !stack.isEmpty();
764
    }
765
766
    private boolean shouldSuppressOffhandCooldown(ItemStack main) {
767
        return !isHandLikeItem(main);
768
    }
769
770
    private boolean isHandLikeItem(ItemStack stack) {
771
        if (stack == null || stack.isEmpty()) return true;
772
        Item item = stack.getItem();
773
        if (item instanceof BowItem || item instanceof CrossbowItem) return false;
774
        if (stack.is(Items.TRIDENT)) return false;
775
        if (FoodUtil.isFood(stack)) return false;
776
777
        final boolean[] hasAttackMod = {false};
778
        stack.forEachModifier(net.minecraft.world.entity.EquipmentSlotGroup.MAINHAND, (attribute, modifier, display) -> {
779
            if (attribute.equals(Attributes.ATTACK_DAMAGE) || attribute.equals(Attributes.ATTACK_SPEED)) {
780
                hasAttackMod[0] = true;
781
            }
782
        });
783
        return !hasAttackMod[0];
784
    }
785
786
    private void renderRiptideBlockedCross(Renderer2D renderer,
787
                                           float centerX,
788
                                           float centerY,
789
                                           float thicknessPx,
790
                                           float lengthPx,
791
                                           boolean outline,
792
                                           float outlinePx,
793
                                           int color) {
794
        float crossLength = lengthPx * RIPTIDE_CROSS_LENGTH_FACTOR;
795
        double hX = centerX - crossLength;
796
        double hY = centerY - thicknessPx * 0.5f;
797
        double vX = centerX - thicknessPx * 0.5f;
798
        double vY = centerY - crossLength;
799
800
        drawSegment(renderer, hX, hY, crossLength * 2.0f, thicknessPx, color, outline, outlinePx);
801
        drawSegment(renderer, vX, vY, thicknessPx, crossLength * 2.0f, color, outline, outlinePx);
802
    }
803
804
    private void updateSwapDetector(Player player) {
805
        ItemStack current = player.getItemBySlot(EquipmentSlot.CHEST);
806
        boolean isElytra = isElytra(current);
807
        boolean isChestplate = isChestplate(current);
808
        boolean candidate = isElytra || isChestplate;
809
810
        if (!chestInit) {
811
            chestInit = true;
812
            lastSwapCandidate = candidate;
813
            lastChestWasElytra = isElytra;
814
            lastChestStack = current.copy();
815
            return;
816
        }
817
818
        if (candidate && lastSwapCandidate && isElytra != lastChestWasElytra
819
                && !ItemStack.isSameItem(current, lastChestStack)) {
820
            Itemizer.showElytraSwap(current.copy());
821
        }
822
823
        lastSwapCandidate = candidate;
824
        lastChestWasElytra = isElytra;
825
        lastChestStack = current.copy();
826
    }
827
828
    private boolean isElytra(ItemStack stack) {
829
        return !stack.isEmpty() && stack.is(Items.ELYTRA);
830
    }
831
832
    private boolean isChestplate(ItemStack stack) {
833
        if (stack.isEmpty() || stack.is(Items.ELYTRA)) return false;
834
        Equippable eq = stack.get(DataComponents.EQUIPPABLE);
835
        return eq != null && eq.slot() == EquipmentSlot.CHEST;
836
    }
837
838
    private void resetSwapDetector() {
839
        chestInit = false;
840
        lastSwapCandidate = false;
841
        lastChestWasElytra = false;
842
        lastChestStack = ItemStack.EMPTY;
843
    }
844
845
    private void drawSegment(Renderer2D renderer,
846
                             double x,
847
                             double y,
848
                             double w,
849
                             double h,
850
                             int color,
851
                             boolean outline,
852
                             float outlinePx) {
853
        if (outline) {
854
            renderer.quad(x - outlinePx, y - outlinePx, w + outlinePx * 2.0f, h + outlinePx * 2.0f, OUTLINE_COLOR);
855
        }
856
        renderer.quad(x, y, w, h, color);
857
    }
858
859
    public enum VulcanReachDisplay implements EnumValue.IdProvider {
860
        TIMED("timed"),
861
        ALWAYS("always");
862
863
        private final String id;
864
865
        VulcanReachDisplay(String id) {
866
            this.id = id;
867
        }
868
869
        @Override
870
        public String id() {
871
            return id;
872
        }
873
    }
874
875
    private enum CrosshairType implements EnumValue.AliasProvider {
876
        CLASSIC,
877
        T_CLASSIC,
878
        ORBIZ;
879
880
        @Override
881
        public List<String> aliases() {
882
            return switch (this) {
883
                case CLASSIC -> List.of("Classic");
884
                case T_CLASSIC -> List.of("T-Classic");
885
                case ORBIZ -> List.of("Orbiz");
886
            };
887
        }
888
    }
889
890
    private enum OrbizMotionMode implements EnumValue.AliasProvider {
891
        STATIC,
892
        DYNAMIC;
893
894
        @Override
895
        public List<String> aliases() {
896
            return switch (this) {
897
                case STATIC -> List.of("Static", "Off", "Disabled", "false");
898
                case DYNAMIC -> List.of("Dynamic", "On", "Enabled", "true");
899
            };
900
        }
901
    }
902
}
903
NicotineRendersrc/client/java/nicotine/mod/mods/render/Crosshair.javaJava · 54 lines · 1.6 KB
SettingsWidthRGBNoCrosshair
Crosshair.javaJava · Minecraft 26.3 · 54 lines · 1.6 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.render;
2
3
import net.minecraft.client.CameraType;
4
import nicotine.events.RenderCrosshairEvent;
5
import nicotine.mod.Mod;
6
import nicotine.mod.ModCategory;
7
import nicotine.mod.option.RGBOption;
8
import nicotine.mod.option.SliderOption;
9
import nicotine.mod.option.ToggleOption;
10
import nicotine.util.EventBus;
11
12
import java.util.Arrays;
13
14
import static nicotine.util.Common.mc;
15
16
public class Crosshair extends Mod {
17
18
    private final SliderOption width = new SliderOption(
19
            "Width",
20
            4,
21
            1,
22
            30
23
    );
24
25
    private final RGBOption rgb = new RGBOption("RGB");
26
    private final ToggleOption noCrosshair = new ToggleOption("NoCrosshair");
27
28
    public Crosshair() {
29
        super(ModCategory.Render,"Crosshair");
30
        this.addOptions(Arrays.asList(width, rgb, noCrosshair));
31
    }
32
33
    @Override
34
    protected void init() {
35
        EventBus.register(RenderCrosshairEvent.class, event -> {
36
            if (!this.enabled)
37
                return true;
38
39
            if (noCrosshair.enabled || mc.options.getCameraType() != CameraType.FIRST_PERSON)
40
                return false;
41
42
            int widthVal = (int) width.value;
43
44
            final int centerWidth = mc.getWindow().getGuiScaledWidth() / 2;
45
            final int centerHeight = (mc.getWindow().getGuiScaledHeight() / 2) - 1;
46
47
            event.context.verticalLine(centerWidth, centerHeight - widthVal - 1, centerHeight + widthVal + 1, rgb.getColor());
48
            event.context.horizontalLine(centerWidth - widthVal, centerWidth + widthVal, centerHeight, rgb.getColor());
49
50
            return false;
51
        });
52
    }
53
}
54
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/crosshair/ModuleCrosshair.ktKotlin · 36 lines · 1.4 KB

Changes the style of your crosshair.

ModuleCrosshair.ktKotlin · Minecraft 26.2 · 36 lines · 1.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
package net.ccbluex.liquidbounce.features.module.modules.render.crosshair
21
22
import net.ccbluex.liquidbounce.features.module.ClientModule
23
import net.ccbluex.liquidbounce.features.module.ModuleCategories
24
import net.ccbluex.liquidbounce.features.module.modules.render.crosshair.modes.CrosshairCircle
25
import net.ccbluex.liquidbounce.features.module.modules.render.crosshair.modes.CrosshairCS2
26
27
object ModuleCrosshair : ClientModule("Crosshair", ModuleCategories.RENDER) {
28
    val modes =
29
        choices("Mode", 0) {
30
            arrayOf(
31
                CrosshairCircle,
32
                CrosshairCS2,
33
            )
34
        }.apply { tagBy(this) }
35
}
36