init
This commit is contained in:
commit
8084ac50b3
1629 changed files with 238620 additions and 0 deletions
|
|
@ -0,0 +1,525 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual;
|
||||
|
||||
import dev.loki.lovisual.events.impl.GameTickEvent;
|
||||
import dev.loki.lovisual.runtime.*;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import dev.loki.lovisual.addon.AddonManager;
|
||||
import dev.loki.lovisual.addon.AddonRenderPipelineManager;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import dev.loki.lovisual.config.MainConfig;
|
||||
import dev.loki.lovisual.events.Events;
|
||||
import dev.loki.lovisual.features.account.AccountConfig;
|
||||
import dev.loki.lovisual.features.command.CommandManager;
|
||||
import dev.loki.lovisual.features.command.VanillaChatRuntimeCleanup;
|
||||
import dev.loki.lovisual.features.gui.clickgui.ClickGuiRenderer;
|
||||
import dev.loki.lovisual.features.gui.clickgui.settings.I18nPreflightContributors;
|
||||
import dev.loki.lovisual.features.gui.hud.HudElements;
|
||||
import dev.loki.lovisual.features.gui.hud.HudRenderSpace;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementBootstrap;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.impl.SwapTooltip;
|
||||
import dev.loki.lovisual.features.module.HudPhase;
|
||||
import dev.loki.lovisual.features.module.ModuleAutoLoader;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import dev.loki.lovisual.features.module.WorldPhase;
|
||||
import dev.loki.lovisual.mixininterface.IGuiGraphics;
|
||||
import dev.loki.lovisual.render.effects.NetherPortalRiftPass;
|
||||
import dev.loki.lovisual.render.effects.SleepOverlayPass;
|
||||
import dev.loki.lovisual.render.engine.CombatantRenderEngineBootstrap;
|
||||
import dev.loki.lovisual.render.engine.core.CombatantRenderSystem;
|
||||
import dev.loki.lovisual.render.engine.core.RenderPhase;
|
||||
import dev.loki.lovisual.render.engine.core.RenderPhaseScope;
|
||||
import dev.loki.lovisual.render.engine.core.ViewportContext;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessManager;
|
||||
import dev.loki.lovisual.render.engine.profiler.ProfilerPhase;
|
||||
import dev.loki.lovisual.render.engine.profiler.RenderProfiler2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.FullScreenRenderer;
|
||||
import dev.loki.lovisual.render.engine.prewarm.RenderPrewarmContributors;
|
||||
import dev.loki.lovisual.render.engine.prewarm.RenderPrewarmManager;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import dev.loki.lovisual.render.helpers.SystemCursor;
|
||||
import dev.loki.lovisual.render.helpers.TickDelta;
|
||||
import dev.loki.lovisual.util.aiming.RotationManager;
|
||||
import dev.loki.lovisual.util.block.bed.SelfBedTracker;
|
||||
import dev.loki.lovisual.util.click.AttackPressing;
|
||||
import dev.loki.lovisual.util.combat.AntiBotTracker;
|
||||
import dev.loki.lovisual.util.combat.protocol.CombatProtocolHeuristics;
|
||||
import dev.loki.lovisual.util.combat.SprintController;
|
||||
import dev.loki.lovisual.util.combat.VulcanReachController;
|
||||
import dev.loki.lovisual.util.entity.simulation.BoatSimulationCache;
|
||||
import dev.loki.lovisual.util.media.MediaSessionService;
|
||||
import dev.loki.lovisual.util.network.BacktrackController;
|
||||
import dev.loki.lovisual.util.network.BlinkManager;
|
||||
import dev.loki.lovisual.util.proxy.ProxyBackend;
|
||||
import dev.loki.lovisual.util.network.FakeLagController;
|
||||
import dev.loki.lovisual.util.player.inventory.InventorySwap;
|
||||
import dev.loki.lovisual.util.player.simulation.PlayerSimulationCache;
|
||||
import dev.loki.lovisual.util.pvp.PvpTargetTracker;
|
||||
import dev.loki.lovisual.util.pvp.PvpTracker;
|
||||
import dev.loki.lovisual.util.target.TargetManager;
|
||||
import dev.loki.lovisual.util.time.TimerController;
|
||||
|
||||
public class LoVisual implements ClientModInitializer {
|
||||
|
||||
private static void registerRuntimeLifecycle() {
|
||||
AddonManager.registerRuntimeLifecycle();
|
||||
ClientRuntime.setCallbackCounter(Events.BUS::listenerCount);
|
||||
ClientRuntime.setModuleCounter(ModuleManager::registeredCount);
|
||||
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "modules";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
ModuleManager.shutdownForRuntime(context);
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerResumeParticipant(new RuntimeResumeParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "modules";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(String reason) {
|
||||
ModuleManager.restoreAfterSoftPanic(reason);
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "clickgui";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
ClickGuiRenderer.shutdownForRuntime();
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "vanilla_chat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
VanillaChatRuntimeCleanup.clearVanillaChatCache();
|
||||
context.increment("vanillaChatCleared", 1);
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "hud";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
if (context.jarReplacement()) {
|
||||
DraggableHudElementRegistry.clearRuntimeReferences();
|
||||
StaticHudElementRegistry.clearRuntimeReferences();
|
||||
}
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "render";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
if (context.jarReplacement()) {
|
||||
PostProcessManager.shutdownForRuntime();
|
||||
CombatantRenderSystem.shutdown();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void renderWorldPhase(WorldPhase phase,
|
||||
com.mojang.blaze3d.vertex.PoseStack matrices,
|
||||
net.minecraft.client.renderer.SubmitNodeCollector consumers) {
|
||||
if (!RuntimeGate.canRunRender()) return;
|
||||
|
||||
ModuleManager.renderWorld(
|
||||
phase,
|
||||
matrices,
|
||||
consumers,
|
||||
TickDelta.tickProgress(false)
|
||||
);
|
||||
}
|
||||
|
||||
private static void refreshHudFrameTiming(DeltaTracker tickCounter) {
|
||||
CombatantRenderSystem.updateFrameTiming(
|
||||
TickDelta.tickProgress(tickCounter, false),
|
||||
TickDelta.frameDeltaTicks(tickCounter),
|
||||
TickDelta.fixedDeltaTicks(tickCounter)
|
||||
);
|
||||
}
|
||||
|
||||
private static void renderHudPhase(HudPhase phase, GuiGraphicsExtractor ctx, DeltaTracker tickCounter) {
|
||||
if (!RuntimeGate.canRunHud()) return;
|
||||
float tickProgress = TickDelta.tickProgress(tickCounter, false);
|
||||
ModuleManager.renderHud(phase, ctx, tickProgress);
|
||||
Renderer2D.Deferred2DLayer layer = deferredLayerForHudPhase(phase);
|
||||
if (renderHudEngine(phase, layer, ctx, tickCounter)) {
|
||||
appendHudDeferredMarker(layer, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean renderHudEngine(HudPhase phase,
|
||||
Renderer2D.Deferred2DLayer layer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
DeltaTracker tickCounter) {
|
||||
boolean rawMain = hasHudMainPassWork(phase, HudRenderSpace.UNSCALED)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_RAW);
|
||||
boolean scaledMain = hasHudMainPassWork(phase, HudRenderSpace.SCALED)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_SCALED);
|
||||
boolean logicalMain = hasHudMainPassWork(phase, HudRenderSpace.UNSCALED_LOGICAL)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_LOGICAL);
|
||||
boolean rawForeground = hasHudForegroundPassWork(phase, HudRenderSpace.UNSCALED)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_RAW_FOREGROUND);
|
||||
boolean scaledForeground = hasHudForegroundPassWork(phase, HudRenderSpace.SCALED)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_SCALED_FOREGROUND);
|
||||
boolean logicalForeground = hasHudForegroundPassWork(phase, HudRenderSpace.UNSCALED_LOGICAL)
|
||||
|| AddonRenderPipelineManager.hasActiveCallbacks(LoVisualRenderStage.HUD_LOGICAL_FOREGROUND);
|
||||
if (!rawMain && !scaledMain && !logicalMain && !rawForeground && !scaledForeground && !logicalForeground) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float tickProgress = TickDelta.tickProgress(tickCounter, false);
|
||||
TextRenderer textRenderer = TextRenderer.get();
|
||||
|
||||
FullScreenRenderer.ensureInit();
|
||||
ViewportContext.beginUnscaled(ctx);
|
||||
refreshHudFrameTiming(tickCounter);
|
||||
|
||||
Renderer2D.withDeferredLayer(layer, () -> {
|
||||
SystemCursor.beginFrame(ctx);
|
||||
try (RenderPhaseScope hudPhase = CombatantRenderSystem.phase(RenderPhase.HUD_MAIN, "2d:phase:" + phase.name())) {
|
||||
// Raw HUD pass
|
||||
if (rawMain) {
|
||||
Renderer2D.COLOR.begin();
|
||||
ModuleManager.renderHudEngine(phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
StaticHudElementRegistry.renderAllEngine(phase, HudRenderSpace.UNSCALED, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_RAW, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
|
||||
// Scaled fixed HUD pass
|
||||
if (scaledMain) {
|
||||
ViewportContext.beginScaled(ctx);
|
||||
Renderer2D.COLOR.begin();
|
||||
StaticHudElementRegistry.renderAllEngine(phase, HudRenderSpace.SCALED, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_SCALED, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
|
||||
// Logical HUD pass
|
||||
if (logicalMain) {
|
||||
ViewportContext.beginUnscaledLogical(ctx);
|
||||
Renderer2D.COLOR.begin();
|
||||
StaticHudElementRegistry.renderAllEngine(phase, HudRenderSpace.UNSCALED_LOGICAL, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
DraggableHudElementRegistry.renderAllEngine(phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_LOGICAL, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
|
||||
// Raw foreground
|
||||
if (rawForeground) {
|
||||
ViewportContext.beginUnscaled(ctx);
|
||||
Renderer2D.COLOR.begin();
|
||||
ModuleManager.renderHudEngineForeground(phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
StaticHudElementRegistry.renderAllEngineForeground(phase, HudRenderSpace.UNSCALED, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_RAW_FOREGROUND, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
|
||||
// Scaled fixed HUD foreground
|
||||
if (scaledForeground) {
|
||||
ViewportContext.beginScaled(ctx);
|
||||
Renderer2D.COLOR.begin();
|
||||
StaticHudElementRegistry.renderAllEngineForeground(phase, HudRenderSpace.SCALED, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_SCALED_FOREGROUND, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
|
||||
// Logical foreground
|
||||
if (logicalForeground) {
|
||||
ViewportContext.beginUnscaledLogical(ctx);
|
||||
Renderer2D.COLOR.begin();
|
||||
StaticHudElementRegistry.renderAllEngineForeground(phase, HudRenderSpace.UNSCALED_LOGICAL, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
DraggableHudElementRegistry.renderAllEngineForeground(phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
AddonRenderPipelineManager.render2D(LoVisualRenderStage.HUD_LOGICAL_FOREGROUND, phase, Renderer2D.COLOR, textRenderer, ctx, tickProgress);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
} finally {
|
||||
SystemCursor.endFrame();
|
||||
ViewportContext.end(ctx);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void renderHudAfterHotbar(GuiGraphicsExtractor ctx, DeltaTracker tickCounter) {
|
||||
if (!RuntimeGate.canRunHud()) return;
|
||||
boolean swapTooltipWork = SwapTooltip.hasWork();
|
||||
boolean targetHudWork = DraggableHudElementRegistry.hasEngineWidgetWork("target_hud");
|
||||
if (!swapTooltipWork && !targetHudWork) return;
|
||||
|
||||
float tickProgress = TickDelta.tickProgress(tickCounter, false);
|
||||
TextRenderer textRenderer = TextRenderer.get();
|
||||
Renderer2D.Deferred2DLayer layer = Renderer2D.Deferred2DLayer.HUD_AFTER_MISC_OVERLAYS;
|
||||
|
||||
FullScreenRenderer.ensureInit();
|
||||
ViewportContext.beginUnscaled(ctx);
|
||||
refreshHudFrameTiming(tickCounter);
|
||||
|
||||
Renderer2D.withDeferredLayer(layer, () -> {
|
||||
SystemCursor.beginFrame(ctx);
|
||||
try (RenderPhaseScope hudPhase = CombatantRenderSystem.phase(RenderPhase.HUD_EFFECTS, "2d:after_hotbar")) {
|
||||
// Raw pass
|
||||
if (swapTooltipWork) {
|
||||
try (ProfilerPhase.Scope tooltipsScope = ProfilerPhase.scope("2d:after_hotbar:swap_tooltip");
|
||||
RenderProfiler2D.Section ignoredTooltips = RenderProfiler2D.section("swap_tooltip")) {
|
||||
Renderer2D.COLOR.begin();
|
||||
SwapTooltip.render();
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
}
|
||||
|
||||
// Logical pass
|
||||
if (targetHudWork) {
|
||||
ViewportContext.beginUnscaledLogical(ctx);
|
||||
try (ProfilerPhase.Scope targetHudScope = ProfilerPhase.scope("2d:after_hotbar:target_hud");
|
||||
RenderProfiler2D.Section ignoredTargetHud = RenderProfiler2D.section("target_hud")) {
|
||||
Renderer2D.COLOR.begin();
|
||||
DraggableHudElementRegistry.renderEngineWidget(
|
||||
"target_hud",
|
||||
Renderer2D.COLOR,
|
||||
textRenderer,
|
||||
ctx,
|
||||
tickProgress
|
||||
);
|
||||
Renderer2D.COLOR.render();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
SystemCursor.endFrame();
|
||||
ViewportContext.end(ctx);
|
||||
}
|
||||
});
|
||||
appendHudDeferredMarker(layer, ctx);
|
||||
}
|
||||
|
||||
private static void appendHudDeferredMarker(Renderer2D.Deferred2DLayer layer, GuiGraphicsExtractor ctx) {
|
||||
if (!(ctx instanceof IGuiGraphics graphics)) return;
|
||||
ctx.nextStratum();
|
||||
graphics.combatant$addDeferredHudMarker(layer);
|
||||
ctx.nextStratum();
|
||||
}
|
||||
|
||||
private static Renderer2D.Deferred2DLayer deferredLayerForHudPhase(HudPhase phase) {
|
||||
if (phase == null) return Renderer2D.Deferred2DLayer.BEFORE_VANILLA_GUI;
|
||||
return switch (phase) {
|
||||
case NONE -> Renderer2D.Deferred2DLayer.BEFORE_VANILLA_GUI;
|
||||
case FIRST -> Renderer2D.Deferred2DLayer.HUD_FIRST;
|
||||
case BEFORE_MISC_OVERLAYS -> Renderer2D.Deferred2DLayer.HUD_BEFORE_MISC_OVERLAYS;
|
||||
case AFTER_MISC_OVERLAYS -> Renderer2D.Deferred2DLayer.HUD_AFTER_MISC_OVERLAYS;
|
||||
case AFTER_BOSS_BAR -> Renderer2D.Deferred2DLayer.HUD_AFTER_BOSS_BAR;
|
||||
case BEFORE_DEMO_TIMER -> Renderer2D.Deferred2DLayer.HUD_BEFORE_DEMO_TIMER;
|
||||
case BEFORE_CHAT -> Renderer2D.Deferred2DLayer.HUD_BEFORE_CHAT;
|
||||
case AFTER_SUBTITLES -> Renderer2D.Deferred2DLayer.HUD_AFTER_SUBTITLES;
|
||||
case LAST -> Renderer2D.Deferred2DLayer.HUD_LAST;
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean hasHudMainPassWork(HudPhase phase, HudRenderSpace space) {
|
||||
boolean moduleWork = space == HudRenderSpace.UNSCALED && ModuleManager.hasHudEngineWork(phase);
|
||||
boolean staticWork = StaticHudElementRegistry.hasEngineWork(phase, space, false);
|
||||
boolean draggableWork = space == HudRenderSpace.UNSCALED_LOGICAL && DraggableHudElementRegistry.hasEngineWork(phase, false);
|
||||
return moduleWork || staticWork || draggableWork;
|
||||
}
|
||||
|
||||
private static boolean hasHudForegroundPassWork(HudPhase phase, HudRenderSpace space) {
|
||||
boolean moduleWork = space == HudRenderSpace.UNSCALED && ModuleManager.hasHudEngineForegroundWork(phase);
|
||||
boolean staticWork = StaticHudElementRegistry.hasEngineWork(phase, space, true);
|
||||
boolean draggableWork = space == HudRenderSpace.UNSCALED_LOGICAL && DraggableHudElementRegistry.hasEngineWork(phase, true);
|
||||
return moduleWork || staticWork || draggableWork;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
CombatantRenderEngineBootstrap.init();
|
||||
PostProcessManager.register(new NetherPortalRiftPass());
|
||||
PostProcessManager.register(new SleepOverlayPass());
|
||||
MainConfig.get(); // Load global settings (debug flag)
|
||||
AccountConfig.get();
|
||||
ProxyBackend.init();
|
||||
CommandManager.init();
|
||||
MediaSessionService.get().init();
|
||||
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> MediaSessionService.get().shutdown());
|
||||
|
||||
// -------- CONFIG + BINDS ----------
|
||||
// Enabled addons declare built-in module exclusions before auto-discovery.
|
||||
AddonManager.prepareModuleLoading();
|
||||
ModuleAutoLoader.load("dev.loki.lovisual.features.module.modules");
|
||||
AddonManager.init();
|
||||
// Initialize modules' enabled state and settings from new config system
|
||||
ModuleManager.loadAllModuleConfigs();
|
||||
AddonManager.notifyClientReady();
|
||||
// Key binds are restored via Module config (KeyBindSetting) in ModuleManager.loadAllModuleConfigs()
|
||||
HudElements.init(); // init HUD config + widgets
|
||||
StaticHudElementBootstrap.init(); // init vanilla HUD elements config
|
||||
Events.BUS.register(I18nPreflightContributors.INSTANCE);
|
||||
Events.BUS.register(RenderPrewarmContributors.INSTANCE);
|
||||
Events.BUS.register(RotationManager.INSTANCE);
|
||||
Events.BUS.register(AttackPressing.INSTANCE);
|
||||
Events.BUS.register(InventorySwap.INSTANCE);
|
||||
Events.BUS.register(SprintController.INSTANCE);
|
||||
Events.BUS.register(AntiBotTracker.INSTANCE);
|
||||
Events.BUS.register(VulcanReachController.INSTANCE);
|
||||
Events.BUS.register(CombatProtocolHeuristics.INSTANCE);
|
||||
Events.BUS.register(PvpTracker.INSTANCE);
|
||||
Events.BUS.register(PvpTargetTracker.INSTANCE);
|
||||
Events.BUS.register(SelfBedTracker.INSTANCE);
|
||||
Events.BUS.register(BoatSimulationCache.INSTANCE);
|
||||
Events.BUS.register(PlayerSimulationCache.INSTANCE);
|
||||
Events.BUS.register(BlinkManager.INSTANCE);
|
||||
Events.BUS.register(FakeLagController.INSTANCE);
|
||||
Events.BUS.register(BacktrackController.INSTANCE);
|
||||
Events.BUS.register(TimerController.INSTANCE);
|
||||
|
||||
// -------- КЛЮЧЕВЫЕ ИВЕНТЫ --------
|
||||
|
||||
// === ТИКИ ===
|
||||
|
||||
|
||||
ClientTickEvents.START_CLIENT_TICK.register(client -> {
|
||||
if (client.player == null) return;
|
||||
if (!RuntimeGate.canRunClientLogic()) return;
|
||||
Events.BUS.post(new GameTickEvent());
|
||||
});
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
ModuleManager.tickRuntimeControllers();
|
||||
if (!RuntimeGate.canRunClientLogic()) return;
|
||||
|
||||
if (!ClickGuiRenderer.isBlockingModuleKeybinds()) {
|
||||
ModuleManager.handleModuleKeybinds();
|
||||
}
|
||||
TargetManager.tick();
|
||||
ModuleManager.tickAll();
|
||||
DraggableHudElementRegistry.tickAll();
|
||||
StaticHudElementRegistry.tickAll();
|
||||
});
|
||||
|
||||
/* ====================== WORLD RENDER ====================== */
|
||||
|
||||
LevelRenderEvents.COLLECT_SUBMITS.register(ctx -> renderWorldPhase(
|
||||
WorldPhase.BEFORE_ENTITIES,
|
||||
ctx.poseStack(),
|
||||
ctx.submitNodeCollector()
|
||||
));
|
||||
|
||||
LevelRenderEvents.AFTER_SOLID_FEATURES.register(ctx -> renderWorldPhase(
|
||||
WorldPhase.AFTER_ENTITIES,
|
||||
ctx.poseStack(),
|
||||
ctx.submitNodeCollector()
|
||||
));
|
||||
|
||||
LevelRenderEvents.BEFORE_TRANSLUCENT_TERRAIN.register(ctx -> renderWorldPhase(
|
||||
WorldPhase.BEFORE_TRANSLUCENT,
|
||||
ctx.poseStack(),
|
||||
ctx.submitNodeCollector()
|
||||
));
|
||||
|
||||
LevelRenderEvents.END_MAIN.register(ctx -> renderWorldPhase(
|
||||
WorldPhase.END_MAIN,
|
||||
ctx.poseStack(),
|
||||
ctx.submitNodeCollector()
|
||||
));
|
||||
|
||||
|
||||
// === HUD 2D OVERLAYS ===
|
||||
|
||||
HudElementRegistry.addFirst(
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_first"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.FIRST, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.addLast(
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_last"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.LAST, ctx, tc)
|
||||
);
|
||||
|
||||
// остальные позиции HUD:
|
||||
HudElementRegistry.attachElementBefore(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.MISC_OVERLAYS,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_before_misc"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.BEFORE_MISC_OVERLAYS, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementAfter(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.MISC_OVERLAYS,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_after_misc"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.AFTER_MISC_OVERLAYS, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementAfter(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.SLEEP,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_after_boss"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.AFTER_BOSS_BAR, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementBefore(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.DEMO_TIMER,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_before_demo"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.BEFORE_DEMO_TIMER, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementBefore(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.CHAT,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_before_chat"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.BEFORE_CHAT, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementAfter(
|
||||
net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements.SUBTITLES,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_after_subtitles"),
|
||||
(ctx, tc) -> renderHudPhase(HudPhase.AFTER_SUBTITLES, ctx, tc)
|
||||
);
|
||||
|
||||
HudElementRegistry.attachElementAfter(
|
||||
VanillaHudElements.HOTBAR,
|
||||
Identifier.fromNamespaceAndPath("lovisual", "hud_after_hotbar"),
|
||||
(ctx, tc) -> renderHudAfterHotbar(ctx, tc)
|
||||
);
|
||||
|
||||
registerRuntimeLifecycle();
|
||||
ClientRuntime.markActive("client initialized");
|
||||
RenderPrewarmManager.prewarm("client initialized");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
record AddonDescriptor(
|
||||
String id,
|
||||
String name,
|
||||
String version,
|
||||
String description,
|
||||
List<String> authors,
|
||||
String iconPath,
|
||||
int apiVersion,
|
||||
String entrypointDefinition
|
||||
) {
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
public record AddonIssue(
|
||||
String addonId,
|
||||
Severity severity,
|
||||
String message,
|
||||
String detail
|
||||
) {
|
||||
public enum Severity {
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddon;
|
||||
import dev.loki.lovisual.features.gui.hud.AbstractHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementRegistry;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleAutoLoader;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import dev.loki.lovisual.runtime.ClientRuntime;
|
||||
import dev.loki.lovisual.runtime.RuntimeResumeParticipant;
|
||||
import dev.loki.lovisual.runtime.RuntimeShutdownContext;
|
||||
import dev.loki.lovisual.runtime.RuntimeShutdownParticipant;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.metadata.CustomValue;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum AddonManager {
|
||||
;
|
||||
|
||||
public static final String ADDON_METADATA_KEY = "combatant:addon";
|
||||
|
||||
private static final Map<String, AddonRegistration> ADDONS = new LinkedHashMap<>();
|
||||
private static final Map<String, Boolean> ENABLED_OVERRIDES = new LinkedHashMap<>();
|
||||
private static final Map<String, String> MODULE_OWNERS = new LinkedHashMap<>();
|
||||
private static final Map<String, String> DRAGGABLE_HUD_OWNERS = new LinkedHashMap<>();
|
||||
private static final Map<String, String> STATIC_HUD_OWNERS = new LinkedHashMap<>();
|
||||
private static boolean discovered;
|
||||
private static boolean moduleLoadingPrepared;
|
||||
private static boolean initialized;
|
||||
private static boolean clientReady;
|
||||
|
||||
/**
|
||||
* Discovers enabled addon entrypoints and lets them configure built-in module
|
||||
* exclusions before {@code ModuleAutoLoader} starts instantiating modules.
|
||||
*/
|
||||
public static void prepareModuleLoading() {
|
||||
ensureDiscovered();
|
||||
if (moduleLoadingPrepared) return;
|
||||
moduleLoadingPrepared = true;
|
||||
configureEnabledAddons();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (initialized) return;
|
||||
prepareModuleLoading();
|
||||
if (!ModuleAutoLoader.isDiscoveryFinished()) {
|
||||
return;
|
||||
}
|
||||
reconcileModuleExclusions();
|
||||
initialized = true;
|
||||
initializeEnabledAddons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes addon startup after module configs have been loaded and applied.
|
||||
*/
|
||||
public static void notifyClientReady() {
|
||||
init();
|
||||
if (!initialized) return;
|
||||
clientReady = true;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureDiscovered() {
|
||||
if (discovered) return;
|
||||
discovered = true;
|
||||
ENABLED_OVERRIDES.clear();
|
||||
ENABLED_OVERRIDES.putAll(AddonStateStore.loadEnabledOverrides());
|
||||
discoverEntrypoints();
|
||||
}
|
||||
|
||||
public static void registerRuntimeLifecycle() {
|
||||
ClientRuntime.setAddonCounter(AddonManager::activeCount);
|
||||
ClientRuntime.registerParticipant(new RuntimeShutdownParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "addons";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(RuntimeShutdownContext context) {
|
||||
suspendForRuntime(context);
|
||||
}
|
||||
});
|
||||
ClientRuntime.registerResumeParticipant(new RuntimeResumeParticipant() {
|
||||
@Override
|
||||
public String id() {
|
||||
return "addons";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(String reason) {
|
||||
resumeAfterRuntime(reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<AddonSnapshot> snapshots() {
|
||||
init();
|
||||
return ADDONS.values().stream()
|
||||
.map(AddonRegistration::snapshot)
|
||||
.sorted(Comparator.comparing(AddonSnapshot::name, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static AddonSnapshot snapshot(String id) {
|
||||
init();
|
||||
AddonRegistration registration = ADDONS.get(normalizeId(id));
|
||||
return registration == null ? null : registration.snapshot();
|
||||
}
|
||||
|
||||
public static boolean isActive(String id) {
|
||||
init();
|
||||
AddonRegistration registration = ADDONS.get(normalizeId(id));
|
||||
return registration != null && registration.enabled && registration.status == AddonStatus.ACTIVE;
|
||||
}
|
||||
|
||||
public static List<AddonIssue> scan() {
|
||||
init();
|
||||
List<AddonIssue> out = new ArrayList<>();
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
validateRegistration(registration);
|
||||
out.addAll(registration.issues);
|
||||
}
|
||||
if (out.isEmpty()) {
|
||||
out.add(new AddonIssue("combatant", AddonIssue.Severity.INFO, "No addon errors found", ""));
|
||||
}
|
||||
return List.copyOf(out);
|
||||
}
|
||||
|
||||
public static String moduleProfileOwnerId(String moduleId) {
|
||||
String addonId = MODULE_OWNERS.get(normalizeId(moduleId));
|
||||
return addonId == null ? "module:" + moduleId : "addon:" + addonId + ":module:" + moduleId;
|
||||
}
|
||||
|
||||
public static String draggableHudProfileOwnerId(String elementId) {
|
||||
String addonId = DRAGGABLE_HUD_OWNERS.get(normalizeId(elementId));
|
||||
return addonId == null ? "hud.draggable:" + elementId : "addon:" + addonId + ":hud.draggable:" + elementId;
|
||||
}
|
||||
|
||||
public static String staticHudProfileOwnerId(String elementId) {
|
||||
String addonId = STATIC_HUD_OWNERS.get(normalizeId(elementId));
|
||||
return addonId == null ? "hud.static:" + elementId : "addon:" + addonId + ":hud.static:" + elementId;
|
||||
}
|
||||
|
||||
public static String profileDisplayName(String ownerId, String displayName) {
|
||||
String addonId = addonIdFromProfileOwner(ownerId);
|
||||
if (addonId == null) return displayName;
|
||||
AddonRegistration registration = ADDONS.get(addonId);
|
||||
String addonName = registration == null ? addonId : registration.descriptor.name();
|
||||
return addonName + " / " + displayName;
|
||||
}
|
||||
|
||||
public static String addonIdFromProfileOwner(String ownerId) {
|
||||
if (ownerId == null || !ownerId.startsWith("addon:")) return null;
|
||||
int start = "addon:".length();
|
||||
int end = ownerId.indexOf(':', start);
|
||||
if (end <= start) return null;
|
||||
return normalizeId(ownerId.substring(start, end));
|
||||
}
|
||||
|
||||
public static boolean setEnabled(String id, boolean enabled) {
|
||||
init();
|
||||
String normalizedId = normalizeId(id);
|
||||
AddonRegistration registration = ADDONS.get(normalizedId);
|
||||
if (registration == null) return false;
|
||||
if (registration.enabled == enabled) return true;
|
||||
|
||||
registration.enabled = enabled;
|
||||
registration.restartRequired = false;
|
||||
ENABLED_OVERRIDES.put(normalizedId, enabled);
|
||||
AddonStateStore.saveEnabledOverrides(ENABLED_OVERRIDES);
|
||||
|
||||
if (enabled) {
|
||||
if (!registration.moduleConfigurationApplied) {
|
||||
configureAddonModules(registration);
|
||||
}
|
||||
if (!registration.initialized) {
|
||||
initializeAddon(registration);
|
||||
} else {
|
||||
resumeRuntimeContributions(registration);
|
||||
resumeAddon(registration, "enabled by user");
|
||||
if (registration.status != AddonStatus.ERROR) {
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
}
|
||||
}
|
||||
if (clientReady) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
registration.restartRequired = !registration.disabledBuiltInModules.isEmpty();
|
||||
if (!registration.initialized) {
|
||||
registration.status = AddonStatus.DISABLED;
|
||||
return true;
|
||||
}
|
||||
|
||||
suspendRuntimeContributions(registration);
|
||||
suspendAddon(registration, "disabled by user");
|
||||
registration.status = AddonStatus.DISABLED;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int activeCount() {
|
||||
int count = 0;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.status == AddonStatus.ACTIVE) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static void discoverEntrypoints() {
|
||||
for (var entrypoint : FabricLoader.getInstance()
|
||||
.getEntrypointContainers(LoVisualAddon.ENTRYPOINT_KEY, LoVisualAddon.class)) {
|
||||
ModMetadata metadata = entrypoint.getProvider().getMetadata();
|
||||
String id = normalizeId(metadata.getId());
|
||||
AddonDescriptor descriptor = descriptor(metadata, entrypoint.getDefinition());
|
||||
boolean enabled = ENABLED_OVERRIDES.getOrDefault(id, true);
|
||||
AddonStatus status = enabled ? AddonStatus.DISCOVERED : AddonStatus.DISABLED;
|
||||
AddonRegistration duplicate = ADDONS.get(id);
|
||||
if (duplicate != null) {
|
||||
duplicate.issue(AddonIssue.Severity.ERROR, "Duplicate addon id", metadata.getId());
|
||||
continue;
|
||||
}
|
||||
AddonRegistration registration = new AddonRegistration(descriptor, entrypoint, enabled, status);
|
||||
validateRegistration(registration);
|
||||
ADDONS.put(id, registration);
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureEnabledAddons() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.enabled) {
|
||||
configureAddonModules(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void configureAddonModules(AddonRegistration registration) {
|
||||
if (registration.moduleConfigurationApplied || !registration.enabled || registration.status == AddonStatus.ERROR) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LoVisualAddon addon = addonInstance(registration);
|
||||
LoVisualModuleLoadContextImpl context = new LoVisualModuleLoadContextImpl(registration);
|
||||
addon.onConfigureModules(context);
|
||||
context.commit();
|
||||
registration.moduleConfigurationApplied = true;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Module configuration failed", t.toString());
|
||||
DebugLog.error("Addon module configuration failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void reconcileModuleExclusions() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.disabledBuiltInModules.isEmpty()) continue;
|
||||
registration.disabledBuiltInModules.removeIf(reference -> {
|
||||
if (ModuleAutoLoader.wasDisableRequestMatched(reference, registration.descriptor.id())) {
|
||||
return false;
|
||||
}
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Built-in module exclusion target was not found",
|
||||
reference
|
||||
);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeEnabledAddons() {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.enabled && registration.status != AddonStatus.ERROR) {
|
||||
initializeAddon(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void initializeAddon(AddonRegistration registration) {
|
||||
if (registration.initialized || !registration.enabled || registration.status == AddonStatus.ERROR) return;
|
||||
if (!registration.moduleConfigurationApplied) {
|
||||
configureAddonModules(registration);
|
||||
if (registration.status == AddonStatus.ERROR) return;
|
||||
}
|
||||
try {
|
||||
LoVisualAddon addon = addonInstance(registration);
|
||||
addon.onInitialize(new LoVisualAddonContextImpl(registration));
|
||||
registration.initialized = true;
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
DebugLog.info("Addon initialized: %s", registration.descriptor.id());
|
||||
if (clientReady) {
|
||||
notifyClientReady(registration);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Initialization failed", t.toString());
|
||||
DebugLog.error("Addon initialization failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyClientReady(AddonRegistration registration) {
|
||||
if (registration == null
|
||||
|| registration.clientReadyNotified
|
||||
|| !registration.initialized
|
||||
|| !registration.enabled
|
||||
|| registration.status != AddonStatus.ACTIVE) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
registration.addon.onClientReady(
|
||||
new LoVisualAddonRuntimeContextImpl(registration.descriptor.id())
|
||||
);
|
||||
registration.clientReadyNotified = true;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Client ready callback failed", t.toString());
|
||||
DebugLog.error("Addon client ready callback failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static LoVisualAddon addonInstance(AddonRegistration registration) {
|
||||
LoVisualAddon addon = registration.addon;
|
||||
if (addon == null) {
|
||||
addon = registration.entrypoint.getEntrypoint();
|
||||
registration.addon = addon;
|
||||
}
|
||||
return addon;
|
||||
}
|
||||
|
||||
private static void suspendForRuntime(RuntimeShutdownContext context) {
|
||||
int suspended = 0;
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.addon == null || registration.status != AddonStatus.ACTIVE) continue;
|
||||
try {
|
||||
if (context.jarReplacement()) {
|
||||
shutdownAddon(registration, context.reason());
|
||||
registration.status = AddonStatus.SHUTDOWN;
|
||||
} else {
|
||||
registration.addon.onRuntimeSuspended(
|
||||
new LoVisualAddonRuntimeContextImpl(registration.descriptor.id())
|
||||
);
|
||||
registration.status = AddonStatus.SUSPENDED;
|
||||
}
|
||||
suspended++;
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime suspend failed", t.toString());
|
||||
DebugLog.error("Addon runtime suspend failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
context.increment("addons_suspended", suspended);
|
||||
}
|
||||
|
||||
private static void resumeAfterRuntime(String reason) {
|
||||
for (AddonRegistration registration : ADDONS.values()) {
|
||||
if (registration.addon == null || registration.status != AddonStatus.SUSPENDED || !registration.enabled) {
|
||||
continue;
|
||||
}
|
||||
resumeAddon(registration, reason);
|
||||
if (registration.status != AddonStatus.ERROR) {
|
||||
registration.status = AddonStatus.ACTIVE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void suspendAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onRuntimeSuspended(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime suspend failed", t.toString());
|
||||
DebugLog.error("Addon runtime suspend failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void resumeAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onRuntimeResumed(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.status = AddonStatus.ERROR;
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Runtime resume failed", t.toString());
|
||||
DebugLog.error("Addon runtime resume failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void shutdownAddon(AddonRegistration registration, String reason) {
|
||||
if (registration.addon == null) return;
|
||||
try {
|
||||
registration.addon.onShutdown(new LoVisualAddonRuntimeContextImpl(registration.descriptor.id()));
|
||||
} catch (Throwable t) {
|
||||
registration.issue(AddonIssue.Severity.ERROR, "Shutdown failed", t.toString());
|
||||
DebugLog.error("Addon shutdown failed: %s", t, registration.descriptor.id());
|
||||
}
|
||||
}
|
||||
|
||||
private static void suspendRuntimeContributions(AddonRegistration registration) {
|
||||
registration.suspendedModules.clear();
|
||||
registration.suspendedDraggableHudElements.clear();
|
||||
registration.suspendedStaticHudElements.clear();
|
||||
for (String id : registration.modules) {
|
||||
Module module = ModuleManager.get(id);
|
||||
if (module != null) {
|
||||
registration.suspendedModules.put(id, module.isEnabled());
|
||||
ModuleManager.setRuntimeEnabledTransient(id, false);
|
||||
}
|
||||
}
|
||||
for (String id : registration.draggableHudElements) {
|
||||
DraggableHudElement element = DraggableHudElementRegistry.getById(id);
|
||||
if (element != null) {
|
||||
registration.suspendedDraggableHudElements.put(id, element.isEnabled());
|
||||
element.setRuntimeEnabledTransient(false);
|
||||
}
|
||||
}
|
||||
for (String id : registration.staticHudElements) {
|
||||
AbstractHudElement element = StaticHudElementRegistry.getById(id);
|
||||
if (element != null) {
|
||||
registration.suspendedStaticHudElements.put(id, element.isEnabled());
|
||||
element.setRuntimeEnabledTransient(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void resumeRuntimeContributions(AddonRegistration registration) {
|
||||
for (String id : registration.modules) {
|
||||
Boolean enabled = registration.suspendedModules.get(id);
|
||||
if (enabled != null) {
|
||||
ModuleManager.setRuntimeEnabledTransient(id, enabled);
|
||||
}
|
||||
}
|
||||
for (String id : registration.draggableHudElements) {
|
||||
Boolean enabled = registration.suspendedDraggableHudElements.get(id);
|
||||
DraggableHudElement element = DraggableHudElementRegistry.getById(id);
|
||||
if (enabled != null && element != null) {
|
||||
element.setRuntimeEnabledTransient(enabled);
|
||||
}
|
||||
}
|
||||
for (String id : registration.staticHudElements) {
|
||||
Boolean enabled = registration.suspendedStaticHudElements.get(id);
|
||||
AbstractHudElement element = StaticHudElementRegistry.getById(id);
|
||||
if (enabled != null && element != null) {
|
||||
element.setRuntimeEnabledTransient(enabled);
|
||||
}
|
||||
}
|
||||
registration.suspendedModules.clear();
|
||||
registration.suspendedDraggableHudElements.clear();
|
||||
registration.suspendedStaticHudElements.clear();
|
||||
}
|
||||
|
||||
static void noteModuleOwner(String addonId, String moduleId) {
|
||||
if (moduleId != null && !moduleId.isBlank()) {
|
||||
MODULE_OWNERS.put(normalizeId(moduleId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
static void noteDraggableHudOwner(String addonId, String elementId) {
|
||||
if (elementId != null && !elementId.isBlank()) {
|
||||
DRAGGABLE_HUD_OWNERS.put(normalizeId(elementId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
static void noteStaticHudOwner(String addonId, String elementId) {
|
||||
if (elementId != null && !elementId.isBlank()) {
|
||||
STATIC_HUD_OWNERS.put(normalizeId(elementId), normalizeId(addonId));
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRegistration(AddonRegistration registration) {
|
||||
if (registration.descriptor.apiVersion() != LoVisualAddon.API_VERSION) {
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Addon API version differs from client API",
|
||||
"addon=" + registration.descriptor.apiVersion() + ", client=" + LoVisualAddon.API_VERSION
|
||||
);
|
||||
}
|
||||
if (registration.descriptor.iconPath() == null || registration.descriptor.iconPath().isBlank()) {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Addon icon is missing", "Add icon in fabric.mod.json");
|
||||
}
|
||||
if (registration.descriptor.entrypointDefinition() == null
|
||||
|| registration.descriptor.entrypointDefinition().isBlank()) {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Entrypoint definition is unavailable", "");
|
||||
}
|
||||
}
|
||||
|
||||
private static AddonDescriptor descriptor(ModMetadata metadata, String entrypointDefinition) {
|
||||
List<String> authors = metadata.getAuthors().stream()
|
||||
.map(person -> person.getName() == null ? "" : person.getName())
|
||||
.filter(name -> !name.isBlank())
|
||||
.toList();
|
||||
return new AddonDescriptor(
|
||||
normalizeId(metadata.getId()),
|
||||
blankFallback(metadata.getName(), metadata.getId()),
|
||||
String.valueOf(metadata.getVersion()),
|
||||
metadata.getDescription() == null ? "" : metadata.getDescription(),
|
||||
authors,
|
||||
metadata.getIconPath(64).or(() -> metadata.getIconPath(32)).orElse(""),
|
||||
apiVersion(metadata),
|
||||
entrypointDefinition
|
||||
);
|
||||
}
|
||||
|
||||
private static int apiVersion(ModMetadata metadata) {
|
||||
CustomValue value = metadata.getCustomValue(ADDON_METADATA_KEY);
|
||||
if (value == null || value.getType() != CustomValue.CvType.OBJECT) return LoVisualAddon.API_VERSION;
|
||||
CustomValue api = value.getAsObject().get("api");
|
||||
if (api == null || api.getType() != CustomValue.CvType.NUMBER) return LoVisualAddon.API_VERSION;
|
||||
return api.getAsNumber().intValue();
|
||||
}
|
||||
|
||||
private static String blankFallback(String value, String fallback) {
|
||||
return value == null || value.isBlank() ? fallback : value;
|
||||
}
|
||||
|
||||
private static String normalizeId(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddon;
|
||||
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class AddonRegistration {
|
||||
final AddonDescriptor descriptor;
|
||||
final EntrypointContainer<LoVisualAddon> entrypoint;
|
||||
final List<String> modules = new ArrayList<>();
|
||||
final List<String> disabledBuiltInModules = new ArrayList<>();
|
||||
final List<String> draggableHudElements = new ArrayList<>();
|
||||
final List<String> staticHudElements = new ArrayList<>();
|
||||
final List<String> commands = new ArrayList<>();
|
||||
final List<String> clickGuiSections = new ArrayList<>();
|
||||
final List<String> moduleExtensions = new ArrayList<>();
|
||||
final List<String> irisPatchManifests = new ArrayList<>();
|
||||
final List<String> renderCallbacks = new ArrayList<>();
|
||||
final List<String> postProcessPasses = new ArrayList<>();
|
||||
final List<AddonIssue> issues = new ArrayList<>();
|
||||
final Map<String, Boolean> suspendedModules = new LinkedHashMap<>();
|
||||
final Map<String, Boolean> suspendedDraggableHudElements = new LinkedHashMap<>();
|
||||
final Map<String, Boolean> suspendedStaticHudElements = new LinkedHashMap<>();
|
||||
LoVisualAddon addon;
|
||||
boolean moduleConfigurationApplied;
|
||||
boolean initialized;
|
||||
boolean clientReadyNotified;
|
||||
AddonStatus status;
|
||||
boolean enabled;
|
||||
boolean restartRequired;
|
||||
|
||||
AddonRegistration(AddonDescriptor descriptor,
|
||||
EntrypointContainer<LoVisualAddon> entrypoint,
|
||||
boolean enabled,
|
||||
AddonStatus status) {
|
||||
this.descriptor = descriptor;
|
||||
this.entrypoint = entrypoint;
|
||||
this.enabled = enabled;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
AddonSnapshot snapshot() {
|
||||
return new AddonSnapshot(
|
||||
descriptor.id(),
|
||||
descriptor.name(),
|
||||
descriptor.version(),
|
||||
descriptor.description(),
|
||||
descriptor.authors(),
|
||||
descriptor.iconPath(),
|
||||
descriptor.apiVersion(),
|
||||
status,
|
||||
enabled,
|
||||
restartRequired,
|
||||
modules.size(),
|
||||
draggableHudElements.size(),
|
||||
staticHudElements.size(),
|
||||
commands.size(),
|
||||
clickGuiSections.size(),
|
||||
moduleExtensions.size(),
|
||||
irisPatchManifests.size(),
|
||||
List.copyOf(issues)
|
||||
);
|
||||
}
|
||||
|
||||
void issue(AddonIssue.Severity severity, String message, String detail) {
|
||||
issues.add(new AddonIssue(descriptor.id(), severity, message, detail));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessContext;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderContext;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import dev.loki.lovisual.features.module.HudPhase;
|
||||
import dev.loki.lovisual.features.module.WorldPhase;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessManager;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum AddonRenderPipelineManager {
|
||||
;
|
||||
|
||||
private static final Map<LoVisualRenderStage, List<RegisteredRenderCallback>> CALLBACKS =
|
||||
new EnumMap<>(LoVisualRenderStage.class);
|
||||
|
||||
static {
|
||||
for (LoVisualRenderStage stage : LoVisualRenderStage.values()) {
|
||||
CALLBACKS.put(stage, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized boolean register(String addonId,
|
||||
String callbackId,
|
||||
LoVisualRenderStage stage,
|
||||
LoVisualRenderCallback callback) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedCallbackId = normalize(callbackId);
|
||||
if (normalizedAddonId.isBlank() || normalizedCallbackId.isBlank() || stage == null || callback == null) {
|
||||
return false;
|
||||
}
|
||||
List<RegisteredRenderCallback> callbacks = CALLBACKS.get(stage);
|
||||
for (RegisteredRenderCallback registered : callbacks) {
|
||||
if (registered.addonId().equals(normalizedAddonId) && registered.callbackId().equals(normalizedCallbackId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
callbacks.add(new RegisteredRenderCallback(normalizedAddonId, normalizedCallbackId, callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasActiveCallbacks(LoVisualRenderStage stage) {
|
||||
if (stage == null) return false;
|
||||
List<RegisteredRenderCallback> callbacks;
|
||||
synchronized (AddonRenderPipelineManager.class) {
|
||||
callbacks = List.copyOf(CALLBACKS.get(stage));
|
||||
}
|
||||
for (RegisteredRenderCallback callback : callbacks) {
|
||||
if (AddonManager.isActive(callback.addonId())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean registerPostProcess(String addonId,
|
||||
String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedPassId = normalize(passId);
|
||||
if (normalizedAddonId.isBlank() || normalizedPassId.isBlank() || phase == null || callback == null) {
|
||||
return false;
|
||||
}
|
||||
PostProcessManager.register(new AddonPostProcessPass(normalizedAddonId, normalizedPassId, phase, priority, callback));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void render2D(LoVisualRenderStage stage,
|
||||
HudPhase hudPhase,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor guiContext,
|
||||
float tickDelta) {
|
||||
render(stage, hudPhase, null, renderer, null, null, textRenderer, guiContext, null, tickDelta);
|
||||
}
|
||||
|
||||
public static void render3D(LoVisualRenderStage stage,
|
||||
WorldPhase worldPhase,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
PoseStack poseStack,
|
||||
float tickDelta) {
|
||||
render(stage, null, worldPhase, null, renderer, depthRenderer, null, null, poseStack, tickDelta);
|
||||
}
|
||||
|
||||
public static synchronized void unregisterAddon(String addonId) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
for (List<RegisteredRenderCallback> callbacks : CALLBACKS.values()) {
|
||||
callbacks.removeIf(callback -> callback.addonId().equals(normalizedAddonId));
|
||||
}
|
||||
}
|
||||
|
||||
private static void render(LoVisualRenderStage stage,
|
||||
HudPhase hudPhase,
|
||||
WorldPhase worldPhase,
|
||||
Renderer2D renderer2D,
|
||||
Renderer3D renderer3D,
|
||||
Renderer3D depthRenderer3D,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor guiContext,
|
||||
PoseStack poseStack,
|
||||
float tickDelta) {
|
||||
List<RegisteredRenderCallback> callbacks;
|
||||
synchronized (AddonRenderPipelineManager.class) {
|
||||
callbacks = List.copyOf(CALLBACKS.get(stage));
|
||||
}
|
||||
for (RegisteredRenderCallback registered : callbacks) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
registered.callback().render(new LoVisualRenderContext(
|
||||
registered.addonId(),
|
||||
registered.callbackId(),
|
||||
stage,
|
||||
hudPhase,
|
||||
worldPhase,
|
||||
renderer2D,
|
||||
renderer3D,
|
||||
depthRenderer3D,
|
||||
textRenderer,
|
||||
guiContext,
|
||||
poseStack,
|
||||
tickDelta
|
||||
));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Render callback failed: addon=%s id=%s",
|
||||
t, registered.addonId(), registered.callbackId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalize(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private record RegisteredRenderCallback(String addonId,
|
||||
String callbackId,
|
||||
LoVisualRenderCallback callback) {
|
||||
}
|
||||
|
||||
private record AddonPostProcessPass(String addonId,
|
||||
String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) implements PostProcessPass {
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return AddonManager.isActive(addonId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(GpuTextureView src, GpuTextureView dst, float tickDelta) {
|
||||
if (!isActive()) return false;
|
||||
try {
|
||||
return callback.render(new LoVisualPostProcessContext(addonId, passId, phase, src, dst, tickDelta));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Post-process callback failed: addon=%s id=%s", t, addonId, passId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Phase getPhase() {
|
||||
return phase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record AddonSnapshot(
|
||||
String id,
|
||||
String name,
|
||||
String version,
|
||||
String description,
|
||||
List<String> authors,
|
||||
String iconPath,
|
||||
int apiVersion,
|
||||
AddonStatus status,
|
||||
boolean enabled,
|
||||
boolean restartRequired,
|
||||
int modules,
|
||||
int draggableHudElements,
|
||||
int staticHudElements,
|
||||
int commands,
|
||||
int clickGuiSections,
|
||||
int moduleExtensions,
|
||||
int irisPatchManifests,
|
||||
List<AddonIssue> issues
|
||||
) {
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class AddonStateStore {
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private AddonStateStore() {
|
||||
}
|
||||
|
||||
static Map<String, Boolean> loadEnabledOverrides() {
|
||||
Path file = stateFile();
|
||||
if (!Files.isRegularFile(file)) return new HashMap<>();
|
||||
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
State state = GSON.fromJson(reader, State.class);
|
||||
if (state == null || state.enabled == null) return new HashMap<>();
|
||||
return new HashMap<>(state.enabled);
|
||||
} catch (Throwable ignored) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
static void saveEnabledOverrides(Map<String, Boolean> enabled) {
|
||||
Path file = stateFile();
|
||||
try {
|
||||
Files.createDirectories(file.getParent());
|
||||
State state = new State();
|
||||
state.enabled = new HashMap<>(enabled);
|
||||
try (Writer writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
|
||||
GSON.toJson(state, writer);
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static Path stateFile() {
|
||||
return FabricLoader.getInstance().getConfigDir()
|
||||
.resolve("combatant")
|
||||
.resolve("addons.json");
|
||||
}
|
||||
|
||||
private static final class State {
|
||||
Map<String, Boolean> enabled = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
public enum AddonStatus {
|
||||
DISCOVERED,
|
||||
DISABLED,
|
||||
ACTIVE,
|
||||
SUSPENDED,
|
||||
ERROR,
|
||||
SHUTDOWN
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiSection;
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiRenderContext;
|
||||
import dev.loki.lovisual.features.gui.clickgui.ClickGuiRenderer;
|
||||
import dev.loki.lovisual.features.gui.clickgui.sections.ClickGuiSection;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ClickGuiSectionManager {
|
||||
;
|
||||
|
||||
private static final Map<String, Entry> SECTIONS = new LinkedHashMap<>();
|
||||
|
||||
public static synchronized boolean register(String addonId,
|
||||
String sectionId,
|
||||
String label,
|
||||
LoVisualClickGuiSection section) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
String normalizedSectionId = normalize(sectionId);
|
||||
if (normalizedAddonId.isBlank() || normalizedSectionId.isBlank() || section == null) {
|
||||
return false;
|
||||
}
|
||||
String id = normalizedAddonId + ":" + normalizedSectionId;
|
||||
if (SECTIONS.containsKey(id)) {
|
||||
return false;
|
||||
}
|
||||
String title = label == null || label.isBlank() ? normalizedSectionId : label.trim();
|
||||
SECTIONS.put(id, new Entry(
|
||||
normalizedAddonId,
|
||||
id,
|
||||
normalizedSectionId,
|
||||
title,
|
||||
new AddonSectionAdapter(section)
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static synchronized void unregisterAddon(String addonId) {
|
||||
String normalizedAddonId = normalize(addonId);
|
||||
SECTIONS.entrySet().removeIf(entry -> {
|
||||
if (!entry.getValue().addonId().equals(normalizedAddonId)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
entry.getValue().section().onDeselected();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public static synchronized List<Entry> sections() {
|
||||
return SECTIONS.values().stream()
|
||||
.filter(entry -> AddonManager.isActive(entry.addonId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value == null ? "" : value.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public record Entry(String addonId,
|
||||
String id,
|
||||
String localId,
|
||||
String label,
|
||||
ClickGuiSection section) {
|
||||
}
|
||||
|
||||
private record AddonSectionAdapter(LoVisualClickGuiSection section) implements ClickGuiSection {
|
||||
@Override
|
||||
public void layout(float x, float y, float w, float h) {
|
||||
section.layout(x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float mouseX, float mouseY) {
|
||||
section.render(
|
||||
new LoVisualClickGuiRenderContext(
|
||||
ClickGuiRenderer.currentRenderer(),
|
||||
ClickGuiRenderer.getInterRegular(),
|
||||
ClickGuiRenderer.getInterMedium()
|
||||
),
|
||||
mouseX,
|
||||
mouseY
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderGlassPass(float alphaFactor) {
|
||||
section.renderGlassPass(alphaFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(float mouseX, float mouseY, int button) {
|
||||
return section.mousePressed(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(float mouseX, float mouseY, int button) {
|
||||
section.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(float mouseX, float mouseY, double amount) {
|
||||
return section.mouseScrolled(mouseX, mouseY, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return section.keyPressed(keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean charTyped(char chr, int modifiers) {
|
||||
return section.charTyped(chr, modifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelected() {
|
||||
section.onSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeselected() {
|
||||
section.onDeselected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return section.isVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddonContext;
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiSection;
|
||||
import dev.loki.lovisual.api.v0.client.LoVisualClientApi;
|
||||
import dev.loki.lovisual.api.v0.module.LoVisualModuleExtension;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandManager;
|
||||
import dev.loki.lovisual.features.gui.hud.AbstractHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import dev.loki.lovisual.features.gui.hud.nondraggable.StaticHudElementRegistry;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.render.engine.pipeline.CombatantRenderPipelines;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import dev.loki.lovisual.render.iris.patch.ShaderPatchEngine;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
final class LoVisualAddonContextImpl implements LoVisualAddonContext {
|
||||
private final AddonRegistration registration;
|
||||
|
||||
LoVisualAddonContextImpl(AddonRegistration registration) {
|
||||
this.registration = registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return registration.descriptor.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoVisualClientApi client() {
|
||||
return LoVisualClientApi.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModContainer modContainer() {
|
||||
return registration.entrypoint.getProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path gameDir() {
|
||||
return FabricLoader.getInstance().getGameDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path configDir() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path addonConfigDir() {
|
||||
return configDir().resolve("lovisual").resolve("addons").resolve(addonId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModule(Module module) {
|
||||
if (module == null) return;
|
||||
module.postInit();
|
||||
registration.modules.add(module.name());
|
||||
AddonManager.noteModuleOwner(addonId(), module.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDraggableHudElement(DraggableHudElement element) {
|
||||
if (element == null) return;
|
||||
DraggableHudElementRegistry.register(element);
|
||||
registration.draggableHudElements.add(element.getId());
|
||||
AddonManager.noteDraggableHudOwner(addonId(), element.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStaticHudElement(AbstractHudElement element) {
|
||||
if (element == null) return;
|
||||
StaticHudElementRegistry.register(element);
|
||||
registration.staticHudElements.add(element.getId());
|
||||
AddonManager.noteStaticHudOwner(addonId(), element.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(ClientCommand command) {
|
||||
if (command == null) return;
|
||||
CommandManager.register(new AddonClientCommand(addonId(), command));
|
||||
registration.commands.add(command.metadata().id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClickGuiSection(String sectionId, String label, LoVisualClickGuiSection section) {
|
||||
if (ClickGuiSectionManager.register(addonId(), sectionId, label, section)) {
|
||||
registration.clickGuiSections.add(sectionId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "ClickGui section registration failed", sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModuleExtension(String moduleId, LoVisualModuleExtension extension) {
|
||||
if (ModuleExtensionManager.register(addonId(), moduleId, extension)) {
|
||||
registration.moduleExtensions.add(moduleId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Module extension target is unavailable", moduleId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIrisShaderPatchManifest(String manifestResourcePath) {
|
||||
if (ShaderPatchEngine.registerManifestResource(manifestResourcePath)) {
|
||||
registration.irisPatchManifests.add(manifestResourcePath);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Iris patch manifest registration failed", manifestResourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRenderCallback(String callbackId, LoVisualRenderStage stage, LoVisualRenderCallback callback) {
|
||||
if (AddonRenderPipelineManager.register(addonId(), callbackId, stage, callback)) {
|
||||
registration.renderCallbacks.add(stage.name().toLowerCase(java.util.Locale.ROOT) + ":" + callbackId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Render callback registration failed", callbackId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPostProcessPass(String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
int priority,
|
||||
LoVisualPostProcessCallback callback) {
|
||||
if (AddonRenderPipelineManager.registerPostProcess(addonId(), passId, phase, priority, callback)) {
|
||||
registration.postProcessPasses.add(phase.name().toLowerCase(java.util.Locale.ROOT) + ":" + passId);
|
||||
} else {
|
||||
registration.issue(AddonIssue.Severity.WARNING, "Post-process registration failed", passId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RenderPipeline registerRenderPipeline(RenderPipeline pipeline) {
|
||||
if (pipeline == null) return null;
|
||||
RenderPipeline registered = CombatantRenderPipelines.registerAddonPipeline(pipeline);
|
||||
registration.renderCallbacks.add("pipeline:" + pipeline.getLocation());
|
||||
return registered;
|
||||
}
|
||||
|
||||
private record AddonClientCommand(String addonId, ClientCommand delegate) implements ClientCommand {
|
||||
@Override
|
||||
public dev.loki.lovisual.features.command.CommandMetadata metadata() {
|
||||
return delegate.metadata();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String name() {
|
||||
return delegate.name();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public java.util.List<String> aliases() {
|
||||
return delegate.aliases();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String usage() {
|
||||
return delegate.usage();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public String description() {
|
||||
return delegate.description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return AddonManager.isActive(addonId) && delegate.isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> suggest(dev.loki.lovisual.features.command.CommandContext ctx, int argIndex, String token) {
|
||||
return delegate.suggest(ctx, argIndex, token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(dev.loki.lovisual.features.command.CommandContext ctx) {
|
||||
return isAvailable() && delegate.execute(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualAddonRuntimeContext;
|
||||
import dev.loki.lovisual.api.v0.client.LoVisualClientApi;
|
||||
|
||||
final class LoVisualAddonRuntimeContextImpl implements LoVisualAddonRuntimeContext {
|
||||
private final String addonId;
|
||||
|
||||
LoVisualAddonRuntimeContextImpl(String addonId) {
|
||||
this.addonId = addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoVisualClientApi client() {
|
||||
return LoVisualClientApi.get();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.addon.LoVisualModuleLoadContext;
|
||||
import dev.loki.lovisual.features.module.ModuleAutoLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class LoVisualModuleLoadContextImpl implements LoVisualModuleLoadContext {
|
||||
private final AddonRegistration registration;
|
||||
private final List<String> pendingExclusions = new ArrayList<>();
|
||||
|
||||
LoVisualModuleLoadContextImpl(AddonRegistration registration) {
|
||||
this.registration = registration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return registration.descriptor.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean disableBuiltInModule(String moduleReference) {
|
||||
String reference = moduleReference == null ? "" : moduleReference.trim();
|
||||
if (reference.isEmpty()) return false;
|
||||
|
||||
if (!ModuleAutoLoader.acceptsDisableRequests()) {
|
||||
noteRestartRequired(reference);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pendingExclusions.contains(reference)) {
|
||||
pendingExclusions.add(reference);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void commit() {
|
||||
for (String reference : pendingExclusions) {
|
||||
if (!registration.disabledBuiltInModules.contains(reference)) {
|
||||
registration.disabledBuiltInModules.add(reference);
|
||||
}
|
||||
if (!ModuleAutoLoader.requestDisable(reference, addonId())) {
|
||||
noteRestartRequired(reference);
|
||||
}
|
||||
}
|
||||
pendingExclusions.clear();
|
||||
}
|
||||
|
||||
private void noteRestartRequired(String reference) {
|
||||
if (!registration.disabledBuiltInModules.contains(reference)) {
|
||||
registration.disabledBuiltInModules.add(reference);
|
||||
}
|
||||
registration.restartRequired = true;
|
||||
registration.issue(
|
||||
AddonIssue.Severity.WARNING,
|
||||
"Built-in module exclusion requires restart",
|
||||
reference
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.module.ModuleExtensionContext;
|
||||
import dev.loki.lovisual.config.SettingDef;
|
||||
import dev.loki.lovisual.config.values.ConfigValue;
|
||||
import dev.loki.lovisual.config.values.ModeValue;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
final class ModuleExtensionContextImpl implements ModuleExtensionContext {
|
||||
private final String addonId;
|
||||
private final Module module;
|
||||
|
||||
ModuleExtensionContextImpl(String addonId, Module module) {
|
||||
this.addonId = addonId;
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addonId() {
|
||||
return addonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String moduleId() {
|
||||
return module.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module module() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSetting(SettingDef setting) {
|
||||
module.addExtensionSetting(setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigValue<?> getConfigValue(String configName) {
|
||||
return module.getConfigValue(configName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addModeOption(String configName, String option) {
|
||||
ConfigValue<?> value = getConfigValue(configName);
|
||||
return value instanceof ModeValue mode && mode.addOption(option);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.module.LoVisualModuleExtension;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ModuleExtensionManager {
|
||||
;
|
||||
|
||||
private static final Map<String, List<RegisteredExtension>> EXTENSIONS = new LinkedHashMap<>();
|
||||
|
||||
public static boolean register(String addonId, String moduleId, LoVisualModuleExtension extension) {
|
||||
if (extension == null || moduleId == null || moduleId.isBlank()) return false;
|
||||
Module module = ModuleManager.get(moduleId);
|
||||
if (module == null) {
|
||||
DebugLog.warn("[Addons] Module extension target missing: addon=%s module=%s", addonId, moduleId);
|
||||
return false;
|
||||
}
|
||||
String normalized = normalize(moduleId);
|
||||
RegisteredExtension registered = new RegisteredExtension(addonId, extension);
|
||||
EXTENSIONS.computeIfAbsent(normalized, ignored -> new ArrayList<>()).add(registered);
|
||||
try {
|
||||
extension.onRegister(new ModuleExtensionContextImpl(addonId, module));
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension registration failed: %s", t, normalized);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int count() {
|
||||
int count = 0;
|
||||
for (List<RegisteredExtension> list : EXTENSIONS.values()) {
|
||||
count += list.size();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static boolean beforeEnable(Module module) {
|
||||
return all(module, extension -> extension.beforeEnable(module));
|
||||
}
|
||||
|
||||
public static void afterEnable(Module module) {
|
||||
each(module, extension -> extension.afterEnable(module));
|
||||
}
|
||||
|
||||
public static boolean beforeDisable(Module module) {
|
||||
return all(module, extension -> extension.beforeDisable(module));
|
||||
}
|
||||
|
||||
public static void afterDisable(Module module) {
|
||||
each(module, extension -> extension.afterDisable(module));
|
||||
}
|
||||
|
||||
public static boolean beforeTick(Module module) {
|
||||
return all(module, extension -> extension.beforeTick(module));
|
||||
}
|
||||
|
||||
public static void afterTick(Module module) {
|
||||
each(module, extension -> extension.afterTick(module));
|
||||
}
|
||||
|
||||
public static boolean beforeFrame(Module module, float frameDeltaTicks) {
|
||||
return all(module, extension -> extension.beforeFrame(module, frameDeltaTicks));
|
||||
}
|
||||
|
||||
public static void afterFrame(Module module, float frameDeltaTicks) {
|
||||
each(module, extension -> extension.afterFrame(module, frameDeltaTicks));
|
||||
}
|
||||
|
||||
public static boolean beforeHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
return all(module, extension -> extension.beforeHudRender(module, renderer, textRenderer, ctx, tickDelta));
|
||||
}
|
||||
|
||||
public static void afterHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
each(module, extension -> extension.afterHudRender(module, renderer, textRenderer, ctx, tickDelta));
|
||||
}
|
||||
|
||||
public static boolean beforeWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
return all(module, extension -> extension.beforeWorldRender(module, renderer, depthRenderer, tickDelta));
|
||||
}
|
||||
|
||||
public static void afterWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
each(module, extension -> extension.afterWorldRender(module, renderer, depthRenderer, tickDelta));
|
||||
}
|
||||
|
||||
private static boolean all(Module module, ExtensionBooleanCall call) {
|
||||
List<RegisteredExtension> extensions = extensions(module);
|
||||
if (extensions.isEmpty()) return true;
|
||||
boolean proceed = true;
|
||||
for (RegisteredExtension registered : extensions) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
proceed &= call.invoke(registered.extension());
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension hook failed: addon=%s module=%s",
|
||||
t, registered.addonId(), module == null ? "" : module.name());
|
||||
}
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
|
||||
private static void each(Module module, ExtensionVoidCall call) {
|
||||
List<RegisteredExtension> extensions = extensions(module);
|
||||
if (extensions.isEmpty()) return;
|
||||
for (RegisteredExtension registered : extensions) {
|
||||
if (!AddonManager.isActive(registered.addonId())) continue;
|
||||
try {
|
||||
call.invoke(registered.extension());
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("[Addons] Module extension hook failed: addon=%s module=%s",
|
||||
t, registered.addonId(), module == null ? "" : module.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<RegisteredExtension> extensions(Module module) {
|
||||
if (module == null) return List.of();
|
||||
List<RegisteredExtension> list = EXTENSIONS.get(normalize(module.name()));
|
||||
return list == null ? List.of() : List.copyOf(list);
|
||||
}
|
||||
|
||||
private static String normalize(String id) {
|
||||
return id == null ? "" : id.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface ExtensionBooleanCall {
|
||||
boolean invoke(LoVisualModuleExtension extension);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface ExtensionVoidCall {
|
||||
void invoke(LoVisualModuleExtension extension);
|
||||
}
|
||||
|
||||
private record RegisteredExtension(String addonId, LoVisualModuleExtension extension) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.addon;
|
||||
|
||||
/**
|
||||
* Fabric entrypoint contract for Combatant addons.
|
||||
*
|
||||
* <p>Declare it in fabric.mod.json under the {@value #ENTRYPOINT_KEY} entrypoint.
|
||||
*/
|
||||
public interface LoVisualAddon {
|
||||
String ENTRYPOINT_KEY = "combatant:addon";
|
||||
int API_VERSION = 0;
|
||||
|
||||
/**
|
||||
* Called before LoVisual auto-loads its built-in modules.
|
||||
*
|
||||
* <p>Use this hook only for startup module exclusions. Normal addon registration
|
||||
* still belongs in {@link #onInitialize(LoVisualAddonContext)}.</p>
|
||||
*/
|
||||
default void onConfigureModules(LoVisualModuleLoadContext context) {
|
||||
}
|
||||
|
||||
void onInitialize(LoVisualAddonContext context);
|
||||
|
||||
/**
|
||||
* Called after all built-in and addon module configs have been loaded and applied.
|
||||
* This is the safe startup hook for mutating settings of existing modules.
|
||||
*/
|
||||
default void onClientReady(LoVisualAddonRuntimeContext context) {
|
||||
}
|
||||
|
||||
default void onRuntimeSuspended(LoVisualAddonRuntimeContext context) {
|
||||
}
|
||||
|
||||
default void onRuntimeResumed(LoVisualAddonRuntimeContext context) {
|
||||
}
|
||||
|
||||
default void onShutdown(LoVisualAddonRuntimeContext context) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.addon;
|
||||
|
||||
import dev.loki.lovisual.events.UsedImplicitly;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.api.v0.clickgui.LoVisualClickGuiSection;
|
||||
import dev.loki.lovisual.features.gui.hud.AbstractHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.api.v0.module.LoVisualModuleExtension;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualPostProcessCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderCallback;
|
||||
import dev.loki.lovisual.api.v0.render.LoVisualRenderStage;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface LoVisualAddonContext extends LoVisualAddonRuntimeContext {
|
||||
@UsedImplicitly
|
||||
ModContainer modContainer();
|
||||
@UsedImplicitly
|
||||
Path gameDir();
|
||||
|
||||
Path configDir();
|
||||
@UsedImplicitly
|
||||
Path addonConfigDir();
|
||||
@UsedImplicitly
|
||||
void registerModule(Module module);
|
||||
@UsedImplicitly
|
||||
void registerDraggableHudElement(DraggableHudElement element);
|
||||
@UsedImplicitly
|
||||
void registerStaticHudElement(AbstractHudElement element);
|
||||
@UsedImplicitly
|
||||
void registerCommand(ClientCommand command);
|
||||
@UsedImplicitly
|
||||
void registerClickGuiSection(String sectionId, String label, LoVisualClickGuiSection section);
|
||||
@UsedImplicitly
|
||||
void registerModuleExtension(String moduleId, LoVisualModuleExtension extension);
|
||||
@UsedImplicitly
|
||||
void registerIrisShaderPatchManifest(String manifestResourcePath);
|
||||
@UsedImplicitly
|
||||
void registerRenderCallback(String callbackId, LoVisualRenderStage stage, LoVisualRenderCallback callback);
|
||||
@UsedImplicitly
|
||||
void registerPostProcessPass(String passId, PostProcessPass.Phase phase, int priority, LoVisualPostProcessCallback callback);
|
||||
@UsedImplicitly
|
||||
RenderPipeline registerRenderPipeline(RenderPipeline pipeline);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.addon;
|
||||
|
||||
import dev.loki.lovisual.api.v0.client.LoVisualClientApi;
|
||||
|
||||
public interface LoVisualAddonRuntimeContext {
|
||||
String addonId();
|
||||
|
||||
LoVisualClientApi client();
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.addon;
|
||||
|
||||
import dev.loki.lovisual.events.UsedImplicitly;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
/**
|
||||
* Early addon context used before Combatant's built-in modules are instantiated.
|
||||
*
|
||||
* <p>Only enabled addons receive this callback. Exclusions are startup-only: changing
|
||||
* an addon's enabled state after module discovery requires a client restart for the
|
||||
* built-in module set to be rebuilt.</p>
|
||||
*/
|
||||
public interface LoVisualModuleLoadContext {
|
||||
@UsedImplicitly
|
||||
String addonId();
|
||||
|
||||
/**
|
||||
* Prevents an auto-loaded built-in module from being instantiated.
|
||||
*
|
||||
* <p>The reference may be a {@code ModuleInfo.id}, module alias, simple class name,
|
||||
* or fully-qualified class name.</p>
|
||||
*
|
||||
* @return {@code true} when the exclusion was accepted for the current startup;
|
||||
* {@code false} when the reference is invalid or module discovery has already started
|
||||
*/
|
||||
@UsedImplicitly
|
||||
boolean disableBuiltInModule(String moduleReference);
|
||||
|
||||
/**
|
||||
* Class-based convenience overload for addons that directly depend on a built-in module type.
|
||||
*/
|
||||
@UsedImplicitly
|
||||
default boolean disableBuiltInModule(Class<? extends Module> moduleType) {
|
||||
return moduleType != null && disableBuiltInModule(moduleType.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.clickgui;
|
||||
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
|
||||
public record LoVisualClickGuiRenderContext(
|
||||
Renderer2D renderer,
|
||||
TextRenderer regularFont,
|
||||
TextRenderer mediumFont
|
||||
) {
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.clickgui;
|
||||
|
||||
public interface LoVisualClickGuiSection {
|
||||
default void layout(float x, float y, float w, float h) {
|
||||
}
|
||||
|
||||
default void render(LoVisualClickGuiRenderContext context, float mouseX, float mouseY) {
|
||||
}
|
||||
|
||||
default void renderGlassPass(float alphaFactor) {
|
||||
}
|
||||
|
||||
default boolean mousePressed(float mouseX, float mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void mouseReleased(float mouseX, float mouseY, int button) {
|
||||
}
|
||||
|
||||
default boolean mouseScrolled(float mouseX, float mouseY, double amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean charTyped(char chr, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void onSelected() {
|
||||
}
|
||||
|
||||
default void onDeselected() {
|
||||
}
|
||||
|
||||
default boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.client;
|
||||
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class LoVisualClientApi {
|
||||
private static final LoVisualClientApi INSTANCE = new LoVisualClientApi();
|
||||
|
||||
private LoVisualClientApi() {
|
||||
}
|
||||
|
||||
public static LoVisualClientApi get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public List<Module> modules() {
|
||||
return ModuleManager.getModules();
|
||||
}
|
||||
|
||||
public Module module(String id) {
|
||||
return ModuleManager.get(id);
|
||||
}
|
||||
|
||||
public boolean isModuleEnabled(String id) {
|
||||
return ModuleManager.isEnabled(id);
|
||||
}
|
||||
|
||||
public void setModuleEnabled(String id, boolean enabled) {
|
||||
ModuleManager.setEnabled(id, enabled);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.module;
|
||||
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
public interface LoVisualModuleExtension {
|
||||
default void onRegister(ModuleExtensionContext context) {
|
||||
}
|
||||
|
||||
default boolean beforeEnable(Module module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterEnable(Module module) {
|
||||
}
|
||||
|
||||
default boolean beforeDisable(Module module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterDisable(Module module) {
|
||||
}
|
||||
|
||||
default boolean beforeTick(Module module) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterTick(Module module) {
|
||||
}
|
||||
|
||||
default boolean beforeFrame(Module module, float frameDeltaTicks) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterFrame(Module module, float frameDeltaTicks) {
|
||||
}
|
||||
|
||||
default boolean beforeHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterHudRender(Module module,
|
||||
Renderer2D renderer,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor ctx,
|
||||
float tickDelta) {
|
||||
}
|
||||
|
||||
default boolean beforeWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void afterWorldRender(Module module,
|
||||
Renderer3D renderer,
|
||||
Renderer3D depthRenderer,
|
||||
float tickDelta) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.module;
|
||||
|
||||
import dev.loki.lovisual.config.SettingDef;
|
||||
import dev.loki.lovisual.config.values.ConfigValue;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
public interface ModuleExtensionContext {
|
||||
String addonId();
|
||||
|
||||
String moduleId();
|
||||
|
||||
Module module();
|
||||
|
||||
void addSetting(SettingDef setting);
|
||||
|
||||
ConfigValue<?> getConfigValue(String configName);
|
||||
|
||||
boolean addModeOption(String configName, String option);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface LoVisualPostProcessCallback {
|
||||
boolean render(LoVisualPostProcessContext context);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
import com.mojang.blaze3d.textures.GpuTextureView;
|
||||
import dev.loki.lovisual.render.engine.postprocess.PostProcessPass;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public record LoVisualPostProcessContext(
|
||||
String addonId,
|
||||
String passId,
|
||||
PostProcessPass.Phase phase,
|
||||
GpuTextureView source,
|
||||
GpuTextureView destination,
|
||||
float tickDelta
|
||||
) {
|
||||
public Minecraft client() {
|
||||
return Minecraft.getInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface LoVisualRenderCallback {
|
||||
void render(LoVisualRenderContext context);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.loki.lovisual.features.module.HudPhase;
|
||||
import dev.loki.lovisual.features.module.WorldPhase;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer2D;
|
||||
import dev.loki.lovisual.render.engine.renderer.Renderer3D;
|
||||
import dev.loki.lovisual.render.engine.text.TextRenderer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphicsExtractor;
|
||||
|
||||
public record LoVisualRenderContext(
|
||||
String addonId,
|
||||
String callbackId,
|
||||
LoVisualRenderStage stage,
|
||||
HudPhase hudPhase,
|
||||
WorldPhase worldPhase,
|
||||
Renderer2D renderer2D,
|
||||
Renderer3D renderer3D,
|
||||
Renderer3D depthRenderer3D,
|
||||
TextRenderer textRenderer,
|
||||
GuiGraphicsExtractor guiContext,
|
||||
PoseStack poseStack,
|
||||
float tickDelta
|
||||
) {
|
||||
public Minecraft client() {
|
||||
return Minecraft.getInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
import com.mojang.blaze3d.PrimitiveTopology;
|
||||
import com.mojang.blaze3d.pipeline.BlendFunction;
|
||||
import com.mojang.blaze3d.pipeline.RenderPipeline;
|
||||
import com.mojang.blaze3d.shaders.UniformType;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dev.loki.lovisual.render.engine.pipeline.CombatantRenderPipelines;
|
||||
import dev.loki.lovisual.render.engine.pipeline.DepthTestFunction;
|
||||
import dev.loki.lovisual.render.engine.pipeline.ExtendedRenderPipelineBuilder;
|
||||
import dev.loki.lovisual.render.engine.rhi.clip.ShapeClipRenderPassContract;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class LoVisualRenderPipelineBuilder {
|
||||
private final ExtendedRenderPipelineBuilder delegate;
|
||||
|
||||
private LoVisualRenderPipelineBuilder(RenderPipeline.Snippet... snippets) {
|
||||
this.delegate = new ExtendedRenderPipelineBuilder(snippets);
|
||||
}
|
||||
|
||||
public static LoVisualRenderPipelineBuilder create(RenderPipeline.Snippet... snippets) {
|
||||
return new LoVisualRenderPipelineBuilder(snippets);
|
||||
}
|
||||
|
||||
public static RenderPipeline.Snippet meshUniforms() {
|
||||
return CombatantRenderPipelines.meshUniforms();
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder location(Identifier id) {
|
||||
delegate.withLocation(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder vertexFormat(VertexFormat format, PrimitiveTopology mode) {
|
||||
delegate.withVertexFormat(format, mode);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder vertexShader(Identifier id) {
|
||||
delegate.withVertexShader(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder fragmentShader(Identifier id) {
|
||||
delegate.withFragmentShader(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder depthTest(DepthTestFunction function) {
|
||||
delegate.withDepthTestFunction(function);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder depthWrite(boolean write) {
|
||||
delegate.withDepthWrite(write);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder blend(BlendFunction blend) {
|
||||
delegate.withBlend(blend);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder cull(boolean cull) {
|
||||
delegate.withCull(cull);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder sampler(String name) {
|
||||
delegate.withSampler(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder uniform(String name, UniformType type) {
|
||||
delegate.withUniform(name, type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder lineSmooth() {
|
||||
delegate.withLineSmooth();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder shapeClipSupport() {
|
||||
delegate.withShapeClipSupport();
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoVisualRenderPipelineBuilder shapeClipContract(ShapeClipRenderPassContract contract) {
|
||||
delegate.withShapeClipContract(contract);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderPipeline build() {
|
||||
return delegate.build();
|
||||
}
|
||||
|
||||
public RenderPipeline buildAndRegister() {
|
||||
return CombatantRenderPipelines.registerAddonPipeline(build());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
public enum LoVisualRenderStage {
|
||||
HUD_RAW,
|
||||
HUD_SCALED,
|
||||
HUD_LOGICAL,
|
||||
HUD_RAW_FOREGROUND,
|
||||
HUD_SCALED_FOREGROUND,
|
||||
HUD_LOGICAL_FOREGROUND,
|
||||
WORLD_BEFORE_TRANSLUCENT,
|
||||
WORLD_END_MAIN,
|
||||
WORLD_POST_PROCESS,
|
||||
SCREEN_BEFORE_VANILLA_GUI,
|
||||
SCREEN_AFTER_VANILLA_GUI
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.api.v0.render;
|
||||
|
||||
import com.mojang.blaze3d.buffers.GpuBufferSlice;
|
||||
import dev.loki.lovisual.render.engine.core.CombatantRenderSystem;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum LoVisualUniforms {
|
||||
;
|
||||
|
||||
public static GpuBufferSlice write(String name,
|
||||
int std140Size,
|
||||
int expectedWritesPerFrame,
|
||||
UniformWriter writer) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new IllegalArgumentException("Uniform name cannot be blank");
|
||||
}
|
||||
if (std140Size <= 0) {
|
||||
throw new IllegalArgumentException("Uniform std140 size must be positive");
|
||||
}
|
||||
if (writer == null) {
|
||||
throw new IllegalArgumentException("Uniform writer cannot be null");
|
||||
}
|
||||
return CombatantRenderSystem.uniforms().write(name, std140Size, expectedWritesPerFrame, writer::write);
|
||||
}
|
||||
|
||||
public static GpuBufferSlice writeCached(String name,
|
||||
int std140Size,
|
||||
int expectedWritesPerFrame,
|
||||
int updateEveryFrames,
|
||||
boolean force,
|
||||
UniformWriter writer) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new IllegalArgumentException("Uniform name cannot be blank");
|
||||
}
|
||||
if (std140Size <= 0) {
|
||||
throw new IllegalArgumentException("Uniform std140 size must be positive");
|
||||
}
|
||||
if (writer == null) {
|
||||
throw new IllegalArgumentException("Uniform writer cannot be null");
|
||||
}
|
||||
return CombatantRenderSystem.uniforms().writeCached(
|
||||
name,
|
||||
std140Size,
|
||||
expectedWritesPerFrame,
|
||||
updateEveryFrames,
|
||||
force,
|
||||
writer::write
|
||||
);
|
||||
}
|
||||
|
||||
public static GpuBufferSlice current(String name) {
|
||||
if (name == null || name.isBlank()) return null;
|
||||
return CombatantRenderSystem.uniforms().current(name);
|
||||
}
|
||||
|
||||
public static void invalidate(String name) {
|
||||
if (name == null || name.isBlank()) return;
|
||||
CombatantRenderSystem.uniforms().invalidate(name);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface UniformWriter {
|
||||
void write(ByteBuffer buffer);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xaero.common.minimap.waypoints.Waypoint;
|
||||
import xaero.hud.minimap.waypoint.WaypointColor;
|
||||
import xaero.hud.minimap.waypoint.WaypointPurpose;
|
||||
|
||||
public enum TriangulatorXaeroMinimapCompat {
|
||||
;
|
||||
private static Waypoint hudWaypoint;
|
||||
private static Waypoint minimapWaypoint;
|
||||
private static boolean hudActive;
|
||||
private static boolean minimapActive;
|
||||
|
||||
@Nullable
|
||||
public static Waypoint getHudWaypoint() {
|
||||
sync();
|
||||
return hudActive ? hudWaypoint : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Waypoint getMinimapWaypoint() {
|
||||
sync();
|
||||
return minimapActive ? minimapWaypoint : null;
|
||||
}
|
||||
|
||||
private static void sync() {
|
||||
TriangulatorXaeroState.XaeroSnapshot snapshot = TriangulatorXaeroState.snapshot();
|
||||
if (snapshot == null) {
|
||||
hudActive = false;
|
||||
minimapActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
TriangulatorXaeroState.SyncPoint point = TriangulatorXaeroState.toCurrentDimension(snapshot);
|
||||
WaypointColor color = snapshot.ready() ? WaypointColor.GOLD : WaypointColor.RED;
|
||||
|
||||
hudWaypoint = syncWaypoint(hudWaypoint, point, color);
|
||||
minimapWaypoint = syncWaypoint(minimapWaypoint, point, color);
|
||||
hudActive = true;
|
||||
minimapActive = true;
|
||||
}
|
||||
|
||||
private static Waypoint syncWaypoint(@Nullable Waypoint waypoint,
|
||||
TriangulatorXaeroState.SyncPoint point,
|
||||
WaypointColor color) {
|
||||
Waypoint result = waypoint;
|
||||
if (result == null) {
|
||||
result = new Waypoint(
|
||||
point.x(),
|
||||
point.y(),
|
||||
point.z(),
|
||||
TriangulatorXaeroState.NAME,
|
||||
TriangulatorXaeroState.SYMBOL,
|
||||
color,
|
||||
WaypointPurpose.NORMAL
|
||||
);
|
||||
result.setTemporary(false);
|
||||
result.setYIncluded(false);
|
||||
}
|
||||
result.setX(point.x());
|
||||
result.setY(point.y());
|
||||
result.setZ(point.z());
|
||||
result.setWaypointColor(color);
|
||||
result.setDisabled(false);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElement;
|
||||
import dev.loki.lovisual.features.gui.hud.draggable.DraggableHudElementRegistry;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public enum TriangulatorXaeroState {
|
||||
;
|
||||
public static final String NAME = "Stronghold";
|
||||
public static final String SYMBOL = "S";
|
||||
public static final String SET = "combatant";
|
||||
public static final int DEFAULT_Y = 64;
|
||||
|
||||
@Nullable
|
||||
public static XaeroSnapshot snapshot() {
|
||||
DraggableHudElement triangulator = DraggableHudElementRegistry.getById("triangulator");
|
||||
if (triangulator == null) return null;
|
||||
try {
|
||||
Object raw = triangulator.getClass().getMethod("getXaeroSnapshot").invoke(triangulator);
|
||||
if (raw == null) return null;
|
||||
return new XaeroSnapshot(
|
||||
readDouble(raw, "overworldX"),
|
||||
readDouble(raw, "overworldZ"),
|
||||
readBoolean(raw, "ready"),
|
||||
readDouble(raw, "confidence"),
|
||||
readInt(raw, "eyeCount")
|
||||
);
|
||||
} catch (ReflectiveOperationException | ClassCastException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static SyncPoint toCurrentDimension(XaeroSnapshot snapshot) {
|
||||
boolean nether = isNetherView();
|
||||
double factor = nether ? 0.125 : 1.0;
|
||||
return new SyncPoint(
|
||||
(int) Math.round(snapshot.overworldX() * factor),
|
||||
DEFAULT_Y,
|
||||
(int) Math.round(snapshot.overworldZ() * factor)
|
||||
);
|
||||
}
|
||||
|
||||
public static boolean isNetherView() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
return mc != null && mc.level != null && mc.level.dimension() == Level.NETHER;
|
||||
}
|
||||
|
||||
private static double readDouble(Object target, String method) throws ReflectiveOperationException {
|
||||
Object value = invoke(target, method);
|
||||
if (value instanceof Number number) return number.doubleValue();
|
||||
throw new ClassCastException(method);
|
||||
}
|
||||
|
||||
private static boolean readBoolean(Object target, String method) throws ReflectiveOperationException {
|
||||
Object value = invoke(target, method);
|
||||
if (value instanceof Boolean bool) return bool;
|
||||
throw new ClassCastException(method);
|
||||
}
|
||||
|
||||
private static int readInt(Object target, String method) throws ReflectiveOperationException {
|
||||
Object value = invoke(target, method);
|
||||
if (value instanceof Number number) return number.intValue();
|
||||
throw new ClassCastException(method);
|
||||
}
|
||||
|
||||
private static Object invoke(Object target, String method) throws ReflectiveOperationException {
|
||||
Method accessor = target.getClass().getMethod(method);
|
||||
return accessor.invoke(target);
|
||||
}
|
||||
|
||||
public record XaeroSnapshot(double overworldX, double overworldZ, boolean ready, double confidence, int eyeCount) {
|
||||
}
|
||||
|
||||
public record SyncPoint(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xaero.common.minimap.waypoints.Waypoint;
|
||||
import xaero.hud.minimap.waypoint.WaypointColor;
|
||||
import xaero.hud.minimap.waypoint.WaypointPurpose;
|
||||
import xaero.map.mods.SupportXaeroMinimap;
|
||||
|
||||
public enum TriangulatorXaeroWorldMapCompat {
|
||||
;
|
||||
|
||||
@Nullable
|
||||
public static xaero.map.mods.gui.Waypoint getWaypoint(SupportXaeroMinimap minimap) {
|
||||
TriangulatorXaeroState.XaeroSnapshot snapshot = TriangulatorXaeroState.snapshot();
|
||||
if (snapshot == null || minimap == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Waypoint baseWaypoint = new Waypoint(
|
||||
(int) Math.round(snapshot.overworldX()),
|
||||
TriangulatorXaeroState.DEFAULT_Y,
|
||||
(int) Math.round(snapshot.overworldZ()),
|
||||
TriangulatorXaeroState.NAME,
|
||||
TriangulatorXaeroState.SYMBOL,
|
||||
snapshot.ready() ? WaypointColor.GOLD : WaypointColor.RED,
|
||||
WaypointPurpose.NORMAL
|
||||
);
|
||||
baseWaypoint.setTemporary(false);
|
||||
baseWaypoint.setYIncluded(false);
|
||||
baseWaypoint.setDisabled(false);
|
||||
return minimap.convertWaypoint(baseWaypoint, false, TriangulatorXaeroState.SET, minimap.getDimDiv());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xaero.common.minimap.waypoints.Waypoint;
|
||||
import xaero.map.mods.SupportXaeroMinimap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Kept as a no-op compatibility bridge for older mixin code paths.
|
||||
* @xwp markers are now inserted into Xaero's real waypoint sets by {@link XaeroWaypointRuntime},
|
||||
* otherwise World Map/minimap hover, open and delete logic cannot see them.
|
||||
*/
|
||||
public enum XaeroCommandWaypointCompat {
|
||||
;
|
||||
|
||||
public static List<Waypoint> getMinimapWaypoints() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public static List<xaero.map.mods.gui.Waypoint> getWorldMapWaypoints(@Nullable SupportXaeroMinimap minimap) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.Level;
|
||||
import xaero.common.HudMod;
|
||||
import xaero.common.minimap.waypoints.Waypoint;
|
||||
import xaero.hud.minimap.BuiltInHudModules;
|
||||
import xaero.hud.minimap.module.MinimapSession;
|
||||
import xaero.hud.minimap.waypoint.WaypointColor;
|
||||
import xaero.hud.minimap.waypoint.WaypointPurpose;
|
||||
import xaero.hud.minimap.waypoint.set.WaypointSet;
|
||||
import xaero.hud.minimap.world.MinimapWorld;
|
||||
import xaero.hud.minimap.world.MinimapWorldManager;
|
||||
import xaero.hud.path.XaeroPath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class XaeroWaypointRuntime {
|
||||
private XaeroWaypointRuntime() {
|
||||
}
|
||||
|
||||
static XaeroWaypointStore.RuntimeAddResult addFromCurrentDimension(int x,
|
||||
int y,
|
||||
int z,
|
||||
String name,
|
||||
boolean dualDefault) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.level == null) {
|
||||
return fail("No client world is loaded.");
|
||||
}
|
||||
|
||||
MinimapSession session = currentSession();
|
||||
if (session == null) {
|
||||
return fail("Xaero minimap session is not ready.");
|
||||
}
|
||||
|
||||
List<XaeroWaypointStore.Marker> added = new ArrayList<>(2);
|
||||
ResourceKey<Level> currentDim = mc.level.dimension();
|
||||
boolean overworld = currentDim == Level.OVERWORLD;
|
||||
boolean nether = currentDim == Level.NETHER;
|
||||
|
||||
if (dualDefault && overworld) {
|
||||
addToWorld(session, Level.OVERWORLD, x, y, z, name, "overworld", added);
|
||||
addToWorld(session, Level.NETHER, XaeroWaypointStore.netherCoord(x), y, XaeroWaypointStore.netherCoord(z), name, "nether", added);
|
||||
return new XaeroWaypointStore.RuntimeAddResult(true,
|
||||
"Added dual Xaero marker: " + XaeroWaypointStore.format(x, y, z)
|
||||
+ " / Nether " + XaeroWaypointStore.format(XaeroWaypointStore.netherCoord(x), y, XaeroWaypointStore.netherCoord(z)) + ".",
|
||||
List.copyOf(added));
|
||||
}
|
||||
if (dualDefault && nether) {
|
||||
addToWorld(session, Level.NETHER, x, y, z, name, "nether", added);
|
||||
addToWorld(session, Level.OVERWORLD, x * 8, y, z * 8, name, "overworld", added);
|
||||
return new XaeroWaypointStore.RuntimeAddResult(true,
|
||||
"Added dual Xaero marker: Nether " + XaeroWaypointStore.format(x, y, z)
|
||||
+ " / Overworld " + XaeroWaypointStore.format(x * 8, y, z * 8) + ".",
|
||||
List.copyOf(added));
|
||||
}
|
||||
|
||||
addToWorld(session, currentDim, x, y, z, name, XaeroWaypointStore.dimensionId(currentDim.identifier()), added);
|
||||
return new XaeroWaypointStore.RuntimeAddResult(true,
|
||||
"Added Xaero marker: " + XaeroWaypointStore.format(x, y, z) + ".",
|
||||
List.copyOf(added));
|
||||
}
|
||||
|
||||
static boolean remove(XaeroWaypointStore.Marker marker) {
|
||||
if (!(marker.waypointSetHandle() instanceof WaypointSet set)
|
||||
|| !(marker.waypointHandle() instanceof Waypoint waypoint)) {
|
||||
return true;
|
||||
}
|
||||
set.remove(waypoint);
|
||||
markChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean exists(XaeroWaypointStore.Marker marker) {
|
||||
if (!(marker.waypointSetHandle() instanceof WaypointSet set)
|
||||
|| !(marker.waypointHandle() instanceof Waypoint waypoint)) {
|
||||
return false;
|
||||
}
|
||||
for (Waypoint existing : set.getWaypoints()) {
|
||||
if (existing == waypoint) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void addToWorld(MinimapSession session,
|
||||
ResourceKey<Level> dimension,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
String name,
|
||||
String kind,
|
||||
List<XaeroWaypointStore.Marker> out) {
|
||||
MinimapWorld world = resolveWorld(session, dimension);
|
||||
if (world == null) {
|
||||
throw new IllegalStateException("Could not resolve Xaero world for " + dimension.identifier());
|
||||
}
|
||||
|
||||
WaypointSet set = currentSet(world);
|
||||
Waypoint waypoint = new Waypoint(
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
XaeroWaypointStore.displayName(name, kind),
|
||||
XaeroWaypointStore.DEFAULT_SYMBOL,
|
||||
WaypointColor.GOLD,
|
||||
WaypointPurpose.NORMAL,
|
||||
true,
|
||||
true
|
||||
);
|
||||
waypoint.setTemporary(true);
|
||||
waypoint.setYIncluded(true);
|
||||
waypoint.setDisabled(false);
|
||||
set.add(waypoint);
|
||||
out.add(XaeroWaypointStore.createMarker(
|
||||
XaeroWaypointStore.dimensionId(dimension.identifier()),
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
waypoint.getName(),
|
||||
waypoint.getSymbol(),
|
||||
set.getName(),
|
||||
kind,
|
||||
set,
|
||||
waypoint
|
||||
));
|
||||
markChanged();
|
||||
}
|
||||
|
||||
private static WaypointSet currentSet(MinimapWorld world) {
|
||||
WaypointSet set = world.getCurrentWaypointSet();
|
||||
if (set != null) {
|
||||
return set;
|
||||
}
|
||||
String setId = world.getCurrentWaypointSetId();
|
||||
if (setId == null || setId.isBlank()) {
|
||||
setId = XaeroWaypointStore.SET;
|
||||
world.setCurrentWaypointSetId(setId);
|
||||
}
|
||||
set = world.getWaypointSet(setId);
|
||||
if (set == null) {
|
||||
world.addWaypointSet(setId);
|
||||
set = world.getWaypointSet(setId);
|
||||
}
|
||||
if (set == null) {
|
||||
throw new IllegalStateException("Could not resolve Xaero waypoint set.");
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private static MinimapWorld resolveWorld(MinimapSession session, ResourceKey<Level> dimension) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
MinimapWorldManager manager = session.getWorldManager();
|
||||
if (mc != null && mc.level != null && mc.level.dimension() == dimension) {
|
||||
return manager.getCurrentWorld();
|
||||
}
|
||||
|
||||
XaeroPath rootPath = session.getWorldState().getCurrentRootContainerPath();
|
||||
XaeroPath currentWorldPath = session.getWorldState().getCurrentWorldPath();
|
||||
if (rootPath == null || currentWorldPath == null) {
|
||||
return manager.getCurrentWorld();
|
||||
}
|
||||
|
||||
String dimensionNode = session.getDimensionHelper().getDimensionDirectoryName(dimension);
|
||||
if (dimensionNode == null || dimensionNode.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String worldNode = null;
|
||||
try {
|
||||
boolean worldMap = HudMod.INSTANCE != null
|
||||
&& HudMod.INSTANCE.getSupportMods() != null
|
||||
&& HudMod.INSTANCE.getSupportMods().worldmap();
|
||||
worldNode = session.getWorldStateUpdater().getPotentialWorldNode(dimension, worldMap);
|
||||
} catch (Throwable ignored) {
|
||||
// Fallback below keeps the marker in the same multiworld node as the current dimension.
|
||||
}
|
||||
if (worldNode == null || worldNode.isBlank()) {
|
||||
worldNode = currentWorldPath.getLastNode();
|
||||
}
|
||||
|
||||
XaeroPath worldPath = rootPath.resolve(dimensionNode).resolve(worldNode);
|
||||
MinimapWorld world = manager.getWorld(worldPath);
|
||||
if (world != null) {
|
||||
world.setDimId(dimension);
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
private static MinimapSession currentSession() {
|
||||
Object session = BuiltInHudModules.MINIMAP.getCurrentSession();
|
||||
return session instanceof MinimapSession minimapSession ? minimapSession : null;
|
||||
}
|
||||
|
||||
private static void markChanged() {
|
||||
MinimapSession session = currentSession();
|
||||
if (session != null && session.getWaypointSession() != null) {
|
||||
session.getWaypointSession().setSetChangedTime(System.currentTimeMillis());
|
||||
}
|
||||
requestWorldMapRefresh();
|
||||
}
|
||||
|
||||
private static void requestWorldMapRefresh() {
|
||||
try {
|
||||
Class<?> supportMods = Class.forName("xaero.map.mods.SupportMods");
|
||||
Object support = supportMods.getField("xaeroMinimap").get(null);
|
||||
if (support != null) {
|
||||
support.getClass().getMethod("requestWaypointsRefresh").invoke(support);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
// World Map is optional; minimap hover/list deletion works through the real Xaero set without it.
|
||||
}
|
||||
}
|
||||
|
||||
private static XaeroWaypointStore.RuntimeAddResult fail(String message) {
|
||||
return new XaeroWaypointStore.RuntimeAddResult(false, message, List.of());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.compat.xaero;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public enum XaeroWaypointStore {
|
||||
;
|
||||
|
||||
public static final String SET = "combatant";
|
||||
public static final String DEFAULT_NAME = "LoVisual";
|
||||
public static final String DEFAULT_SYMBOL = "C";
|
||||
|
||||
private static final AtomicLong NEXT_ID = new AtomicLong(1L);
|
||||
private static final CopyOnWriteArrayList<Marker> MARKERS = new CopyOnWriteArrayList<>();
|
||||
|
||||
public static AddResult addFromCurrentDimension(int x, int y, int z, String name, boolean dualDefault) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.level == null) {
|
||||
return new AddResult(false, 0, "No client world is loaded.");
|
||||
}
|
||||
|
||||
String safeName = sanitizeName(name);
|
||||
try {
|
||||
RuntimeAddResult runtime = XaeroWaypointRuntime.addFromCurrentDimension(x, y, z, safeName, dualDefault);
|
||||
if (!runtime.success()) {
|
||||
return new AddResult(false, 0, runtime.message());
|
||||
}
|
||||
MARKERS.addAll(runtime.markers());
|
||||
return new AddResult(true, runtime.markers().size(), runtime.message());
|
||||
} catch (NoClassDefFoundError | ExceptionInInitializerError error) {
|
||||
return new AddResult(false, 0, "Xaero waypoint runtime is not available.");
|
||||
} catch (Throwable throwable) {
|
||||
return new AddResult(false, 0, "Failed to add Xaero marker: " + throwable.getClass().getSimpleName() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Marker> currentDimensionMarkers() {
|
||||
pruneMissing();
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.level == null || MARKERS.isEmpty()) return List.of();
|
||||
String dim = dimensionId(mc.level.dimension().identifier());
|
||||
List<Marker> out = new ArrayList<>();
|
||||
for (Marker marker : MARKERS) {
|
||||
if (marker.dimensionId().equals(dim)) {
|
||||
out.add(marker);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static List<Marker> markers() {
|
||||
pruneMissing();
|
||||
return List.copyOf(MARKERS);
|
||||
}
|
||||
|
||||
public static RemoveResult remove(String selector) {
|
||||
pruneMissing();
|
||||
if (MARKERS.isEmpty()) {
|
||||
return new RemoveResult(true, 0, "No LoVisual Xaero markers to remove.");
|
||||
}
|
||||
|
||||
List<Marker> targets = select(selector);
|
||||
if (targets.isEmpty()) {
|
||||
return new RemoveResult(false, 0, "No matching LoVisual Xaero marker: " + selector + ".");
|
||||
}
|
||||
|
||||
int removed = 0;
|
||||
for (Marker marker : targets) {
|
||||
if (removeMarker(marker)) {
|
||||
removed++;
|
||||
}
|
||||
}
|
||||
if (removed == 0) {
|
||||
return new RemoveResult(false, 0, "No LoVisual Xaero markers were removed.");
|
||||
}
|
||||
return new RemoveResult(true, removed, "Removed Xaero markers: " + removed + ".");
|
||||
}
|
||||
|
||||
public static int clear() {
|
||||
return remove(null).count();
|
||||
}
|
||||
|
||||
static Marker createMarker(String dimensionId,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
String name,
|
||||
String symbol,
|
||||
String set,
|
||||
String kind,
|
||||
Object waypointSetHandle,
|
||||
Object waypointHandle) {
|
||||
return new Marker(
|
||||
NEXT_ID.getAndIncrement(),
|
||||
dimensionId,
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
name,
|
||||
symbol,
|
||||
set,
|
||||
kind,
|
||||
System.currentTimeMillis(),
|
||||
waypointSetHandle,
|
||||
waypointHandle
|
||||
);
|
||||
}
|
||||
|
||||
private static List<Marker> select(String selector) {
|
||||
String normalized = selector == null ? "" : selector.trim();
|
||||
if (normalized.isEmpty()
|
||||
|| "all".equalsIgnoreCase(normalized)
|
||||
|| "*".equals(normalized)) {
|
||||
return new ArrayList<>(MARKERS);
|
||||
}
|
||||
|
||||
Integer index = parsePositiveInt(normalized);
|
||||
if (index != null) {
|
||||
List<Marker> snapshot = markers();
|
||||
int zeroIndex = index - 1;
|
||||
if (zeroIndex >= 0 && zeroIndex < snapshot.size()) {
|
||||
return List.of(snapshot.get(zeroIndex));
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
String lower = normalized.toLowerCase(Locale.ROOT);
|
||||
List<Marker> out = new ArrayList<>();
|
||||
for (Marker marker : MARKERS) {
|
||||
if (marker.name().toLowerCase(Locale.ROOT).contains(lower)
|
||||
|| marker.kind().toLowerCase(Locale.ROOT).contains(lower)
|
||||
|| marker.dimensionId().toLowerCase(Locale.ROOT).contains(lower)) {
|
||||
out.add(marker);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static boolean removeMarker(Marker marker) {
|
||||
boolean removedFromXaero = true;
|
||||
try {
|
||||
removedFromXaero = XaeroWaypointRuntime.remove(marker);
|
||||
} catch (NoClassDefFoundError | ExceptionInInitializerError ignored) {
|
||||
removedFromXaero = true;
|
||||
} catch (Throwable ignored) {
|
||||
removedFromXaero = false;
|
||||
}
|
||||
boolean removedFromStore = MARKERS.remove(marker);
|
||||
return removedFromStore && removedFromXaero;
|
||||
}
|
||||
|
||||
private static void pruneMissing() {
|
||||
if (MARKERS.isEmpty()) return;
|
||||
try {
|
||||
Iterator<Marker> iterator = MARKERS.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Marker marker = iterator.next();
|
||||
if (!XaeroWaypointRuntime.exists(marker)) {
|
||||
MARKERS.remove(marker);
|
||||
}
|
||||
}
|
||||
} catch (NoClassDefFoundError | ExceptionInInitializerError ignored) {
|
||||
MARKERS.clear();
|
||||
} catch (Throwable ignored) {
|
||||
// Keep the in-memory index if Xaero is mid-session reload or unavailable for a tick.
|
||||
}
|
||||
}
|
||||
|
||||
static int netherCoord(int overworldCoord) {
|
||||
return (int) Math.round(overworldCoord / 8.0);
|
||||
}
|
||||
|
||||
static String dimensionId(Identifier id) {
|
||||
return id == null ? "" : id.toString();
|
||||
}
|
||||
|
||||
static String sanitizeName(String name) {
|
||||
if (name == null || name.isBlank()) return DEFAULT_NAME;
|
||||
String trimmed = name.trim();
|
||||
return trimmed.length() > 40 ? trimmed.substring(0, 40) : trimmed;
|
||||
}
|
||||
|
||||
static String displayName(String name, String kind) {
|
||||
String safeName = sanitizeName(name);
|
||||
if (kind == null || kind.isBlank() || kind.contains(":")) return safeName;
|
||||
return safeName + " " + kind;
|
||||
}
|
||||
|
||||
static String format(int x, int y, int z) {
|
||||
return String.format(Locale.ROOT, "%d %d %d", x, y, z);
|
||||
}
|
||||
|
||||
private static Integer parsePositiveInt(String value) {
|
||||
try {
|
||||
int parsed = Integer.parseInt(value);
|
||||
return parsed <= 0 ? null : parsed;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isOverworld() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
return mc != null && mc.level != null && mc.level.dimension() == Level.OVERWORLD;
|
||||
}
|
||||
|
||||
static boolean isNether() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
return mc != null && mc.level != null && mc.level.dimension() == Level.NETHER;
|
||||
}
|
||||
|
||||
public record Marker(long id,
|
||||
String dimensionId,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
String name,
|
||||
String symbol,
|
||||
String set,
|
||||
String kind,
|
||||
long createdAtMs,
|
||||
Object waypointSetHandle,
|
||||
Object waypointHandle) {
|
||||
}
|
||||
|
||||
public record AddResult(boolean success, int count, String message) {
|
||||
}
|
||||
|
||||
public record RemoveResult(boolean success, int count, String message) {
|
||||
}
|
||||
|
||||
static record RuntimeAddResult(boolean success, String message, List<Marker> markers) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class Event {
|
||||
private boolean cancelled;
|
||||
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.runtime.RuntimeGate;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public final class EventBus {
|
||||
private static final Subscriber[] EMPTY_SUBSCRIBERS = new Subscriber[0];
|
||||
private static final Comparator<Subscriber> PRIORITY =
|
||||
Comparator.comparingInt((Subscriber sub) -> sub.priority).reversed();
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
private final Reference2ObjectOpenHashMap<Class<?>, Subscriber[]> exactHandlers = new Reference2ObjectOpenHashMap<>();
|
||||
private final Reference2ObjectOpenHashMap<Class<?>, Subscriber[]> dispatchCache = new Reference2ObjectOpenHashMap<>();
|
||||
private final Reference2ObjectOpenHashMap<Object, Subscriber[]> ownerIndex = new Reference2ObjectOpenHashMap<>();
|
||||
|
||||
private static Subscriber[] append(Subscriber[] old, Subscriber sub) {
|
||||
Subscriber[] next = Arrays.copyOf(old, old.length + 1);
|
||||
next[old.length] = sub;
|
||||
return next;
|
||||
}
|
||||
|
||||
private static Subscriber[] remove(Subscriber[] old, Subscriber sub) {
|
||||
int index = -1;
|
||||
for (int i = 0; i < old.length; i++) {
|
||||
if (old[i] == sub) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < 0) return old;
|
||||
if (old.length == 1) return EMPTY_SUBSCRIBERS;
|
||||
|
||||
Subscriber[] next = new Subscriber[old.length - 1];
|
||||
System.arraycopy(old, 0, next, 0, index);
|
||||
System.arraycopy(old, index + 1, next, index, old.length - index - 1);
|
||||
return next;
|
||||
}
|
||||
|
||||
private static void sortSubscribers(Subscriber[] subscribers) {
|
||||
Arrays.sort(subscribers, PRIORITY);
|
||||
}
|
||||
|
||||
public void register(Object listener) {
|
||||
if (listener instanceof Module module) {
|
||||
registerOwned(module, listener);
|
||||
} else {
|
||||
registerOwned(null, listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerOwned(Module gateModule, Object listener) {
|
||||
if (listener == null) return;
|
||||
|
||||
synchronized (lock) {
|
||||
if (ownerIndex.containsKey(listener)) return;
|
||||
|
||||
Subscriber[] subs = scan(listener, gateModule);
|
||||
if (subs.length == 0) return;
|
||||
|
||||
ownerIndex.put(listener, subs);
|
||||
for (Subscriber sub : subs) {
|
||||
Subscriber[] old = exactHandlers.get(sub.eventType);
|
||||
if (old == null) old = EMPTY_SUBSCRIBERS;
|
||||
Subscriber[] next = append(old, sub);
|
||||
sortSubscribers(next);
|
||||
exactHandlers.put(sub.eventType, next);
|
||||
}
|
||||
|
||||
dispatchCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister(Object listener) {
|
||||
if (listener == null) return;
|
||||
|
||||
synchronized (lock) {
|
||||
Subscriber[] subs = ownerIndex.remove(listener);
|
||||
if (subs == null || subs.length == 0) return;
|
||||
|
||||
for (Subscriber sub : subs) {
|
||||
Subscriber[] old = exactHandlers.get(sub.eventType);
|
||||
if (old == null || old.length == 0) continue;
|
||||
|
||||
Subscriber[] next = remove(old, sub);
|
||||
if (next.length == 0) {
|
||||
exactHandlers.remove(sub.eventType);
|
||||
} else {
|
||||
exactHandlers.put(sub.eventType, next);
|
||||
}
|
||||
}
|
||||
|
||||
dispatchCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasListeners(Class<? extends Event> eventType) {
|
||||
return subscribersFor(eventType).length != 0;
|
||||
}
|
||||
|
||||
public <T extends Event> T post(T event) {
|
||||
if (event == null) return null;
|
||||
if (!RuntimeGate.canRunClientLogic()) return event;
|
||||
|
||||
Subscriber[] subscribers = subscribersFor(event.getClass());
|
||||
for (Subscriber sub : subscribers) {
|
||||
Module gate = sub.gateModule;
|
||||
if (gate != null && !gate.isEnabled()) continue;
|
||||
|
||||
try {
|
||||
sub.invoker.invoke(event);
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("Event handler failed: %s", t, sub.describe());
|
||||
}
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
synchronized (lock) {
|
||||
exactHandlers.clear();
|
||||
dispatchCache.clear();
|
||||
ownerIndex.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public int listenerCount() {
|
||||
synchronized (lock) {
|
||||
return ownerIndex.size();
|
||||
}
|
||||
}
|
||||
|
||||
private Subscriber[] scan(Object listener, Module gateModule) {
|
||||
List<Subscriber> out = new ArrayList<>();
|
||||
Class<?> cls = listener.getClass();
|
||||
|
||||
for (Method method : cls.getDeclaredMethods()) {
|
||||
if (!method.isAnnotationPresent(EventHandler.class)) continue;
|
||||
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
if (params.length != 1) continue;
|
||||
if (!Event.class.isAssignableFrom(params[0])) continue;
|
||||
|
||||
EventHandler meta = method.getAnnotation(EventHandler.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Event> eventType = (Class<? extends Event>) params[0];
|
||||
|
||||
EventInvoker invoker = createInvoker(listener, method);
|
||||
out.add(new Subscriber(listener, gateModule, method, invoker, eventType, meta.priority()));
|
||||
}
|
||||
|
||||
return out.toArray(Subscriber[]::new);
|
||||
}
|
||||
|
||||
private EventInvoker createInvoker(Object listener, Method method) {
|
||||
method.setAccessible(true);
|
||||
try {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
MethodHandle handle = lookup.unreflect(method).bindTo(listener);
|
||||
return handle::invoke;
|
||||
} catch (Throwable t) {
|
||||
DebugLog.error("Failed to create MethodHandle event invoker, falling back to reflection: %s", t,
|
||||
listener.getClass().getName() + "#" + method.getName());
|
||||
return event -> method.invoke(listener, event);
|
||||
}
|
||||
}
|
||||
|
||||
private Subscriber[] subscribersFor(Class<?> eventType) {
|
||||
if (eventType == null) return EMPTY_SUBSCRIBERS;
|
||||
|
||||
synchronized (lock) {
|
||||
Subscriber[] cached = dispatchCache.get(eventType);
|
||||
if (cached != null) return cached;
|
||||
|
||||
Subscriber[] built = buildFlattenedSubscribers(eventType);
|
||||
dispatchCache.put(eventType, built);
|
||||
return built;
|
||||
}
|
||||
}
|
||||
|
||||
private Subscriber[] buildFlattenedSubscribers(Class<?> eventType) {
|
||||
int total = 0;
|
||||
|
||||
Class<?> type = eventType;
|
||||
while (type != null && Event.class.isAssignableFrom(type)) {
|
||||
Subscriber[] exact = exactHandlers.get(type);
|
||||
if (exact != null) total += exact.length;
|
||||
type = type.getSuperclass();
|
||||
}
|
||||
|
||||
if (total == 0) return EMPTY_SUBSCRIBERS;
|
||||
|
||||
Subscriber[] out = new Subscriber[total];
|
||||
int offset = 0;
|
||||
|
||||
type = eventType;
|
||||
while (type != null && Event.class.isAssignableFrom(type)) {
|
||||
Subscriber[] exact = exactHandlers.get(type);
|
||||
if (exact != null && exact.length > 0) {
|
||||
System.arraycopy(exact, 0, out, offset, exact.length);
|
||||
offset += exact.length;
|
||||
}
|
||||
type = type.getSuperclass();
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface EventInvoker {
|
||||
void invoke(Event event) throws Throwable;
|
||||
}
|
||||
|
||||
private static final class Subscriber {
|
||||
final Object owner;
|
||||
final Module gateModule;
|
||||
final Method method;
|
||||
final EventInvoker invoker;
|
||||
final Class<? extends Event> eventType;
|
||||
final int priority;
|
||||
final String description;
|
||||
|
||||
Subscriber(Object owner,
|
||||
Module gateModule,
|
||||
Method method,
|
||||
EventInvoker invoker,
|
||||
Class<? extends Event> eventType,
|
||||
int priority) {
|
||||
this.owner = owner;
|
||||
this.gateModule = gateModule;
|
||||
this.method = method;
|
||||
this.invoker = invoker;
|
||||
this.eventType = eventType;
|
||||
this.priority = priority;
|
||||
this.description = owner.getClass().getName() + "#" + method.getName();
|
||||
}
|
||||
|
||||
String describe() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@UsedImplicitly
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface EventHandler {
|
||||
int priority() default 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events;
|
||||
|
||||
public enum Events {
|
||||
;
|
||||
public static final EventBus BUS = new EventBus();
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks code that is intentionally reached through reflection, Fabric entrypoints,
|
||||
* addon API calls, event dispatch, serialization, or other non-direct call paths.
|
||||
*
|
||||
* <p>This is a source-level documentation and IntelliJ IDEA inspection hint. It is
|
||||
* not a runtime contract and should not be used for behavior checks.</p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@Target({
|
||||
ElementType.ANNOTATION_TYPE,
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD,
|
||||
ElementType.TYPE
|
||||
})
|
||||
public @interface UsedImplicitly {
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public final class AttackEntityEvent extends Event {
|
||||
private final Player player;
|
||||
private final Entity target;
|
||||
|
||||
public AttackEntityEvent(Player player, Entity target) {
|
||||
this.player = player;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Combatant modifications copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Portions of this file are based on LiquidBounce
|
||||
* (https://github.com/CCBlueX/LiquidBounce).
|
||||
* Copyright (c) 2015-2026 CCBlueX.
|
||||
*
|
||||
* LiquidBounce portions are licensed under GPLv3-or-later.
|
||||
* Combatant modifications are licensed under GPLv3.
|
||||
* See THIRD_PARTY_NOTICES.md for details.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import dev.loki.lovisual.util.network.BlinkManager;
|
||||
import dev.loki.lovisual.util.network.TransferOrigin;
|
||||
|
||||
/**
|
||||
* Adapted from LiquidBounce's BlinkPacketEvent.
|
||||
*/
|
||||
public class BlinkPacketEvent extends Event {
|
||||
private final Packet<?> packet;
|
||||
@Getter
|
||||
private final TransferOrigin origin;
|
||||
@Getter
|
||||
private BlinkManager.Action action = BlinkManager.Action.FLUSH;
|
||||
|
||||
public BlinkPacketEvent(Packet<?> packet, TransferOrigin origin) {
|
||||
this.packet = packet;
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Packet<?>> T getPacket() {
|
||||
return (T) packet;
|
||||
}
|
||||
|
||||
public void setAction(BlinkManager.Action action) {
|
||||
if (action == null || this.action == action || this.action.getPriority() >= action.getPriority()) {
|
||||
return;
|
||||
}
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CombatProtocolBossbarEvent extends Event {
|
||||
public final List<String> names;
|
||||
public final long timeMs;
|
||||
|
||||
public CombatProtocolBossbarEvent(List<String> names) {
|
||||
this(names, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public CombatProtocolBossbarEvent(List<String> names, long timeMs) {
|
||||
this.names = names == null ? List.of() : List.copyOf(names);
|
||||
this.timeMs = timeMs;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public final class CrosshairTargetUpdateEvent extends Event {
|
||||
private final float tickDelta;
|
||||
@Setter
|
||||
private HitResult hitResult;
|
||||
@Setter
|
||||
private Entity targetedEntity;
|
||||
|
||||
public CrosshairTargetUpdateEvent(float tickDelta, HitResult hitResult, Entity targetedEntity) {
|
||||
this.tickDelta = tickDelta;
|
||||
this.hitResult = hitResult;
|
||||
this.targetedEntity = targetedEntity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public class EventBreakBlock extends Event {
|
||||
private final BlockPos pos;
|
||||
|
||||
public EventBreakBlock(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public class EventCollision extends Event {
|
||||
private final BlockPos pos;
|
||||
@Setter
|
||||
private BlockState state;
|
||||
|
||||
public EventCollision(BlockState state, BlockPos pos) {
|
||||
this.state = state;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
public class EventPostSync extends Event {
|
||||
public EventPostSync() {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class EventPushOutOfBlocks extends Event {
|
||||
private final double x;
|
||||
private final double z;
|
||||
|
||||
public EventPushOutOfBlocks(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
|
||||
public class EventSync extends Event {
|
||||
@Getter
|
||||
private final float originalYaw;
|
||||
@Getter
|
||||
private final float originalPitch;
|
||||
@Getter
|
||||
private float yaw;
|
||||
@Getter
|
||||
private float pitch;
|
||||
private boolean rotationOverride;
|
||||
@Getter
|
||||
private boolean silentRotation;
|
||||
@Getter
|
||||
private Runnable postAction;
|
||||
|
||||
public EventSync(float yaw, float pitch) {
|
||||
this.originalYaw = yaw;
|
||||
this.originalPitch = pitch;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setYaw(float yaw) {
|
||||
this.yaw = yaw;
|
||||
this.rotationOverride = true;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
this.rotationOverride = true;
|
||||
}
|
||||
|
||||
public void setRotation(float yaw, float pitch, boolean silent) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
this.rotationOverride = true;
|
||||
this.silentRotation = silent;
|
||||
}
|
||||
|
||||
public boolean hasRotationOverride() {
|
||||
return rotationOverride;
|
||||
}
|
||||
|
||||
public void addPostAction(Runnable r) {
|
||||
if (r == null) return;
|
||||
if (postAction == null) {
|
||||
postAction = r;
|
||||
} else {
|
||||
Runnable prev = postAction;
|
||||
postAction = () -> {
|
||||
prev.run();
|
||||
r.run();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import dev.loki.lovisual.util.target.TargetManager;
|
||||
|
||||
/**
|
||||
* Fired when the centralized target changes.
|
||||
*/
|
||||
public class EventTargetChanged extends Event {
|
||||
public final LivingEntity previous;
|
||||
public final TargetManager.Source previousSource;
|
||||
public final LivingEntity current;
|
||||
public final TargetManager.Source currentSource;
|
||||
|
||||
public EventTargetChanged(LivingEntity previous,
|
||||
TargetManager.Source previousSource,
|
||||
LivingEntity current,
|
||||
TargetManager.Source currentSource) {
|
||||
this.previous = previous;
|
||||
this.previousSource = previousSource;
|
||||
this.current = current;
|
||||
this.currentSource = currentSource;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public final class FireworkEvent extends Event {
|
||||
private Vec3 vector;
|
||||
|
||||
public FireworkEvent(Vec3 vector) {
|
||||
this.vector = vector;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
/**
|
||||
* Fired at the start of each client tick.
|
||||
*/
|
||||
public final class GameTickEvent extends Event {
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.config.SettingDef;
|
||||
import dev.loki.lovisual.config.SettingOwner;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import dev.loki.lovisual.features.gui.clickgui.settings.Setting;
|
||||
import dev.loki.lovisual.features.gui.clickgui.settings.SettingFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Collects setting-backed i18n keys after language resources are loaded.
|
||||
*/
|
||||
public final class I18nPreflightCollectEvent extends Event {
|
||||
private final String reason;
|
||||
private final ArrayList<Entry> entries = new ArrayList<>();
|
||||
|
||||
public I18nPreflightCollectEvent(String reason) {
|
||||
this.reason = reason != null && !reason.isBlank() ? reason : "i18n preflight";
|
||||
}
|
||||
|
||||
public String reason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent setting(Setting setting) {
|
||||
return setting("settings", setting);
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent setting(String path, Setting setting) {
|
||||
if (setting != null) {
|
||||
entries.add(new Entry(normalizePath(path), setting));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent settings(Iterable<? extends Setting> values) {
|
||||
return settings("settings", values);
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent settings(String path, Iterable<? extends Setting> values) {
|
||||
if (values == null) return this;
|
||||
for (Setting setting : values) {
|
||||
setting(path, setting);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent settingDefs(SettingOwner owner, Iterable<SettingDef> defs) {
|
||||
return settingDefs(owner != null ? owner.name() : "settings", owner, defs);
|
||||
}
|
||||
|
||||
public I18nPreflightCollectEvent settingDefs(String path, SettingOwner owner, Iterable<SettingDef> defs) {
|
||||
if (owner == null || defs == null) return this;
|
||||
for (SettingDef def : defs) {
|
||||
Setting setting = SettingFactory.fromDef(def);
|
||||
if (setting == null) continue;
|
||||
setting.setParent(owner);
|
||||
setting(path, setting);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<Entry> entries() {
|
||||
return Collections.unmodifiableList(entries);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return entries.isEmpty();
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
if (path == null || path.isBlank()) return "settings";
|
||||
String normalized = path.trim().replace('\\', '/');
|
||||
while (normalized.contains("//")) {
|
||||
normalized = normalized.replace("//", "/");
|
||||
}
|
||||
if (normalized.startsWith("/")) normalized = normalized.substring(1);
|
||||
if (normalized.endsWith("/")) normalized = normalized.substring(0, normalized.length() - 1);
|
||||
return normalized.isBlank() ? "settings" : normalized;
|
||||
}
|
||||
|
||||
public record Entry(String path, Setting setting) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.input.KeyEvent;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public final class KeyInputEvent extends Event {
|
||||
private final int action;
|
||||
private final KeyEvent input;
|
||||
|
||||
public KeyInputEvent(int action, KeyEvent input) {
|
||||
this.action = action;
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public final class KeybindIsPressedEvent extends Event {
|
||||
|
||||
private final KeyMapping keyBinding;
|
||||
@Setter
|
||||
private boolean pressed;
|
||||
|
||||
public KeybindIsPressedEvent(KeyMapping keyBinding, boolean pressed) {
|
||||
this.keyBinding = keyBinding;
|
||||
this.pressed = pressed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class LightmapEvent extends Event {
|
||||
private final float originalAmbient;
|
||||
@Setter
|
||||
private float ambientLight;
|
||||
|
||||
public LightmapEvent(float ambientLight) {
|
||||
this.originalAmbient = ambientLight;
|
||||
this.ambientLight = ambientLight;
|
||||
}
|
||||
|
||||
public void raiseAmbientLight(float ambientLight) {
|
||||
if (ambientLight > this.ambientLight) {
|
||||
this.ambientLight = ambientLight;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return Math.abs(ambientLight - originalAmbient) > 1.0e-4f;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.renderer.state.LightmapRenderState;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
public class LightmapModifyEvent extends Event {
|
||||
private static final float EPSILON = 1.0e-4f;
|
||||
|
||||
private final LightmapRenderState state;
|
||||
private final float originalBrightness;
|
||||
@Getter
|
||||
private boolean modified;
|
||||
|
||||
public LightmapModifyEvent(LightmapRenderState state) {
|
||||
this.state = state;
|
||||
this.originalBrightness = state != null ? state.brightness : 0.0f;
|
||||
}
|
||||
|
||||
public LightmapRenderState state() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public float originalBrightness() {
|
||||
return originalBrightness;
|
||||
}
|
||||
|
||||
public void raiseMinimumLight(float minLight) {
|
||||
if (state == null) return;
|
||||
|
||||
float strength = Mth.clamp(minLight, 0.0f, 1.0f);
|
||||
if (strength <= EPSILON) return;
|
||||
|
||||
state.needsUpdate = true;
|
||||
|
||||
// Do not emulate FullBright by forcing brightness/night vision to 1.0.
|
||||
// In the 1.21+ UBO lightmap path that behaves like global exposure and blows out the scene.
|
||||
float exposureFloor = 0.08f + 0.18f * strength;
|
||||
state.brightness = Math.max(state.brightness, exposureFloor);
|
||||
state.nightVisionEffectIntensity = Math.max(state.nightVisionEffectIntensity, 0.10f * strength);
|
||||
|
||||
// Lift the generated lightmap itself, but keep vanilla color response instead of whitening it.
|
||||
state.skyFactor = Math.max(state.skyFactor, 0.55f + 0.35f * strength);
|
||||
state.blockFactor = Math.max(state.blockFactor, 1.4f + 0.25f * strength);
|
||||
|
||||
// FullBright must not be attenuated by darkness/boss-world darkening.
|
||||
float attenuation = 1.0f - strength;
|
||||
state.darknessEffectScale *= attenuation;
|
||||
state.bossOverlayWorldDarkening *= attenuation;
|
||||
|
||||
float colorFloor = 0.10f + 0.28f * strength;
|
||||
state.blockLightTint = raiseColorFloor(state.blockLightTint, colorFloor);
|
||||
state.skyLightColor = raiseColorFloor(state.skyLightColor, colorFloor);
|
||||
state.ambientColor = raiseColorFloor(state.ambientColor, colorFloor);
|
||||
state.nightVisionColor = raiseColorFloor(state.nightVisionColor, colorFloor);
|
||||
|
||||
modified = true;
|
||||
}
|
||||
|
||||
private static Vector3fc raiseColorFloor(Vector3fc color, float floor) {
|
||||
float min = Mth.clamp(floor, 0.0f, 1.0f);
|
||||
if (color == null) {
|
||||
return new Vector3f(min, min, min);
|
||||
}
|
||||
return new Vector3f(
|
||||
Math.max(color.x(), min),
|
||||
Math.max(color.y(), min),
|
||||
Math.max(color.z(), min)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Combatant modifications copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Portions of this file are based on LiquidBounce
|
||||
* (https://github.com/CCBlueX/LiquidBounce).
|
||||
* Copyright (c) 2015-2026 CCBlueX.
|
||||
*
|
||||
* LiquidBounce portions are licensed under GPLv3-or-later.
|
||||
* Combatant modifications are licensed under GPLv3.
|
||||
* See THIRD_PARTY_NOTICES.md for details.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.world.entity.player.Input;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public final class MovementInputEvent extends Event {
|
||||
private boolean forward;
|
||||
private boolean backward;
|
||||
private boolean left;
|
||||
private boolean right;
|
||||
private boolean jump;
|
||||
private boolean sneak;
|
||||
private boolean sprint;
|
||||
|
||||
public MovementInputEvent(Input input) {
|
||||
this.forward = input.forward();
|
||||
this.backward = input.backward();
|
||||
this.left = input.left();
|
||||
this.right = input.right();
|
||||
this.jump = input.jump();
|
||||
this.sneak = input.shift();
|
||||
this.sprint = input.sprint();
|
||||
}
|
||||
|
||||
public Input toPlayerInput() {
|
||||
return new Input(forward, backward, left, right, jump, sneak, sprint);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import dev.loki.lovisual.util.network.TransferOrigin;
|
||||
|
||||
public class PacketEvent extends Event {
|
||||
private final Packet<?> packet;
|
||||
@Getter
|
||||
private final TransferOrigin origin;
|
||||
@Getter
|
||||
private final boolean original;
|
||||
|
||||
public PacketEvent(Packet<?> packet) {
|
||||
this(packet, null, true);
|
||||
}
|
||||
|
||||
public PacketEvent(Packet<?> packet, TransferOrigin origin, boolean original) {
|
||||
this.packet = packet;
|
||||
this.origin = origin;
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Packet<?>> T getPacket() {
|
||||
return (T) this.packet;
|
||||
}
|
||||
|
||||
public static class Send extends PacketEvent {
|
||||
public Send(Packet<?> packet) {
|
||||
super(packet, TransferOrigin.OUTGOING, true);
|
||||
}
|
||||
|
||||
public Send(Packet<?> packet, boolean original) {
|
||||
super(packet, TransferOrigin.OUTGOING, original);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Receive extends PacketEvent {
|
||||
public Receive(Packet<?> packet) {
|
||||
super(packet, TransferOrigin.INCOMING, true);
|
||||
}
|
||||
|
||||
public Receive(Packet<?> packet, boolean original) {
|
||||
super(packet, TransferOrigin.INCOMING, original);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendPost extends PacketEvent {
|
||||
public SendPost(Packet<?> packet) {
|
||||
super(packet, TransferOrigin.OUTGOING, true);
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public SendPost(Packet<?> packet, boolean original) {
|
||||
super(packet, TransferOrigin.OUTGOING, original);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReceivePost extends PacketEvent {
|
||||
public ReceivePost(Packet<?> packet) {
|
||||
super(packet, TransferOrigin.INCOMING, true);
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
public ReceivePost(Packet<?> packet, boolean original) {
|
||||
super(packet, TransferOrigin.INCOMING, original);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public final class PlayerJumpEvent extends Event {
|
||||
private float yaw;
|
||||
private float motion;
|
||||
|
||||
public PlayerJumpEvent(float yaw, float motion) {
|
||||
this.yaw = yaw;
|
||||
this.motion = motion;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Combatant modifications copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Portions of this file are based on, adapted from, or implemented
|
||||
* with reference to Meteor Client
|
||||
* (https://github.com/MeteorDevelopment/meteor-client).
|
||||
* Copyright (c) Meteor Development.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
* See THIRD_PARTY_NOTICES.md for details.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public class PlayerMoveEvent extends Event {
|
||||
private final MoverType type;
|
||||
@Setter
|
||||
private Vec3 movement;
|
||||
|
||||
public PlayerMoveEvent(MoverType type, Vec3 movement) {
|
||||
this.type = type;
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class PlayerSafeWalkEvent extends Event {
|
||||
private boolean safeWalk;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public final class PlayerStepEvent extends Event {
|
||||
private float height;
|
||||
|
||||
public PlayerStepEvent(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public final class PlayerStepSuccessEvent extends Event {
|
||||
private final Vec3 adjustedVec;
|
||||
|
||||
public PlayerStepSuccessEvent(Vec3 adjustedVec) {
|
||||
this.adjustedVec = adjustedVec;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
@Getter
|
||||
public class PlayerVelocityStrafe extends Event {
|
||||
|
||||
private final Vec3 movementInput;
|
||||
private final float speed;
|
||||
private final float yaw;
|
||||
@Setter
|
||||
private Vec3 velocity;
|
||||
|
||||
public PlayerVelocityStrafe(Vec3 movementInput, float speed, float yaw, Vec3 velocity) {
|
||||
this.movementInput = movementInput;
|
||||
this.speed = speed;
|
||||
this.yaw = yaw;
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class PostPlayerUpdateEvent extends Event {
|
||||
private int iterations;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
/**
|
||||
* Fired when a PvP-related chat or game message is received.
|
||||
*/
|
||||
public class PvpChatEvent extends Event {
|
||||
public final String message;
|
||||
public final Source source;
|
||||
public final long timeMs;
|
||||
public PvpChatEvent(String message, Source source) {
|
||||
this(message, source, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public PvpChatEvent(String message, Source source, long timeMs) {
|
||||
this.message = message;
|
||||
this.source = source;
|
||||
this.timeMs = timeMs;
|
||||
}
|
||||
|
||||
public enum Source {
|
||||
GAME_MESSAGE,
|
||||
CHAT_MESSAGE
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
/**
|
||||
* Fired when an in-game HUD overlay message is shown (action bar).
|
||||
*/
|
||||
public class PvpOverlayEvent extends Event {
|
||||
public final Component message;
|
||||
public final boolean tinted;
|
||||
public final long timeMs;
|
||||
|
||||
public PvpOverlayEvent(Component message, boolean tinted) {
|
||||
this(message, tinted, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public PvpOverlayEvent(Component message, boolean tinted, long timeMs) {
|
||||
this.message = message;
|
||||
this.tinted = tinted;
|
||||
this.timeMs = timeMs;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
|
||||
/**
|
||||
* Fired when the server updates tab-list header/footer text.
|
||||
*/
|
||||
public class PvpTabEvent extends Event {
|
||||
public final String header;
|
||||
public final String footer;
|
||||
public final long timeMs;
|
||||
|
||||
public PvpTabEvent(String header, String footer) {
|
||||
this(header, footer, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public PvpTabEvent(String header, String footer, long timeMs) {
|
||||
this.header = header == null ? "" : header;
|
||||
this.footer = footer == null ? "" : footer;
|
||||
this.timeMs = timeMs;
|
||||
}
|
||||
|
||||
public String combinedText() {
|
||||
if (header.isBlank()) return footer;
|
||||
if (footer.isBlank()) return header;
|
||||
return header + "\n" + footer;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import dev.loki.lovisual.render.engine.svg.SvgRegistry;
|
||||
import dev.loki.lovisual.render.engine.text.FontInfo;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Collects render resources that are known to be needed before the first GUI/HUD draw.
|
||||
* Producers should add only resources implied by current runtime state/config: enabled
|
||||
* modules, enabled HUD elements, and UI surfaces that can be opened immediately.
|
||||
*/
|
||||
public final class RenderPrewarmCollectEvent extends Event {
|
||||
private final String reason;
|
||||
private final LinkedHashSet<FontInfo> fonts = new LinkedHashSet<>();
|
||||
private final LinkedHashSet<Identifier> svgMsdfIcons = new LinkedHashSet<>();
|
||||
|
||||
public RenderPrewarmCollectEvent(String reason) {
|
||||
this.reason = reason != null ? reason : "render prewarm";
|
||||
}
|
||||
|
||||
public String reason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public RenderPrewarmCollectEvent font(String family) {
|
||||
return font(family, FontInfo.Type.Regular);
|
||||
}
|
||||
|
||||
public RenderPrewarmCollectEvent font(String family, FontInfo.Type type) {
|
||||
if (family == null || family.isBlank()) return this;
|
||||
fonts.add(new FontInfo(family.trim(), type != null ? type : FontInfo.Type.Regular));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderPrewarmCollectEvent font(@Nullable FontInfo info) {
|
||||
if (info != null && info.family() != null && !info.family().isBlank()) {
|
||||
fonts.add(info);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderPrewarmCollectEvent svg(String nameOrPath) {
|
||||
Identifier id = SvgRegistry.resolve(nameOrPath);
|
||||
if (id != null) {
|
||||
svgMsdfIcons.add(id);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public RenderPrewarmCollectEvent svg(@Nullable Identifier id) {
|
||||
if (id != null) {
|
||||
svgMsdfIcons.add(id);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<FontInfo> fonts() {
|
||||
return Collections.unmodifiableSet(fonts);
|
||||
}
|
||||
|
||||
public Set<Identifier> svgMsdfIcons() {
|
||||
return Collections.unmodifiableSet(svgMsdfIcons);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return fonts.isEmpty() && svgMsdfIcons.isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Rotation lifecycle event fired each tick in two phases.
|
||||
*/
|
||||
@Getter
|
||||
public final class RotationUpdateEvent extends Event {
|
||||
private final Type type;
|
||||
|
||||
public RotationUpdateEvent(Type type) {
|
||||
this.type = type == null ? Type.PRE : type;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PRE,
|
||||
POST
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.events.impl;
|
||||
|
||||
import dev.loki.lovisual.events.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class SprintControlEvent extends Event {
|
||||
@Getter
|
||||
private final float forward;
|
||||
@Getter
|
||||
private final float sideways;
|
||||
@Getter
|
||||
private final Source source;
|
||||
@Setter
|
||||
private boolean sprint;
|
||||
public SprintControlEvent(float forward, float sideways, boolean sprint, Source source) {
|
||||
this.forward = forward;
|
||||
this.sideways = sideways;
|
||||
this.sprint = sprint;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
return forward != 0.0f || sideways != 0.0f;
|
||||
}
|
||||
|
||||
public boolean shouldSprint() {
|
||||
return sprint;
|
||||
}
|
||||
|
||||
public enum Source {
|
||||
INPUT,
|
||||
MOVEMENT_TICK,
|
||||
NETWORK
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.account;
|
||||
|
||||
public enum AccountAuthType {
|
||||
OFFLINE("offline"),
|
||||
MICROSOFT("microsoft");
|
||||
|
||||
private final String id;
|
||||
|
||||
AccountAuthType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static AccountAuthType byId(String raw) {
|
||||
if (raw == null || raw.isBlank()) {
|
||||
return OFFLINE;
|
||||
}
|
||||
for (AccountAuthType type : values()) {
|
||||
if (type.id.equalsIgnoreCase(raw.trim()) || type.name().equalsIgnoreCase(raw.trim())) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return OFFLINE;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,473 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.account;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
import dev.loki.lovisual.config.ConfigNameProvider;
|
||||
import dev.loki.lovisual.config.ConfigSerializer;
|
||||
import dev.loki.lovisual.config.JsonConfigObject;
|
||||
import dev.loki.lovisual.config.values.ConfigValue;
|
||||
import dev.loki.lovisual.config.values.StringValue;
|
||||
import dev.loki.lovisual.util.session.MicrosoftSessionResult;
|
||||
import dev.loki.lovisual.util.session.SessionChanger;
|
||||
import dev.loki.lovisual.util.session.microsoft.MicrosoftAuthService;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
public final class AccountConfig implements JsonConfigObject, ConfigNameProvider {
|
||||
|
||||
public static final AccountConfig INSTANCE = new AccountConfig();
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
|
||||
|
||||
private final AccountsValue accounts = new AccountsValue("accounts");
|
||||
private final StringValue activeAccountName = new StringValue("active_name", "");
|
||||
private final StringValue activeAccountDate = new StringValue("active_date", "");
|
||||
private final StringValue activeAccountSkin = new StringValue("active_skin", "");
|
||||
private String microsoftAuthorizationRequiredName = "";
|
||||
|
||||
private AccountConfig() {
|
||||
ConfigSerializer.load(this);
|
||||
applyActiveSession();
|
||||
}
|
||||
|
||||
public static AccountConfig get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static boolean isBlank(String value) {
|
||||
return value == null || value.isBlank();
|
||||
}
|
||||
|
||||
private static String normalizeName(String name) {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
private static String nowString() {
|
||||
return LocalDateTime.now().format(DATE_FORMAT);
|
||||
}
|
||||
|
||||
private static Identifier parseIdentifier(String raw) {
|
||||
if (isBlank(raw)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Identifier.parse(raw);
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static UUID parseUuid(String raw) {
|
||||
if (isBlank(raw)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return UUID.fromString(raw.trim());
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<AccountEntry> getAccounts() {
|
||||
return accounts.get();
|
||||
}
|
||||
|
||||
public List<AccountEntry> getSortedAccounts() {
|
||||
List<AccountEntry> sorted = new ArrayList<>(accounts.get());
|
||||
sorted.sort(Comparator
|
||||
.comparing(AccountEntry::isPinned).reversed()
|
||||
.thenComparingInt(AccountEntry::getOriginalIndex));
|
||||
return sorted;
|
||||
}
|
||||
|
||||
public AccountEntry getAccountBySortedIndex(int sortedIndex) {
|
||||
List<AccountEntry> sorted = getSortedAccounts();
|
||||
if (sortedIndex < 0 || sortedIndex >= sorted.size()) {
|
||||
return null;
|
||||
}
|
||||
return sorted.get(sortedIndex);
|
||||
}
|
||||
|
||||
public AccountEntry findByName(String name) {
|
||||
String normalized = normalizeName(name);
|
||||
if (normalized.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
for (AccountEntry entry : accounts.get()) {
|
||||
if (normalizeName(entry.getName()).equals(normalized)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public AccountEntry addAccount(String name) {
|
||||
return addAccount(name, nowString(), null);
|
||||
}
|
||||
|
||||
public AccountEntry addAccount(String name, String date, Identifier skin) {
|
||||
String cleanName = normalizeName(name);
|
||||
if (cleanName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AccountEntry existing = findByName(cleanName);
|
||||
if (existing != null) {
|
||||
existing.setAuthType(AccountAuthType.OFFLINE);
|
||||
existing.setOnlineUuid(null);
|
||||
existing.setMicrosoftRefreshToken("");
|
||||
clearAuthorizationRequired(existing.getName());
|
||||
if (!isBlank(date)) {
|
||||
existing.setDate(date);
|
||||
}
|
||||
if (skin != null) {
|
||||
existing.setSkin(skin);
|
||||
}
|
||||
save();
|
||||
return existing;
|
||||
}
|
||||
|
||||
AccountEntry entry = new AccountEntry(cleanName, isBlank(date) ? nowString() : date, skin, false, accounts.get().size());
|
||||
accounts.get().add(entry);
|
||||
save();
|
||||
return entry;
|
||||
}
|
||||
|
||||
public AccountEntry addMicrosoftAccount(MicrosoftSessionResult session) {
|
||||
if (session == null || isBlank(session.name()) || session.uuid() == null || isBlank(session.refreshToken())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AccountEntry existing = findByName(session.name());
|
||||
if (existing != null) {
|
||||
existing.applyMicrosoftSession(session);
|
||||
existing.setDate(nowString());
|
||||
clearAuthorizationRequired(existing.getName());
|
||||
save();
|
||||
return existing;
|
||||
}
|
||||
|
||||
AccountEntry entry = new AccountEntry(
|
||||
session.name(),
|
||||
nowString(),
|
||||
null,
|
||||
false,
|
||||
accounts.get().size(),
|
||||
AccountAuthType.MICROSOFT,
|
||||
session.uuid(),
|
||||
session.refreshToken()
|
||||
);
|
||||
accounts.get().add(entry);
|
||||
clearAuthorizationRequired(entry.getName());
|
||||
save();
|
||||
return entry;
|
||||
}
|
||||
|
||||
public void removeAccount(AccountEntry entry) {
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
if (!accounts.get().remove(entry)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isActive(entry)) {
|
||||
clearActiveAccount();
|
||||
} else {
|
||||
reindexAccounts();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAccountBySortedIndex(int sortedIndex) {
|
||||
removeAccount(getAccountBySortedIndex(sortedIndex));
|
||||
}
|
||||
|
||||
public void clearAllAccounts() {
|
||||
accounts.get().clear();
|
||||
activeAccountName.set("");
|
||||
activeAccountDate.set("");
|
||||
activeAccountSkin.set("");
|
||||
microsoftAuthorizationRequiredName = "";
|
||||
save();
|
||||
}
|
||||
|
||||
public void togglePin(int sortedIndex) {
|
||||
AccountEntry entry = getAccountBySortedIndex(sortedIndex);
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
entry.togglePinned();
|
||||
save();
|
||||
}
|
||||
|
||||
public void setActiveAccount(AccountEntry entry) {
|
||||
if (entry == null) {
|
||||
clearActiveAccount();
|
||||
return;
|
||||
}
|
||||
|
||||
activeAccountName.set(normalizeName(entry.getName()));
|
||||
activeAccountDate.set(entry.getDate() == null ? "" : entry.getDate());
|
||||
Identifier skin = entry.getSkin();
|
||||
activeAccountSkin.set(skin == null ? "" : skin.toString());
|
||||
applySession(entry);
|
||||
save();
|
||||
}
|
||||
|
||||
public void setActiveAccount(String name, String date, Identifier skin) {
|
||||
String cleanName = normalizeName(name);
|
||||
if (cleanName.isEmpty()) {
|
||||
clearActiveAccount();
|
||||
return;
|
||||
}
|
||||
|
||||
AccountEntry entry = findByName(cleanName);
|
||||
if (entry == null) {
|
||||
entry = addAccount(cleanName, date, skin);
|
||||
} else {
|
||||
if (!isBlank(date)) {
|
||||
entry.setDate(date);
|
||||
}
|
||||
if (skin != null) {
|
||||
entry.setSkin(skin);
|
||||
}
|
||||
}
|
||||
setActiveAccount(entry);
|
||||
}
|
||||
|
||||
public void clearActiveAccount() {
|
||||
activeAccountName.set("");
|
||||
activeAccountDate.set("");
|
||||
activeAccountSkin.set("");
|
||||
reindexAccounts();
|
||||
save();
|
||||
}
|
||||
|
||||
public String getActiveAccountName() {
|
||||
return activeAccountName.get();
|
||||
}
|
||||
|
||||
public String getActiveAccountDate() {
|
||||
return activeAccountDate.get();
|
||||
}
|
||||
|
||||
public Identifier getActiveAccountSkin() {
|
||||
return parseIdentifier(activeAccountSkin.get());
|
||||
}
|
||||
|
||||
public boolean isMicrosoftAuthorizationRequired() {
|
||||
return getMicrosoftAuthorizationRequiredAccount() != null;
|
||||
}
|
||||
|
||||
public AccountEntry getMicrosoftAuthorizationRequiredAccount() {
|
||||
if (isBlank(microsoftAuthorizationRequiredName)) {
|
||||
return null;
|
||||
}
|
||||
AccountEntry entry = findByName(microsoftAuthorizationRequiredName);
|
||||
return entry != null && entry.isMicrosoft() ? entry : null;
|
||||
}
|
||||
|
||||
public void clearMicrosoftAuthorizationRequired() {
|
||||
microsoftAuthorizationRequiredName = "";
|
||||
}
|
||||
|
||||
public void save() {
|
||||
reindexAccounts();
|
||||
ConfigSerializer.requestSave(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigName() {
|
||||
return "accounts";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConfigValue<?>> getConfigValues() {
|
||||
List<ConfigValue<?>> values = new ArrayList<>();
|
||||
values.add(accounts);
|
||||
values.add(activeAccountName);
|
||||
values.add(activeAccountDate);
|
||||
values.add(activeAccountSkin);
|
||||
return values;
|
||||
}
|
||||
|
||||
private void applyActiveSession() {
|
||||
if (isBlank(activeAccountName.get())) {
|
||||
return;
|
||||
}
|
||||
AccountEntry entry = findByName(activeAccountName.get());
|
||||
if (entry != null) {
|
||||
applySession(entry);
|
||||
} else {
|
||||
SessionChanger.changeUsername(activeAccountName.get());
|
||||
}
|
||||
}
|
||||
|
||||
private void applySession(AccountEntry entry) {
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entry.isMicrosoft()) {
|
||||
clearAuthorizationRequired(entry.getName());
|
||||
SessionChanger.changeUsername(entry.getName())
|
||||
.exceptionally(t -> {
|
||||
DebugLog.error("[AccountConfig] Failed to apply offline account session: " + entry.getName(), t);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
String refreshToken = entry.getMicrosoftRefreshToken();
|
||||
if (isBlank(refreshToken)) {
|
||||
if (SessionChanger.canUseOriginalLauncherSession(entry.getName(), entry.getOnlineUuid())) {
|
||||
clearAuthorizationRequired(entry.getName());
|
||||
SessionChanger.restoreOriginalLauncherSession(false)
|
||||
.exceptionally(t -> {
|
||||
DebugLog.error("[AccountConfig] Failed to restore launcher Microsoft session: " + entry.getName(), t);
|
||||
markAuthorizationRequired(entry);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
markAuthorizationRequired(entry);
|
||||
DebugLog.warnOnce("alt-microsoft-token-empty-" + entry.getName(), "[AccountConfig] Microsoft account requires authorization: %s", entry.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
clearAuthorizationRequired(entry.getName());
|
||||
MicrosoftAuthService.loginWithRefreshToken(refreshToken)
|
||||
.thenCompose(session -> {
|
||||
entry.applyMicrosoftSession(session);
|
||||
activeAccountName.set(session.name());
|
||||
activeAccountDate.set(entry.getDate() == null ? "" : entry.getDate());
|
||||
save();
|
||||
return SessionChanger.changeSession(session.toLoginData());
|
||||
})
|
||||
.exceptionally(t -> {
|
||||
DebugLog.error("[AccountConfig] Failed to apply Microsoft account session: " + entry.getName(), t);
|
||||
markAuthorizationRequired(entry);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void markAuthorizationRequired(AccountEntry entry) {
|
||||
microsoftAuthorizationRequiredName = entry == null ? "" : normalizeName(entry.getName());
|
||||
}
|
||||
|
||||
private void clearAuthorizationRequired(String name) {
|
||||
if (normalizeName(name).equalsIgnoreCase(normalizeName(microsoftAuthorizationRequiredName))) {
|
||||
microsoftAuthorizationRequiredName = "";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isActive(AccountEntry entry) {
|
||||
if (entry == null) {
|
||||
return false;
|
||||
}
|
||||
return normalizeName(entry.getName()).equals(normalizeName(activeAccountName.get()));
|
||||
}
|
||||
|
||||
private void reindexAccounts() {
|
||||
List<AccountEntry> list = accounts.get();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
list.get(i).setOriginalIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AccountsValue extends ConfigValue<List<AccountEntry>> {
|
||||
|
||||
private AccountsValue(String name) {
|
||||
super(name, new ArrayList<>());
|
||||
}
|
||||
|
||||
private static String stringValue(Object value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
return String.valueOf(value).trim();
|
||||
}
|
||||
|
||||
private static boolean boolValue(Object value) {
|
||||
if (value instanceof Boolean bool) {
|
||||
return bool;
|
||||
}
|
||||
if (value instanceof String string) {
|
||||
return Boolean.parseBoolean(string);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int intValue(Object value, int fallback) {
|
||||
if (value instanceof Number number) {
|
||||
return Math.max(0, number.intValue());
|
||||
}
|
||||
if (value instanceof String string) {
|
||||
try {
|
||||
return Math.max(0, Integer.parseInt(string.trim()));
|
||||
} catch (NumberFormatException ignored) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJson() {
|
||||
List<Object> out = new ArrayList<>();
|
||||
for (AccountEntry entry : value) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("name", entry.getName());
|
||||
row.put("date", entry.getDate());
|
||||
row.put("skin", entry.getSkin() == null ? "" : entry.getSkin().toString());
|
||||
row.put("pinned", entry.isPinned());
|
||||
row.put("originalIndex", entry.getOriginalIndex());
|
||||
row.put("authType", entry.getAuthType().id());
|
||||
row.put("onlineUuid", entry.getOnlineUuid() == null ? "" : entry.getOnlineUuid().toString());
|
||||
row.put("microsoftRefreshToken", "");
|
||||
out.add(row);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromJson(Object json) {
|
||||
List<AccountEntry> loaded = new ArrayList<>();
|
||||
if (json instanceof Iterable<?> iterable) {
|
||||
int fallbackIndex = 0;
|
||||
for (Object item : iterable) {
|
||||
if (!(item instanceof Map<?, ?> row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = stringValue(row.get("name"));
|
||||
if (name.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String date = stringValue(row.get("date"));
|
||||
Identifier skin = parseIdentifier(stringValue(row.get("skin")));
|
||||
boolean pinned = boolValue(row.get("pinned"));
|
||||
int originalIndex = intValue(row.get("originalIndex"), fallbackIndex);
|
||||
AccountAuthType authType = AccountAuthType.byId(stringValue(row.get("authType")));
|
||||
UUID onlineUuid = parseUuid(stringValue(row.get("onlineUuid")));
|
||||
loaded.add(new AccountEntry(name, date, skin, pinned, originalIndex, authType, onlineUuid, ""));
|
||||
fallbackIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
loaded.sort(Comparator.comparingInt(AccountEntry::getOriginalIndex));
|
||||
value = loaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.account;
|
||||
|
||||
import dev.loki.lovisual.util.session.MicrosoftSessionResult;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public final class AccountEntry {
|
||||
|
||||
private String name;
|
||||
private String date;
|
||||
@Setter
|
||||
private Identifier skin;
|
||||
@Setter
|
||||
private boolean pinned;
|
||||
private int originalIndex;
|
||||
private AccountAuthType authType;
|
||||
@Setter
|
||||
private UUID onlineUuid;
|
||||
private String microsoftRefreshToken;
|
||||
|
||||
public AccountEntry(String name, String date, Identifier skin, boolean pinned, int originalIndex) {
|
||||
this(name, date, skin, pinned, originalIndex, AccountAuthType.OFFLINE, null, "");
|
||||
}
|
||||
|
||||
public AccountEntry(String name,
|
||||
String date,
|
||||
Identifier skin,
|
||||
boolean pinned,
|
||||
int originalIndex,
|
||||
AccountAuthType authType,
|
||||
UUID onlineUuid,
|
||||
String microsoftRefreshToken) {
|
||||
this.name = name == null ? "" : name;
|
||||
this.date = date == null ? "" : date;
|
||||
this.skin = skin;
|
||||
this.pinned = pinned;
|
||||
this.originalIndex = Math.max(0, originalIndex);
|
||||
this.authType = authType == null ? AccountAuthType.OFFLINE : authType;
|
||||
this.onlineUuid = onlineUuid;
|
||||
this.microsoftRefreshToken = microsoftRefreshToken == null ? "" : microsoftRefreshToken;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name == null ? "" : name;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date == null ? "" : date;
|
||||
}
|
||||
|
||||
public void togglePinned() {
|
||||
pinned = !pinned;
|
||||
}
|
||||
|
||||
public void setOriginalIndex(int originalIndex) {
|
||||
this.originalIndex = Math.max(0, originalIndex);
|
||||
}
|
||||
|
||||
public void setAuthType(AccountAuthType authType) {
|
||||
this.authType = authType == null ? AccountAuthType.OFFLINE : authType;
|
||||
}
|
||||
|
||||
public boolean isMicrosoft() {
|
||||
return authType == AccountAuthType.MICROSOFT;
|
||||
}
|
||||
|
||||
public void setMicrosoftRefreshToken(String microsoftRefreshToken) {
|
||||
this.microsoftRefreshToken = microsoftRefreshToken == null ? "" : microsoftRefreshToken;
|
||||
}
|
||||
|
||||
public void applyMicrosoftSession(MicrosoftSessionResult session) {
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
this.authType = AccountAuthType.MICROSOFT;
|
||||
this.name = session.name();
|
||||
this.onlineUuid = session.uuid();
|
||||
this.microsoftRefreshToken = session.refreshToken();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.account;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.DefaultPlayerSkin;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.entity.player.PlayerSkin;
|
||||
import dev.loki.lovisual.util.player.PlayerSkinResolver;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum SkinManager {
|
||||
;
|
||||
|
||||
private static final Map<String, Identifier> CACHE = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Boolean> LOADING = new ConcurrentHashMap<>();
|
||||
private static final Executor EXECUTOR = Executors.newFixedThreadPool(3, runnable -> {
|
||||
Thread thread = new Thread(runnable, "LoVisual-AltSkinLoader");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
||||
public static Identifier getSkin(String playerName) {
|
||||
String key = normalizeKey(playerName);
|
||||
if (key.isEmpty()) {
|
||||
return defaultSkin(playerName);
|
||||
}
|
||||
|
||||
Identifier cached = CACHE.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
if (LOADING.putIfAbsent(key, Boolean.TRUE) == null) {
|
||||
CompletableFuture.runAsync(() -> loadSkin(playerName, key), EXECUTOR);
|
||||
}
|
||||
|
||||
return defaultSkin(playerName);
|
||||
}
|
||||
|
||||
public static void removeSkin(String playerName) {
|
||||
String key = normalizeKey(playerName);
|
||||
if (key.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
CACHE.remove(key);
|
||||
LOADING.remove(key);
|
||||
}
|
||||
|
||||
public static void reloadSkin(String playerName) {
|
||||
removeSkin(playerName);
|
||||
getSkin(playerName);
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
CACHE.clear();
|
||||
LOADING.clear();
|
||||
}
|
||||
|
||||
private static void loadSkin(String playerName, String key) {
|
||||
try {
|
||||
UUID uuid = fetchUuid(playerName);
|
||||
if (uuid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
if (client == null || client.getSkinManager() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, playerName);
|
||||
Supplier<PlayerSkin> supplier = client.getSkinManager().createLookup(profile, false);
|
||||
if (supplier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerSkin textures = supplier.get();
|
||||
Identifier skin = PlayerSkinResolver.resolveAssetId(textures == null ? null : textures.body());
|
||||
if (skin != null) {
|
||||
CACHE.put(key, skin);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
} finally {
|
||||
LOADING.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static UUID fetchUuid(String playerName) {
|
||||
String cleanName = normalizeName(playerName);
|
||||
if (cleanName.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection) URI
|
||||
.create("https://api.mojang.com/users/profiles/minecraft/" + cleanName)
|
||||
.toURL()
|
||||
.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
connection.setRequestProperty("User-Agent", "LoVisual");
|
||||
|
||||
if (connection.getResponseCode() != 200) {
|
||||
connection.disconnect();
|
||||
return null;
|
||||
}
|
||||
|
||||
try (InputStreamReader reader = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
if (!json.has("id")) {
|
||||
return null;
|
||||
}
|
||||
return parseUuid(json.get("id").getAsString());
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static UUID parseUuid(String raw) {
|
||||
if (raw == null || raw.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String value = raw.trim();
|
||||
if (value.length() == 32) {
|
||||
value = value.substring(0, 8) + "-" + value.substring(8, 12) + "-" + value.substring(12, 16)
|
||||
+ "-" + value.substring(16, 20) + "-" + value.substring(20);
|
||||
}
|
||||
|
||||
try {
|
||||
return UUID.fromString(value);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Identifier defaultSkin(String playerName) {
|
||||
String cleanName = normalizeName(playerName);
|
||||
UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + cleanName).getBytes(StandardCharsets.UTF_8));
|
||||
GameProfile profile = new GameProfile(uuid, cleanName);
|
||||
PlayerSkin textures = DefaultPlayerSkin.get(profile);
|
||||
Identifier resolved = PlayerSkinResolver.resolveAssetId(textures == null ? null : textures.body());
|
||||
if (resolved != null) {
|
||||
return resolved;
|
||||
}
|
||||
return Identifier.fromNamespaceAndPath("minecraft", "textures/entity/player/wide/steve.png");
|
||||
}
|
||||
|
||||
private static String normalizeKey(String playerName) {
|
||||
String cleanName = normalizeName(playerName);
|
||||
return cleanName.isEmpty() ? "" : cleanName.toLowerCase();
|
||||
}
|
||||
|
||||
private static String normalizeName(String playerName) {
|
||||
return playerName == null ? "" : playerName.trim();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ClientCommand {
|
||||
default CommandMetadata metadata() {
|
||||
return CommandMetadata.from(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy addon API v0 metadata hook. New commands must use {@link CommandInfo}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default String name() {
|
||||
return CommandMetadata.fromAnnotation(getClass()).id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy addon API v0 metadata hook. New commands must use {@link CommandInfo}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
default List<String> aliases() {
|
||||
CommandMetadata metadata = CommandMetadata.annotated(getClass());
|
||||
return metadata == null ? List.of() : metadata.aliases();
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy addon API v0 metadata hook. New commands must use {@link CommandInfo}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
default String usage() {
|
||||
CommandMetadata metadata = CommandMetadata.annotated(getClass());
|
||||
return metadata == null ? name() : metadata.usage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy addon API v0 metadata hook. New commands must use {@link CommandInfo}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
default String description() {
|
||||
CommandMetadata metadata = CommandMetadata.annotated(getClass());
|
||||
return metadata == null ? usage() : metadata.description();
|
||||
}
|
||||
|
||||
default boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
boolean execute(CommandContext ctx);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record CommandContext(Minecraft mc, String raw, String name, List<String> args) {
|
||||
|
||||
public String arg(int idx) {
|
||||
if (idx < 0 || idx >= args.size()) return null;
|
||||
return args.get(idx);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import dev.loki.lovisual.events.UsedImplicitly;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@UsedImplicitly
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface CommandInfo {
|
||||
String id();
|
||||
|
||||
String[] aliases() default {};
|
||||
|
||||
String usage() default "";
|
||||
|
||||
String descriptionKey() default "";
|
||||
}
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import dev.loki.lovisual.util.logging.DebugLog;
|
||||
import io.github.classgraph.ClassGraph;
|
||||
import io.github.classgraph.ClassInfo;
|
||||
import io.github.classgraph.ScanResult;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public enum CommandManager {
|
||||
;
|
||||
private static final List<ClientCommand> COMMANDS = new ArrayList<>();
|
||||
private static boolean initialized;
|
||||
|
||||
public static synchronized void init() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
discover("dev.loki.lovisual.features.command.impl");
|
||||
}
|
||||
|
||||
public static List<ClientCommand> getCommands() {
|
||||
if (!initialized) init();
|
||||
return Collections.unmodifiableList(COMMANDS);
|
||||
}
|
||||
|
||||
public static void register(ClientCommand cmd) {
|
||||
if (cmd == null) return;
|
||||
CommandMetadata metadata = cmd.metadata();
|
||||
if (findRegistered(metadata.id()) != null) {
|
||||
throw new IllegalArgumentException("Duplicate client command: @" + metadata.id());
|
||||
}
|
||||
for (String alias : metadata.aliases()) {
|
||||
if (findRegistered(alias) != null) {
|
||||
throw new IllegalArgumentException("Duplicate client command alias: @" + alias);
|
||||
}
|
||||
}
|
||||
COMMANDS.add(cmd);
|
||||
}
|
||||
|
||||
public static boolean handle(String raw) {
|
||||
if (raw == null) return false;
|
||||
String trimmed = raw.trim();
|
||||
if (!isCommandLike(trimmed)) return false;
|
||||
if (!initialized) init();
|
||||
|
||||
String body = trimmed.substring(1).trim();
|
||||
if (body.isEmpty()) return false;
|
||||
String[] parts = body.split("\\s+");
|
||||
if (parts.length == 0) return false;
|
||||
String name = parts[0].toLowerCase();
|
||||
|
||||
ClientCommand cmd = find(name);
|
||||
if (cmd == null) {
|
||||
CommandOutput.error("Unknown client command: @" + name + ". Use @help.");
|
||||
return true;
|
||||
}
|
||||
if (!cmd.isAvailable()) {
|
||||
return true; // silently ignore when command is disabled
|
||||
}
|
||||
|
||||
List<String> args = new ArrayList<>();
|
||||
args.addAll(Arrays.asList(parts).subList(1, parts.length));
|
||||
CommandContext ctx = new CommandContext(Minecraft.getInstance(), raw, name, args);
|
||||
return cmd.execute(ctx);
|
||||
}
|
||||
|
||||
public static List<Suggestion> suggest(String input, int cursor) {
|
||||
if (input == null) return List.of();
|
||||
int start = firstNonWhitespace(input);
|
||||
if (start < 0 || input.charAt(start) != '@') return List.of();
|
||||
if (!initialized) init();
|
||||
|
||||
int cursorClamped = Math.max(start + 1, Math.min(cursor, input.length()));
|
||||
String before = input.substring(start + 1, cursorClamped);
|
||||
String[] parts = before.split("\\s+", -1);
|
||||
if (parts.length == 0) return List.of();
|
||||
|
||||
int argIndex = parts.length - 1;
|
||||
String token = parts[argIndex];
|
||||
String cmdName = parts[0].toLowerCase();
|
||||
|
||||
int tokenStartInBefore = before.lastIndexOf(' ');
|
||||
tokenStartInBefore = tokenStartInBefore >= 0 ? tokenStartInBefore + 1 : 0;
|
||||
int tokenStartInInput = start + 1 + tokenStartInBefore;
|
||||
int tokenEndInInput = tokenStartInInput + token.length();
|
||||
StringRange range = StringRange.between(tokenStartInInput, tokenEndInInput);
|
||||
|
||||
List<String> suggestions;
|
||||
if (argIndex == 0) {
|
||||
suggestions = suggestCommandNames(token);
|
||||
} else {
|
||||
ClientCommand cmd = find(cmdName);
|
||||
if (cmd == null || !cmd.isAvailable()) return List.of();
|
||||
List<String> args = new ArrayList<>();
|
||||
args.addAll(Arrays.asList(parts).subList(1, parts.length));
|
||||
CommandContext ctx = new CommandContext(Minecraft.getInstance(), input, cmdName, args);
|
||||
suggestions = cmd.suggest(ctx, argIndex, token);
|
||||
}
|
||||
|
||||
if (suggestions == null || suggestions.isEmpty()) return List.of();
|
||||
List<Suggestion> out = new ArrayList<>(suggestions.size());
|
||||
for (String s : suggestions) {
|
||||
if (s == null || s.isBlank()) continue;
|
||||
out.add(new Suggestion(range, s));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static ClientCommand find(String name) {
|
||||
if (!initialized) init();
|
||||
return findRegistered(name);
|
||||
}
|
||||
|
||||
private static ClientCommand findRegistered(String name) {
|
||||
if (name == null || name.isBlank()) return null;
|
||||
for (ClientCommand cmd : COMMANDS) {
|
||||
CommandMetadata metadata = cmd.metadata();
|
||||
if (metadata.id().equalsIgnoreCase(name)) return cmd;
|
||||
for (String alias : metadata.aliases()) {
|
||||
if (alias.equalsIgnoreCase(name)) return cmd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isCommandLike(String text) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if (Character.isWhitespace(c)) continue;
|
||||
return c == '@';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<String> suggestCommandNames(String token) {
|
||||
String lower = token == null ? "" : token.toLowerCase();
|
||||
List<String> out = new ArrayList<>();
|
||||
for (ClientCommand cmd : COMMANDS) {
|
||||
if (!cmd.isAvailable()) continue;
|
||||
CommandMetadata metadata = cmd.metadata();
|
||||
if (lower.isEmpty() || metadata.id().startsWith(lower)) {
|
||||
out.add(metadata.id());
|
||||
}
|
||||
for (String alias : metadata.aliases()) {
|
||||
if (alias == null || alias.isBlank()) continue;
|
||||
if (lower.isEmpty() || alias.startsWith(lower)) {
|
||||
out.add(alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int firstNonWhitespace(String text) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if (!Character.isWhitespace(c)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static void discover(String basePackage) {
|
||||
try (ScanResult scan = new ClassGraph()
|
||||
.enableClassInfo()
|
||||
.enableAnnotationInfo()
|
||||
.acceptPackages(basePackage)
|
||||
.scan()) {
|
||||
scan.getClassesWithAnnotation(CommandInfo.class.getName()).stream()
|
||||
.map(ClassInfo::getName)
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.forEach(CommandManager::loadCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadCandidate(String className) {
|
||||
try {
|
||||
Class<?> type = Class.forName(className, false, CommandManager.class.getClassLoader());
|
||||
if (!ClientCommand.class.isAssignableFrom(type)) {
|
||||
DebugLog.config("Skipping annotated non-command: %s", type.getName());
|
||||
return;
|
||||
}
|
||||
int modifiers = type.getModifiers();
|
||||
if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || type.isAnnotation()) {
|
||||
DebugLog.config("Skipping non-concrete command class: %s", type.getName());
|
||||
return;
|
||||
}
|
||||
Constructor<?> constructor = type.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
register((ClientCommand) constructor.newInstance());
|
||||
DebugLog.config("Loaded command: %s", type.getName());
|
||||
} catch (NoSuchMethodException exception) {
|
||||
DebugLog.error("Failed to load command %s: no no-args constructor", exception, className);
|
||||
} catch (Throwable throwable) {
|
||||
DebugLog.error("Failed to load command: %s", throwable, className);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class CommandMetadata {
|
||||
private static final ClassValue<Optional<CommandMetadata>> ANNOTATED = new ClassValue<>() {
|
||||
@Override
|
||||
protected Optional<CommandMetadata> computeValue(Class<?> type) {
|
||||
CommandInfo info = type.getAnnotation(CommandInfo.class);
|
||||
return info == null ? Optional.empty() : Optional.of(from(info));
|
||||
}
|
||||
};
|
||||
|
||||
private final String id;
|
||||
private final List<String> aliases;
|
||||
private final String usage;
|
||||
private final String description;
|
||||
private final boolean localizedDescription;
|
||||
|
||||
private CommandMetadata(String id,
|
||||
List<String> aliases,
|
||||
String usage,
|
||||
String description,
|
||||
boolean localizedDescription) {
|
||||
this.id = normalizeId(id);
|
||||
this.aliases = normalizeAliases(aliases, this.id);
|
||||
this.usage = usage == null || usage.isBlank() ? "@" + this.id : usage.trim();
|
||||
if (description == null || description.isBlank()) {
|
||||
this.description = this.usage;
|
||||
this.localizedDescription = false;
|
||||
} else {
|
||||
this.description = description.trim();
|
||||
this.localizedDescription = localizedDescription;
|
||||
}
|
||||
}
|
||||
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<String> aliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public String usage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return localizedDescription ? I18n.get(description) : description;
|
||||
}
|
||||
|
||||
public String descriptionKey() {
|
||||
return localizedDescription ? description : "";
|
||||
}
|
||||
|
||||
public static CommandMetadata from(ClientCommand command) {
|
||||
if (command == null) throw new IllegalArgumentException("command cannot be null");
|
||||
|
||||
CommandMetadata annotated = annotated(command.getClass());
|
||||
if (annotated != null) return annotated;
|
||||
return fromLegacy(command);
|
||||
}
|
||||
|
||||
static CommandMetadata fromAnnotation(Class<?> type) {
|
||||
CommandMetadata annotated = annotated(type);
|
||||
if (annotated == null) {
|
||||
throw new IllegalStateException(type.getName() + " must be annotated with @CommandInfo");
|
||||
}
|
||||
return annotated;
|
||||
}
|
||||
|
||||
static CommandMetadata annotated(Class<?> type) {
|
||||
return ANNOTATED.get(type).orElse(null);
|
||||
}
|
||||
|
||||
private static CommandMetadata from(CommandInfo info) {
|
||||
return new CommandMetadata(info.id(), List.of(info.aliases()), info.usage(), info.descriptionKey(), true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static CommandMetadata fromLegacy(ClientCommand command) {
|
||||
String id = command.name();
|
||||
List<String> aliases = command.aliases();
|
||||
String usage = command.usage();
|
||||
String description = command.description();
|
||||
return new CommandMetadata(id, aliases, usage, description, false);
|
||||
}
|
||||
|
||||
private static String normalizeId(String id) {
|
||||
if (id == null || id.isBlank()) throw new IllegalArgumentException("Command id cannot be blank");
|
||||
String normalized = id.trim().toLowerCase(Locale.ROOT);
|
||||
if (normalized.charAt(0) == '@') normalized = normalized.substring(1);
|
||||
if (normalized.isBlank() || normalized.chars().anyMatch(Character::isWhitespace)) {
|
||||
throw new IllegalArgumentException("Invalid command id: " + id);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private static List<String> normalizeAliases(List<String> aliases, String id) {
|
||||
if (aliases == null || aliases.isEmpty()) return List.of();
|
||||
List<String> normalized = new ArrayList<>(aliases.size());
|
||||
for (String alias : aliases) {
|
||||
if (alias == null || alias.isBlank()) continue;
|
||||
String value = alias.trim().toLowerCase(Locale.ROOT);
|
||||
if (value.charAt(0) == '@') value = value.substring(1);
|
||||
if (value.isBlank() || value.chars().anyMatch(Character::isWhitespace) || value.equals(id)) continue;
|
||||
if (!normalized.contains(value)) normalized.add(value);
|
||||
}
|
||||
return List.copyOf(normalized);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* This file is part of the LoVisual Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
|
||||
import dev.loki.lovisual.features.theme.Theme;
|
||||
import dev.loki.lovisual.features.theme.Themes;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public enum CommandOutput {
|
||||
;
|
||||
|
||||
public static final String PREFIX = "[LoVisual]";
|
||||
private static final int MAX_RECENT_MESSAGES = 128;
|
||||
private static final Map<Component, Tone> LOVISUAL_MESSAGES =
|
||||
Collections.synchronizedMap(new WeakHashMap<>());
|
||||
private static final Deque<MessageLine> RECENT_MESSAGES = new ArrayDeque<>();
|
||||
|
||||
public record MessageLine(Component text, long timestampMs, Tone tone) {
|
||||
}
|
||||
|
||||
public enum Tone {
|
||||
INFO,
|
||||
SUCCESS,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
|
||||
public static void send(String message) {
|
||||
send(message, Tone.INFO);
|
||||
}
|
||||
|
||||
public static void success(String message) {
|
||||
send(message, Tone.SUCCESS);
|
||||
}
|
||||
|
||||
public static void warning(String message) {
|
||||
send(message, Tone.WARNING);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
send(message, Tone.ERROR);
|
||||
}
|
||||
|
||||
public static void send(String message, Tone tone) {
|
||||
if (message == null || message.isBlank()) return;
|
||||
send(Component.literal(message), tone == null ? Tone.INFO : tone);
|
||||
}
|
||||
|
||||
public static void send(Component text) {
|
||||
send(text, Tone.INFO);
|
||||
}
|
||||
|
||||
public static void send(Component text, Tone tone) {
|
||||
if (text == null) return;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.gui == null || mc.gui.hud == null) return;
|
||||
|
||||
Tone resolvedTone = tone == null ? Tone.INFO : tone;
|
||||
Component formatted = mark(format(text, resolvedTone), resolvedTone);
|
||||
remember(formatted, resolvedTone);
|
||||
mc.gui.hud.getChat().addClientSystemMessage(formatted);
|
||||
}
|
||||
|
||||
public static boolean isLoVisualMessage(Component text) {
|
||||
if (text == null) return false;
|
||||
synchronized (LOVISUAL_MESSAGES) {
|
||||
return LOVISUAL_MESSAGES.containsKey(text);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tone toneOf(Component text) {
|
||||
if (text == null) return Tone.INFO;
|
||||
synchronized (LOVISUAL_MESSAGES) {
|
||||
Tone tone = LOVISUAL_MESSAGES.get(text);
|
||||
return tone == null ? Tone.INFO : tone;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<MessageLine> recentMessages() {
|
||||
synchronized (RECENT_MESSAGES) {
|
||||
return new ArrayList<>(RECENT_MESSAGES);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearRecentMessages() {
|
||||
synchronized (RECENT_MESSAGES) {
|
||||
RECENT_MESSAGES.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static void remember(Component text, Tone tone) {
|
||||
synchronized (RECENT_MESSAGES) {
|
||||
RECENT_MESSAGES.addLast(new MessageLine(text, System.currentTimeMillis(), tone));
|
||||
while (RECENT_MESSAGES.size() > MAX_RECENT_MESSAGES) {
|
||||
RECENT_MESSAGES.removeFirst();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Component mark(Component text, Tone tone) {
|
||||
synchronized (LOVISUAL_MESSAGES) {
|
||||
LOVISUAL_MESSAGES.put(text, tone == null ? Tone.INFO : tone);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static MutableComponent format(Component body, Tone tone) {
|
||||
MutableComponent out = Component.empty();
|
||||
appendGradientPrefix(out, tone);
|
||||
out.append(Component.literal(" "));
|
||||
out.append(copyBody(body, bodyColor(tone)).withStyle(style -> style.withBold(false)));
|
||||
return out;
|
||||
}
|
||||
|
||||
private static MutableComponent copyBody(Component body, int color) {
|
||||
MutableComponent copy = body.copy();
|
||||
return copy.withStyle(style -> style.withColor(color & 0x00FFFFFF));
|
||||
}
|
||||
|
||||
private static void appendGradientPrefix(MutableComponent out, Tone tone) {
|
||||
String prefix = PREFIX;
|
||||
int start = prefixStartColor(tone);
|
||||
int end = prefixEndColor(tone);
|
||||
int steps = Math.max(1, prefix.length() - 1);
|
||||
for (int i = 0; i < prefix.length(); i++) {
|
||||
final int color = mixRgb(start, end, i / (float) steps) & 0x00FFFFFF;
|
||||
out.append(Component.literal(String.valueOf(prefix.charAt(i)))
|
||||
.withStyle(style -> style.withColor(color).withBold(true)));
|
||||
}
|
||||
}
|
||||
|
||||
public static int prefixStartColor(Tone tone) {
|
||||
Themes.Theme theme = Theme.theme();
|
||||
int accent = theme.accent();
|
||||
return switch (tone) {
|
||||
case SUCCESS -> mixRgb(accent, 0xFF55FF93, 0.45f);
|
||||
case WARNING -> mixRgb(accent, 0xFFFFC85A, 0.45f);
|
||||
case ERROR -> mixRgb(accent, 0xFFFF6A6A, 0.55f);
|
||||
default -> accent;
|
||||
};
|
||||
}
|
||||
|
||||
public static int prefixEndColor(Tone tone) {
|
||||
Themes.Theme theme = Theme.theme();
|
||||
int text = theme.textPrimary();
|
||||
int accentSoft = theme.accentSoft();
|
||||
return switch (tone) {
|
||||
case SUCCESS -> mixRgb(text, 0xFF55FF93, 0.28f);
|
||||
case WARNING -> mixRgb(text, 0xFFFFD985, 0.32f);
|
||||
case ERROR -> mixRgb(text, 0xFFFF8A8A, 0.42f);
|
||||
default -> mixRgb(text, accentSoft, 0.35f);
|
||||
};
|
||||
}
|
||||
|
||||
public static int bodyColor(Tone tone) {
|
||||
Themes.Theme theme = Theme.theme();
|
||||
int base = mixRgb(theme.textPrimary(), 0xFFFFFFFF, 0.24f);
|
||||
return switch (tone) {
|
||||
case SUCCESS -> mixRgb(base, 0xFFBFFFE0, 0.18f);
|
||||
case WARNING -> mixRgb(base, 0xFFFFE5A8, 0.18f);
|
||||
case ERROR -> mixRgb(base, 0xFFFFB0B0, 0.25f);
|
||||
default -> base;
|
||||
};
|
||||
}
|
||||
|
||||
public static int mixRgb(int a, int b, float t) {
|
||||
t = Math.max(0.0f, Math.min(1.0f, t));
|
||||
int ar = (a >> 16) & 0xFF;
|
||||
int ag = (a >> 8) & 0xFF;
|
||||
int ab = a & 0xFF;
|
||||
int br = (b >> 16) & 0xFF;
|
||||
int bg = (b >> 8) & 0xFF;
|
||||
int bb = b & 0xFF;
|
||||
int r = Math.round(ar + (br - ar) * t);
|
||||
int g = Math.round(ag + (bg - ag) * t);
|
||||
int bl = Math.round(ab + (bb - ab) * t);
|
||||
return 0xFF000000 | (r << 16) | (g << 8) | bl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.ChatComponent;
|
||||
|
||||
public enum VanillaChatRuntimeCleanup {
|
||||
;
|
||||
|
||||
public static void clearVanillaChatCache() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.gui == null || mc.gui.hud == null) return;
|
||||
ChatComponent chat = mc.gui.hud.getChat();
|
||||
if (chat != null) {
|
||||
chat.clearMessages(true);
|
||||
}
|
||||
CommandOutput.clearRecentMessages();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.addon.AddonIssue;
|
||||
import dev.loki.lovisual.addon.AddonManager;
|
||||
import dev.loki.lovisual.addon.AddonSnapshot;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "addons",
|
||||
usage = "@addons [list|scan|enable|disable] [id]",
|
||||
descriptionKey = "command.addons.description"
|
||||
)
|
||||
public final class AddonsCommand implements ClientCommand {
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
if (argIndex == 1) {
|
||||
return List.of("list", "scan", "enable", "disable").stream()
|
||||
.filter(value -> value.startsWith(lower))
|
||||
.toList();
|
||||
}
|
||||
if (argIndex == 2) {
|
||||
return AddonManager.snapshots().stream()
|
||||
.map(AddonSnapshot::id)
|
||||
.filter(id -> lower.isEmpty() || id.startsWith(lower))
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String action = ctx.arg(0);
|
||||
if (action == null || action.isBlank() || "list".equalsIgnoreCase(action)) {
|
||||
list();
|
||||
return true;
|
||||
}
|
||||
if ("scan".equalsIgnoreCase(action)) {
|
||||
scan();
|
||||
return true;
|
||||
}
|
||||
if ("enable".equalsIgnoreCase(action) || "disable".equalsIgnoreCase(action)) {
|
||||
String id = ctx.arg(1);
|
||||
if (id == null || id.isBlank()) {
|
||||
CommandOutput.send("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
boolean enabled = "enable".equalsIgnoreCase(action);
|
||||
boolean ok = AddonManager.setEnabled(id, enabled);
|
||||
CommandOutput.send(ok
|
||||
? "Addon " + id + " " + (enabled ? "enabled" : "disabled")
|
||||
: "Addon not found: " + id);
|
||||
return true;
|
||||
}
|
||||
CommandOutput.send("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void list() {
|
||||
List<AddonSnapshot> addons = AddonManager.snapshots();
|
||||
if (addons.isEmpty()) {
|
||||
CommandOutput.send("No LoVisual addons installed.");
|
||||
return;
|
||||
}
|
||||
for (AddonSnapshot addon : addons) {
|
||||
CommandOutput.send(addon.id() + " " + addon.version()
|
||||
+ " [" + addon.status().name().toLowerCase(Locale.ROOT) + "]"
|
||||
+ " modules=" + addon.modules()
|
||||
+ " hud=" + (addon.draggableHudElements() + addon.staticHudElements())
|
||||
+ " commands=" + addon.commands()
|
||||
+ " clickGui=" + addon.clickGuiSections()
|
||||
+ " extensions=" + addon.moduleExtensions()
|
||||
+ " irisPatches=" + addon.irisPatchManifests()
|
||||
+ (addon.restartRequired() ? " restart-required" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
private static void scan() {
|
||||
for (AddonIssue issue : AddonManager.scan()) {
|
||||
CommandOutput.send("Addon scan " + issue.severity().name().toLowerCase(Locale.ROOT)
|
||||
+ " [" + issue.addonId() + "]: " + issue.message()
|
||||
+ (issue.detail() == null || issue.detail().isBlank() ? "" : " (" + issue.detail() + ")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.util.input.KeyUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "bind",
|
||||
aliases = {"binds", "keybind"},
|
||||
usage = "@bind <module> <key|combo|none> | @bind list",
|
||||
descriptionKey = "command.bind.description"
|
||||
)
|
||||
public final class BindCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String moduleArg = ctx.arg(0);
|
||||
if (moduleArg != null && moduleArg.equalsIgnoreCase("list")) {
|
||||
listBinds();
|
||||
return true;
|
||||
}
|
||||
Module module = CommandUtils.findModule(moduleArg);
|
||||
if (module == null) {
|
||||
CommandOutput.error(moduleArg == null ? "Usage: " + metadata().usage() : "Module not found: " + moduleArg);
|
||||
return true;
|
||||
}
|
||||
String key = ctx.arg(1);
|
||||
if (key == null) {
|
||||
CommandOutput.send(module.getDisplayName() + " bind: " + module.getKeyBindSetting().getValue().get());
|
||||
return true;
|
||||
}
|
||||
String normalized = key.trim().toUpperCase(Locale.ROOT);
|
||||
if (!normalized.equals("NONE") && KeyUtil.stringToCombo(normalized).isEmpty()) {
|
||||
CommandOutput.error("Unknown key or combo: " + key);
|
||||
return true;
|
||||
}
|
||||
module.getKeyBindSetting().setKeyByName(normalized);
|
||||
module.saveConfig();
|
||||
CommandOutput.success(module.getDisplayName() + " bound to " + normalized);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex == 1) {
|
||||
List<String> modules = CommandUtils.suggestModules(token);
|
||||
if (token == null || token.isBlank() || "list".startsWith(token.toLowerCase(Locale.ROOT))) {
|
||||
java.util.ArrayList<String> out = new java.util.ArrayList<>(modules);
|
||||
out.add("list");
|
||||
return out;
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
if (argIndex == 2) return List.of("NONE", "R", "V", "LEFT_CTRL+R");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private static void listBinds() {
|
||||
List<Module> bound = CommandUtils.sortedModules().stream()
|
||||
.filter(module -> !module.getKeyBindSetting().getValue().isNone())
|
||||
.toList();
|
||||
if (bound.isEmpty()) {
|
||||
CommandOutput.send("No module binds configured.");
|
||||
return;
|
||||
}
|
||||
CommandOutput.send("Module binds: " + bound.size());
|
||||
for (Module module : bound) {
|
||||
CommandOutput.send(module.getDisplayName() + " — " + module.getKeyBindSetting().getValue().get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
final class CommandUtils {
|
||||
private CommandUtils() {
|
||||
}
|
||||
|
||||
static Module findModule(String query) {
|
||||
if (query == null || query.isBlank()) return null;
|
||||
for (Module module : ModuleManager.getModules()) {
|
||||
if (matchesModule(module, query)) return module;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<String> suggestModules(String token) {
|
||||
String lower = normalize(token);
|
||||
return ModuleManager.getModules().stream()
|
||||
.map(Module::name)
|
||||
.filter(name -> lower.isEmpty() || name.startsWith(lower))
|
||||
.sorted(String.CASE_INSENSITIVE_ORDER)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static List<String> suggestPlayers(Minecraft mc, String token) {
|
||||
if (mc == null || mc.getConnection() == null) return List.of();
|
||||
String lower = normalize(token);
|
||||
List<String> names = new ArrayList<>();
|
||||
for (PlayerInfo info : mc.getConnection().getOnlinePlayers()) {
|
||||
if (info == null || info.getProfile() == null) continue;
|
||||
String name = info.getProfile().name();
|
||||
if (name != null && (lower.isEmpty() || name.toLowerCase(Locale.ROOT).startsWith(lower))) {
|
||||
names.add(name);
|
||||
}
|
||||
}
|
||||
names.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
return names;
|
||||
}
|
||||
|
||||
static List<Module> sortedModules() {
|
||||
return ModuleManager.getModules().stream()
|
||||
.sorted(Comparator.comparing(Module::name, String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
}
|
||||
|
||||
static String join(List<String> parts, int start) {
|
||||
if (parts == null || start < 0 || start >= parts.size()) return "";
|
||||
return String.join(" ", parts.subList(start, parts.size())).trim();
|
||||
}
|
||||
|
||||
static boolean parseState(String value, boolean current) {
|
||||
if (value == null || value.isBlank() || value.equalsIgnoreCase("toggle")) return !current;
|
||||
return value.equalsIgnoreCase("on")
|
||||
|| value.equalsIgnoreCase("true")
|
||||
|| value.equalsIgnoreCase("enable")
|
||||
|| value.equalsIgnoreCase("enabled")
|
||||
|| value.equals("1");
|
||||
}
|
||||
|
||||
static boolean isState(String value) {
|
||||
if (value == null) return true;
|
||||
return switch (value.toLowerCase(Locale.ROOT)) {
|
||||
case "toggle", "on", "off", "true", "false", "enable", "disable", "enabled", "disabled", "1", "0" -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean matchesModule(Module module, String query) {
|
||||
if (module.name().equalsIgnoreCase(query) || module.getDisplayName().equalsIgnoreCase(query)) return true;
|
||||
for (String alias : module.getAliases()) {
|
||||
if (alias.equalsIgnoreCase(query)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value == null ? "" : value.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.config.ConfigPaths;
|
||||
import dev.loki.lovisual.config.ConfigSerializer;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.module.ModuleManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "config",
|
||||
aliases = {"cfg", "settings"},
|
||||
usage = "@config [save|load|path]",
|
||||
descriptionKey = "command.config.description"
|
||||
)
|
||||
public final class ConfigCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String action = ctx.arg(0) == null ? "save" : ctx.arg(0).toLowerCase(Locale.ROOT);
|
||||
switch (action) {
|
||||
case "save" -> {
|
||||
ModuleManager.saveAllModuleConfigs();
|
||||
ConfigSerializer.saveAll();
|
||||
CommandOutput.success("Client config saved.");
|
||||
}
|
||||
case "load", "reload" -> {
|
||||
ConfigSerializer.loadAll();
|
||||
ModuleManager.loadAllModuleConfigs();
|
||||
CommandOutput.success("Client config reloaded.");
|
||||
}
|
||||
case "path", "folder" -> CommandOutput.send("Config directory: " + ConfigPaths.root().toAbsolutePath());
|
||||
default -> CommandOutput.warning("Usage: " + metadata().usage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex != 1) return List.of();
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
return List.of("save", "load", "path").stream().filter(value -> value.startsWith(lower)).toList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "coordinates",
|
||||
aliases = {"coords", "position", "pos"},
|
||||
usage = "@coordinates",
|
||||
descriptionKey = "command.coordinates.description"
|
||||
)
|
||||
public final class CoordinatesCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
if (ctx.mc() == null || ctx.mc().player == null) {
|
||||
CommandOutput.error("Player is unavailable.");
|
||||
return true;
|
||||
}
|
||||
CommandOutput.send(String.format(Locale.ROOT, "Position: %.2f, %.2f, %.2f | Block: %d, %d, %d",
|
||||
ctx.mc().player.getX(), ctx.mc().player.getY(), ctx.mc().player.getZ(),
|
||||
ctx.mc().player.getBlockX(), ctx.mc().player.getBlockY(), ctx.mc().player.getBlockZ()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandManager;
|
||||
import dev.loki.lovisual.features.command.CommandMetadata;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "help",
|
||||
aliases = {"commands", "cmds"},
|
||||
usage = "@help [page|command]",
|
||||
descriptionKey = "command.help.description"
|
||||
)
|
||||
public final class HelpCommand implements ClientCommand {
|
||||
private static final int PAGE_SIZE = 7;
|
||||
private static final int TITLE_COLOR = 0xFF7EC8FF;
|
||||
private static final int COMMAND_COLOR = 0xFFFFFFFF;
|
||||
private static final int MUTED_COLOR = 0xFF9AA7B5;
|
||||
private static final int ACTIVE_COLOR = 0xFF70E0A0;
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String selector = ctx.arg(0);
|
||||
if (selector != null && !selector.isBlank() && !isInteger(selector)) {
|
||||
ClientCommand command = CommandManager.find(selector.toLowerCase(Locale.ROOT));
|
||||
if (command == null || !command.isAvailable()) {
|
||||
CommandOutput.error("Command not found: @" + selector);
|
||||
return true;
|
||||
}
|
||||
showDetails(command);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<ClientCommand> commands = CommandManager.getCommands().stream()
|
||||
.filter(ClientCommand::isAvailable)
|
||||
.sorted(Comparator.comparing(command -> command.metadata().id(), String.CASE_INSENSITIVE_ORDER))
|
||||
.toList();
|
||||
int pages = Math.max(1, (commands.size() + PAGE_SIZE - 1) / PAGE_SIZE);
|
||||
int page = Math.max(1, Math.min(parseInt(selector, 1), pages));
|
||||
int from = Math.min(commands.size(), (page - 1) * PAGE_SIZE);
|
||||
int to = Math.min(commands.size(), from + PAGE_SIZE);
|
||||
|
||||
MutableComponent message = Component.empty();
|
||||
message.append(Component.literal("Client commands " + commands.size())
|
||||
.withStyle(style -> style.withBold(true).withColor(TITLE_COLOR)));
|
||||
message.append(Component.literal(" - page " + page + "/" + pages)
|
||||
.withStyle(style -> style.withColor(MUTED_COLOR)));
|
||||
|
||||
for (int i = from; i < to; i++) {
|
||||
ClientCommand command = commands.get(i);
|
||||
message.append(Component.literal("\n- ").withStyle(style -> style.withColor(MUTED_COLOR)));
|
||||
message.append(commandLink(command));
|
||||
message.append(Component.literal(" - " + command.metadata().description())
|
||||
.withStyle(style -> style.withColor(MUTED_COLOR)));
|
||||
}
|
||||
|
||||
message.append(Component.literal("\n"));
|
||||
if (page > 1) {
|
||||
message.append(pageButton("< previous", page - 1));
|
||||
} else {
|
||||
message.append(Component.literal("< previous").withStyle(style -> style.withColor(0xFF59616B)));
|
||||
}
|
||||
message.append(Component.literal(" "));
|
||||
if (page < pages) {
|
||||
message.append(pageButton("next >", page + 1));
|
||||
} else {
|
||||
message.append(Component.literal("next >").withStyle(style -> style.withColor(0xFF59616B)));
|
||||
}
|
||||
CommandOutput.send(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex != 1) return List.of();
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
return CommandManager.getCommands().stream()
|
||||
.filter(ClientCommand::isAvailable)
|
||||
.map(command -> command.metadata().id())
|
||||
.filter(name -> lower.isEmpty() || name.startsWith(lower))
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static MutableComponent commandLink(ClientCommand command) {
|
||||
CommandMetadata metadata = command.metadata();
|
||||
String insert = "@" + metadata.id() + " ";
|
||||
String aliases = metadata.aliases().isEmpty() ? "none" : String.join(", ", metadata.aliases());
|
||||
Component hover = Component.literal(metadata.description()
|
||||
+ "\nUsage: " + metadata.usage()
|
||||
+ "\nAliases: " + aliases
|
||||
+ "\nClick to insert");
|
||||
return Component.literal("@" + metadata.id())
|
||||
.withStyle(style -> style
|
||||
.withColor(COMMAND_COLOR)
|
||||
.withUnderlined(true)
|
||||
.withClickEvent(new ClickEvent.SuggestCommand(insert))
|
||||
.withHoverEvent(new HoverEvent.ShowText(hover)));
|
||||
}
|
||||
|
||||
private static MutableComponent pageButton(String label, int page) {
|
||||
return Component.literal(label)
|
||||
.withStyle(style -> style
|
||||
.withBold(true)
|
||||
.withColor(ACTIVE_COLOR)
|
||||
.withClickEvent(new ClickEvent.RunCommand("@help " + page))
|
||||
.withHoverEvent(new HoverEvent.ShowText(Component.literal("Open help page " + page))));
|
||||
}
|
||||
|
||||
private static void showDetails(ClientCommand command) {
|
||||
CommandMetadata metadata = command.metadata();
|
||||
MutableComponent message = Component.literal("@" + metadata.id())
|
||||
.withStyle(style -> style.withBold(true).withColor(TITLE_COLOR));
|
||||
message.append(Component.literal("\n" + metadata.description()).withStyle(style -> style.withColor(COMMAND_COLOR)));
|
||||
message.append(Component.literal("\nUsage: " + metadata.usage()).withStyle(style -> style.withColor(MUTED_COLOR)));
|
||||
if (!metadata.aliases().isEmpty()) {
|
||||
message.append(Component.literal("\nAliases: " + String.join(", ", metadata.aliases()))
|
||||
.withStyle(style -> style.withColor(MUTED_COLOR)));
|
||||
}
|
||||
CommandOutput.send(message);
|
||||
}
|
||||
|
||||
private static boolean isInteger(String value) {
|
||||
try {
|
||||
Integer.parseInt(value);
|
||||
return true;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int parseInt(String value, int fallback) {
|
||||
if (value == null) return fallback;
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "hide",
|
||||
aliases = {"modulevisibility", "showmodule"},
|
||||
usage = "@hide <module> [on|off|toggle]",
|
||||
descriptionKey = "command.hide.description"
|
||||
)
|
||||
public final class HideCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
Module module = CommandUtils.findModule(ctx.arg(0));
|
||||
if (module == null) {
|
||||
CommandOutput.error(ctx.arg(0) == null ? "Usage: " + metadata().usage() : "Module not found: " + ctx.arg(0));
|
||||
return true;
|
||||
}
|
||||
String action = ctx.arg(1);
|
||||
if (!CommandUtils.isState(action)) {
|
||||
CommandOutput.warning("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
boolean hidden = CommandUtils.parseState(action, !module.isShownInModuleList());
|
||||
module.setShownInModuleList(!hidden);
|
||||
CommandOutput.success(module.getDisplayName() + (hidden ? " hidden from ModuleList" : " shown in ModuleList"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex == 1) return CommandUtils.suggestModules(token);
|
||||
if (argIndex == 2) {
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
return List.of("on", "off", "toggle").stream().filter(value -> value.startsWith(lower)).toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.render.iris.IrisCompatibilityFeature;
|
||||
import dev.loki.lovisual.render.iris.IrisCompatibilityProfile;
|
||||
import dev.loki.lovisual.render.iris.IrisRuntime;
|
||||
import dev.loki.lovisual.render.iris.IrisRuntimeSnapshot;
|
||||
import dev.loki.lovisual.render.iris.patch.ShaderPatchEngine;
|
||||
import dev.loki.lovisual.runtime.RuntimeGate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandInfo(
|
||||
id = "iris",
|
||||
aliases = "shaderpack",
|
||||
usage = "@iris",
|
||||
descriptionKey = "command.iris.description"
|
||||
)
|
||||
public final class IrisCommand implements ClientCommand {
|
||||
private static String formatFeature(IrisCompatibilityFeature feature) {
|
||||
return feature.name().toLowerCase(java.util.Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !RuntimeGate.isPanic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
IrisRuntimeSnapshot snapshot = IrisRuntime.snapshot();
|
||||
CommandOutput.send(snapshot.shortLine());
|
||||
|
||||
if (!snapshot.modLoaded()) {
|
||||
return true;
|
||||
}
|
||||
CommandOutput.send("Iris API: " + (snapshot.apiAvailable() ? "available" : "unavailable")
|
||||
+ ", status: " + snapshot.status()
|
||||
+ ", shadow pass: " + snapshot.renderingShadowPass());
|
||||
|
||||
IrisCompatibilityProfile profile = snapshot.profile();
|
||||
String features = profile.features().isEmpty()
|
||||
? "none"
|
||||
: profile.features().stream()
|
||||
.map(IrisCommand::formatFeature)
|
||||
.collect(Collectors.joining(", "));
|
||||
CommandOutput.send("Iris profile: " + profile.getId()
|
||||
+ " (" + profile.displayName() + "), features: " + features);
|
||||
List<String> patchDiagnostics = ShaderPatchEngine.diagnostics();
|
||||
CommandOutput.send("Iris patch compiler: " + (patchDiagnostics.isEmpty() ? "no session data" : "session data follows"));
|
||||
for (String diagnostic : patchDiagnostics) {
|
||||
CommandOutput.send("patch " + diagnostic);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
import dev.loki.lovisual.features.module.ModuleCategory;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "modules",
|
||||
aliases = {"modulelist", "mods"},
|
||||
usage = "@modules [all|enabled|combat|movement|player|visuals|misc] [page]",
|
||||
descriptionKey = "command.modules.description"
|
||||
)
|
||||
public final class ModulesCommand implements ClientCommand {
|
||||
private static final int PAGE_SIZE = 10;
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String filter = ctx.arg(0) == null ? "all" : ctx.arg(0).toLowerCase(Locale.ROOT);
|
||||
List<Module> modules = CommandUtils.sortedModules().stream()
|
||||
.filter(module -> accepts(module, filter))
|
||||
.toList();
|
||||
if (!filter.equals("all") && !filter.equals("enabled") && parseCategory(filter) == null) {
|
||||
CommandOutput.warning("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
int pages = Math.max(1, (modules.size() + PAGE_SIZE - 1) / PAGE_SIZE);
|
||||
int page = Math.max(1, Math.min(parsePage(ctx.arg(1)), pages));
|
||||
int from = Math.min(modules.size(), (page - 1) * PAGE_SIZE);
|
||||
int to = Math.min(modules.size(), from + PAGE_SIZE);
|
||||
|
||||
MutableComponent message = Component.literal("Modules " + filter + " (" + modules.size() + ") — " + page + "/" + pages)
|
||||
.withStyle(style -> style.withBold(true).withColor(0xFF7EC8FF));
|
||||
for (int i = from; i < to; i++) {
|
||||
Module module = modules.get(i);
|
||||
int color = module.isEnabled() ? 0xFF70E0A0 : 0xFF9AA7B5;
|
||||
message.append(Component.literal("\n• "));
|
||||
message.append(Component.literal(module.getDisplayName())
|
||||
.withStyle(style -> style
|
||||
.withColor(color)
|
||||
.withClickEvent(new ClickEvent.RunCommand("@toggle " + module.name()))
|
||||
.withHoverEvent(new HoverEvent.ShowText(Component.literal(
|
||||
module.getDescription() + "\nClick to toggle\nID: " + module.name())))));
|
||||
message.append(Component.literal(" [" + (module.isEnabled() ? "ON" : "OFF") + "]")
|
||||
.withStyle(style -> style.withColor(color)));
|
||||
}
|
||||
if (pages > 1) {
|
||||
message.append(Component.literal("\n"));
|
||||
if (page > 1) message.append(pageButton("‹", filter, page - 1));
|
||||
message.append(Component.literal(" page " + page + "/" + pages + " "));
|
||||
if (page < pages) message.append(pageButton("›", filter, page + 1));
|
||||
}
|
||||
CommandOutput.send(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex != 1) return List.of();
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
return List.of("all", "enabled", "combat", "movement", "player", "visuals", "misc").stream()
|
||||
.filter(value -> value.startsWith(lower)).toList();
|
||||
}
|
||||
|
||||
private static boolean accepts(Module module, String filter) {
|
||||
if (filter.equals("all")) return true;
|
||||
if (filter.equals("enabled")) return module.isEnabled();
|
||||
ModuleCategory category = parseCategory(filter);
|
||||
return category != null && module.getCategory() == category;
|
||||
}
|
||||
|
||||
private static ModuleCategory parseCategory(String value) {
|
||||
try {
|
||||
return ModuleCategory.valueOf(value.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static int parsePage(String value) {
|
||||
try {
|
||||
return value == null ? 1 : Integer.parseInt(value);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static MutableComponent pageButton(String label, String filter, int page) {
|
||||
return Component.literal(label).withStyle(style -> style
|
||||
.withBold(true)
|
||||
.withColor(0xFF70E0A0)
|
||||
.withClickEvent(new ClickEvent.RunCommand("@modules " + filter + " " + page)));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.util.player.NetworkStatsUtil;
|
||||
|
||||
@CommandInfo(
|
||||
id = "ping",
|
||||
aliases = "latency",
|
||||
usage = "@ping",
|
||||
descriptionKey = "command.ping.description"
|
||||
)
|
||||
public final class PingCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
int ping = NetworkStatsUtil.getPing(ctx.mc());
|
||||
if (ping < 0) CommandOutput.warning("Ping is unavailable.");
|
||||
else CommandOutput.send("Ping: " + ping + " ms");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.config.ConfigSerializer;
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.relations.PlayerRelations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class RelationCommand implements ClientCommand {
|
||||
protected abstract Set<String> entries(PlayerRelations relations);
|
||||
|
||||
protected abstract boolean add(PlayerRelations relations, String name);
|
||||
|
||||
protected abstract boolean remove(PlayerRelations relations, String name);
|
||||
|
||||
protected abstract String singular();
|
||||
|
||||
@Override
|
||||
public final boolean execute(CommandContext ctx) {
|
||||
PlayerRelations relations = PlayerRelations.get();
|
||||
String action = ctx.arg(0);
|
||||
if (action == null || action.equalsIgnoreCase("list")) {
|
||||
list(entries(relations));
|
||||
return true;
|
||||
}
|
||||
if (action.equalsIgnoreCase("clear")) {
|
||||
int count = entries(relations).size();
|
||||
entries(relations).clear();
|
||||
save(relations);
|
||||
CommandOutput.success("Cleared " + count + ' ' + singular() + " entries.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = ctx.arg(1);
|
||||
if (name == null || name.isBlank()) {
|
||||
CommandOutput.warning("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
|
||||
String stored = find(entries(relations), name);
|
||||
boolean changed;
|
||||
String result;
|
||||
switch (action.toLowerCase(Locale.ROOT)) {
|
||||
case "add" -> {
|
||||
changed = stored == null && add(relations, name);
|
||||
result = changed ? "Added " + name + " as " + singular() + '.' : name + " is already listed.";
|
||||
}
|
||||
case "remove", "delete", "del" -> {
|
||||
changed = stored != null && remove(relations, stored);
|
||||
result = changed ? "Removed " + stored + " from " + singular() + " list." : name + " is not listed.";
|
||||
}
|
||||
case "toggle" -> {
|
||||
changed = stored == null ? add(relations, name) : remove(relations, stored);
|
||||
result = stored == null ? "Added " + name + " as " + singular() + '.' : "Removed " + stored + " from " + singular() + " list.";
|
||||
}
|
||||
default -> {
|
||||
CommandOutput.warning("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (changed) save(relations);
|
||||
if (changed) CommandOutput.success(result);
|
||||
else CommandOutput.warning(result);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
if (argIndex == 1) {
|
||||
return List.of("list", "add", "remove", "toggle", "clear").stream()
|
||||
.filter(value -> value.startsWith(lower))
|
||||
.toList();
|
||||
}
|
||||
if (argIndex == 2) {
|
||||
List<String> names = new ArrayList<>(CommandUtils.suggestPlayers(ctx.mc(), token));
|
||||
for (String entry : entries(PlayerRelations.get())) {
|
||||
if ((lower.isEmpty() || entry.toLowerCase(Locale.ROOT).startsWith(lower)) && !names.contains(entry)) {
|
||||
names.add(entry);
|
||||
}
|
||||
}
|
||||
names.sort(String.CASE_INSENSITIVE_ORDER);
|
||||
return names;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private void list(Set<String> values) {
|
||||
if (values.isEmpty()) {
|
||||
CommandOutput.send("No " + singular() + " entries.");
|
||||
return;
|
||||
}
|
||||
List<String> sorted = values.stream().sorted(String.CASE_INSENSITIVE_ORDER).toList();
|
||||
CommandOutput.send(Character.toUpperCase(singular().charAt(0)) + singular().substring(1) + " (" + sorted.size() + "): "
|
||||
+ String.join(", ", sorted));
|
||||
}
|
||||
|
||||
private static String find(Set<String> entries, String query) {
|
||||
for (String entry : entries) {
|
||||
if (entry.equalsIgnoreCase(query)) return entry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void save(PlayerRelations relations) {
|
||||
ConfigSerializer.save(relations);
|
||||
}
|
||||
|
||||
@CommandInfo(
|
||||
id = "friend",
|
||||
aliases = {"friends", "f"},
|
||||
usage = "@friend [list|add|remove|toggle|clear] [player]",
|
||||
descriptionKey = "command.friend.description"
|
||||
)
|
||||
public static final class Friends extends RelationCommand {
|
||||
@Override protected Set<String> entries(PlayerRelations relations) { return relations.getFriends(); }
|
||||
@Override protected boolean add(PlayerRelations relations, String name) { return relations.addFriend(name); }
|
||||
@Override protected boolean remove(PlayerRelations relations, String name) { return relations.removeFriend(name); }
|
||||
@Override protected String singular() { return "friend"; }
|
||||
}
|
||||
|
||||
@CommandInfo(
|
||||
id = "enemy",
|
||||
aliases = {"enemies", "e"},
|
||||
usage = "@enemy [list|add|remove|toggle|clear] [player]",
|
||||
descriptionKey = "command.enemy.description"
|
||||
)
|
||||
public static final class Enemies extends RelationCommand {
|
||||
@Override protected Set<String> entries(PlayerRelations relations) { return relations.getEnemies(); }
|
||||
@Override protected boolean add(PlayerRelations relations, String name) { return relations.addEnemy(name); }
|
||||
@Override protected boolean remove(PlayerRelations relations, String name) { return relations.removeEnemy(name); }
|
||||
@Override protected String singular() { return "enemy"; }
|
||||
}
|
||||
|
||||
@CommandInfo(
|
||||
id = "staff",
|
||||
aliases = {"staffs", "admin"},
|
||||
usage = "@staff [list|add|remove|toggle|clear] [player]",
|
||||
descriptionKey = "command.staff.description"
|
||||
)
|
||||
public static final class Staff extends RelationCommand {
|
||||
@Override protected Set<String> entries(PlayerRelations relations) { return relations.getStaff(); }
|
||||
@Override protected boolean add(PlayerRelations relations, String name) { return relations.addStaff(name); }
|
||||
@Override protected boolean remove(PlayerRelations relations, String name) { return relations.removeStaff(name); }
|
||||
@Override protected String singular() { return "staff"; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.runtime.ClientRuntime;
|
||||
import dev.loki.lovisual.runtime.ClientRuntimeState;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
@CommandInfo(
|
||||
id = "runtime",
|
||||
aliases = {"panic", "jarreplace"},
|
||||
usage = "@runtime [status|panic|resume|jar|source]",
|
||||
descriptionKey = "command.runtime.description"
|
||||
)
|
||||
public final class RuntimeCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
String action = ctx.arg(0);
|
||||
if (action == null || action.equalsIgnoreCase("status")) {
|
||||
sendStatus();
|
||||
return true;
|
||||
}
|
||||
if (action.equalsIgnoreCase("panic")) {
|
||||
ClientRuntime.toggleSoftPanic("runtime command");
|
||||
CommandOutput.send("Runtime state: " + ClientRuntime.state());
|
||||
return true;
|
||||
}
|
||||
if (action.equalsIgnoreCase("resume")) {
|
||||
if (ClientRuntime.state() == ClientRuntimeState.SOFT_PANIC) {
|
||||
ClientRuntime.exitSoftPanic("runtime command");
|
||||
}
|
||||
CommandOutput.send("Runtime state: " + ClientRuntime.state());
|
||||
return true;
|
||||
}
|
||||
if (action.equalsIgnoreCase("jar") || action.equalsIgnoreCase("replace")) {
|
||||
ClientRuntime.prepareJarReplacement("runtime command");
|
||||
CommandOutput.send("Client is fully disabled for safe JAR replacement. Restart Minecraft to use the new JAR.");
|
||||
return true;
|
||||
}
|
||||
if (action.equalsIgnoreCase("source")) {
|
||||
Path jar = ClientRuntime.loaderBridge().currentModJarPath();
|
||||
CommandOutput.send("Loader: standardFabric=" + ClientRuntime.loaderBridge().isStandardFabric()
|
||||
+ ", safeJarReplacement=" + ClientRuntime.loaderBridge().supportsSafeJarReplacement());
|
||||
CommandOutput.send("Current mod source: " + (jar == null ? "<unknown>" : jar.toAbsolutePath()));
|
||||
CommandOutput.send("LoVisual class source: "
|
||||
+ ClientRuntime.loaderBridge().describeClassSource("dev.loki.lovisual.LoVisual"));
|
||||
return true;
|
||||
}
|
||||
CommandOutput.send("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex != 1) return List.of();
|
||||
String lower = token == null ? "" : token.toLowerCase();
|
||||
return List.of("status", "panic", "resume", "jar", "source").stream()
|
||||
.filter(value -> lower.isEmpty() || value.startsWith(lower))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void sendStatus() {
|
||||
for (String line : ClientRuntime.diagnostics().lines()) {
|
||||
CommandOutput.send(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.util.player.NetworkStatsUtil;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "serverinfo",
|
||||
aliases = {"server", "sinfo"},
|
||||
usage = "@serverinfo",
|
||||
descriptionKey = "command.serverinfo.description"
|
||||
)
|
||||
public final class ServerInfoCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
if (ctx.mc() == null || ctx.mc().level == null) {
|
||||
CommandOutput.error("No world is loaded.");
|
||||
return true;
|
||||
}
|
||||
if (ctx.mc().hasSingleplayerServer()) {
|
||||
String name = ctx.mc().getSingleplayerServer() == null
|
||||
? "Singleplayer"
|
||||
: ctx.mc().getSingleplayerServer().getWorldData().getLevelName();
|
||||
CommandOutput.send("World: " + name + " | Singleplayer | TPS: 20.00");
|
||||
return true;
|
||||
}
|
||||
ServerData server = ctx.mc().getCurrentServer();
|
||||
String address = server == null || server.ip == null ? "unknown" : server.ip;
|
||||
String label = server == null || server.name == null ? "unknown" : server.name;
|
||||
int ping = NetworkStatsUtil.getPing(ctx.mc());
|
||||
float tps = NetworkStatsUtil.getTps(ctx.mc());
|
||||
CommandOutput.send(String.format(Locale.ROOT, "Server: %s | %s | Ping: %s | TPS: %.2f",
|
||||
label, address, ping < 0 ? "unknown" : ping + " ms", tps));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.features.module.Module;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "toggle",
|
||||
aliases = "t",
|
||||
usage = "@toggle <module> [on|off|toggle]",
|
||||
descriptionKey = "command.toggle.description"
|
||||
)
|
||||
public final class ToggleCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
Module module = CommandUtils.findModule(ctx.arg(0));
|
||||
if (module == null) {
|
||||
CommandOutput.error(ctx.arg(0) == null ? "Usage: " + metadata().usage() : "Module not found: " + ctx.arg(0));
|
||||
return true;
|
||||
}
|
||||
String stateArg = ctx.arg(1);
|
||||
if (!CommandUtils.isState(stateArg)) {
|
||||
CommandOutput.warning("Usage: " + metadata().usage());
|
||||
return true;
|
||||
}
|
||||
boolean next = CommandUtils.parseState(stateArg, module.isEnabled());
|
||||
if (next && !module.isAvailable()) {
|
||||
CommandOutput.error(module.getDisplayName() + " is unavailable: " + module.getAvailabilityReason());
|
||||
return true;
|
||||
}
|
||||
module.setEnabled(next);
|
||||
if (module.isEnabled() == next) {
|
||||
CommandOutput.success(module.getDisplayName() + ": " + (next ? "ON" : "OFF"));
|
||||
} else {
|
||||
CommandOutput.error("Could not change " + module.getDisplayName() + '.');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext ctx, int argIndex, String token) {
|
||||
if (argIndex == 1) return CommandUtils.suggestModules(token);
|
||||
if (argIndex == 2) {
|
||||
String lower = token == null ? "" : token.toLowerCase(Locale.ROOT);
|
||||
return List.of("on", "off", "toggle").stream().filter(value -> value.startsWith(lower)).toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* This file is part of the Combatant Client distribution.
|
||||
* Copyright (c) 2026 pivosos2007.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3.0.
|
||||
*/
|
||||
|
||||
package dev.loki.lovisual.features.command.impl;
|
||||
|
||||
import dev.loki.lovisual.features.command.ClientCommand;
|
||||
import dev.loki.lovisual.features.command.CommandContext;
|
||||
import dev.loki.lovisual.features.command.CommandInfo;
|
||||
import dev.loki.lovisual.features.command.CommandOutput;
|
||||
import dev.loki.lovisual.util.player.NetworkStatsUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@CommandInfo(
|
||||
id = "tps",
|
||||
aliases = "servertps",
|
||||
usage = "@tps",
|
||||
descriptionKey = "command.tps.description"
|
||||
)
|
||||
public final class TpsCommand implements ClientCommand {
|
||||
@Override
|
||||
public boolean execute(CommandContext ctx) {
|
||||
float tps = NetworkStatsUtil.getTps(ctx.mc());
|
||||
CommandOutput.send(String.format(Locale.ROOT, "TPS: %.2f / 20.00", tps));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue