Better module system
This commit is contained in:
@@ -7,8 +7,9 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import org.saturnclient.modules.mods.*;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||
import org.saturnclient.ui2.RenderScope;
|
||||
|
||||
public class ModManager {
|
||||
public static Module[] MODS = {
|
||||
@@ -29,7 +30,8 @@ public class ModManager {
|
||||
|
||||
if (textRenderer != null &&
|
||||
!(SaturnClient.client.currentScreen instanceof HudEditor)) {
|
||||
SaturnClientConfig.textRenderer = textRenderer;
|
||||
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
||||
((DrawContextAccessor) context).getVertexConsumers());
|
||||
|
||||
for (Module m : MODS) {
|
||||
if (m instanceof HudMod && m.isEnabled()) {
|
||||
@@ -45,6 +47,8 @@ public class ModManager {
|
||||
((HudMod) m).render(context);
|
||||
|
||||
matrices.pop();
|
||||
} else {
|
||||
m.render(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.saturnclient.saturnclient.config.ConfigManager;
|
||||
import org.saturnclient.saturnclient.config.NamedProperty;
|
||||
import org.saturnclient.ui.Textures;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public abstract class Module {
|
||||
@@ -29,6 +30,8 @@ public abstract class Module {
|
||||
configManager = config;
|
||||
}
|
||||
|
||||
public void render(DrawContext scope) {}
|
||||
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
public abstract void setEnabled(boolean e);
|
||||
@@ -36,7 +39,7 @@ public abstract class Module {
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public Identifier getIconTexture() {
|
||||
return Textures.getModIcon(namespace);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package org.saturnclient.modules.mods;
|
||||
|
||||
import org.saturnclient.modules.Module;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.config.NamedProperty;
|
||||
import org.saturnclient.saturnclient.config.Property;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class Crosshair extends Module {
|
||||
Identifier textureLocation = Identifier.of("saturnclient", "textures/gui/hud/crosshair_range.png");
|
||||
|
||||
public static NamedProperty<Boolean> enabled = new Property<>(false).named("Enabled");
|
||||
public static NamedProperty<Boolean> range_indicator = new Property<>(false).named("Range Indicator");
|
||||
|
||||
@@ -12,6 +21,23 @@ public class Crosshair extends Module {
|
||||
super("Crosshair", "crosshair", enabled, range_indicator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context) {
|
||||
if (enabled.prop.value
|
||||
&& range_indicator.prop.value
|
||||
&& SaturnClient.client.targetedEntity != null
|
||||
&& SaturnClient.client.targetedEntity.isAlive()) {
|
||||
RenderSystem.setShaderTexture(0, textureLocation);
|
||||
int scaledWidth = 15;
|
||||
int scaledHeight = 15;
|
||||
|
||||
context.drawTexture(RenderLayer::getCrosshair, textureLocation,
|
||||
(context.getScaledWindowWidth() - scaledWidth) / 2,
|
||||
(context.getScaledWindowHeight() - scaledHeight) / 2, 0.0F, 0.0F, scaledWidth, scaledHeight,
|
||||
scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled.prop.value;
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.saturnclient.ui.SaturnUi;
|
||||
import org.saturnclient.ui.Textures;
|
||||
import org.saturnclient.ui.animations.FadeIn;
|
||||
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.ColorHelper;
|
||||
|
||||
@@ -31,7 +30,6 @@ public class SaturnClientConfig {
|
||||
new Property<>(true);
|
||||
|
||||
public static int WHITE = ColorHelper.getArgb(255, 255, 255, 255);
|
||||
public static TextRenderer textRenderer = null;
|
||||
|
||||
public static int getWhite(float alpha) {
|
||||
return ((int) (alpha * 255) << 24) | (normal.value & 0x00FFFFFF);
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Code from: https://github.com/Selyss
|
||||
* Repo: https://github.com/Selyss/CrosshairIndicator/tree/main
|
||||
*/
|
||||
|
||||
package org.saturnclient.saturnclient.mixin;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.RenderTickCounter;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import net.minecraft.client.gui.hud.InGameHud;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
@Mixin(InGameHud.class)
|
||||
public class Crosshair {
|
||||
@Unique
|
||||
Identifier textureLocation = Identifier.of("saturnclient", "textures/gui/hud/crosshair_range.png");
|
||||
|
||||
@Inject(method = "renderCrosshair", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIII)V", ordinal = 0))
|
||||
private void drawCrosshair(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
|
||||
if (org.saturnclient.modules.mods.Crosshair.enabled.prop.value
|
||||
&& org.saturnclient.modules.mods.Crosshair.range_indicator.prop.value
|
||||
&& SaturnClient.client.targetedEntity != null
|
||||
&& SaturnClient.client.targetedEntity.isAlive()) {
|
||||
RenderSystem.setShaderTexture(0, textureLocation);
|
||||
int scaledWidth = 15;
|
||||
int scaledHeight = 15;
|
||||
|
||||
context.drawTexture(RenderLayer::getCrosshair, textureLocation,
|
||||
(context.getScaledWindowWidth() - scaledWidth) / 2,
|
||||
(context.getScaledWindowHeight() - scaledHeight) / 2, 0.0F, 0.0F, scaledWidth, scaledHeight,
|
||||
scaledWidth, scaledHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,10 +64,10 @@ public class SaturnModComp extends SaturnWidget {
|
||||
color);
|
||||
|
||||
context.drawText(
|
||||
SaturnClientConfig.textRenderer,
|
||||
SaturnClient.client.textRenderer,
|
||||
SaturnUi.text(mod.getName()),
|
||||
20,
|
||||
(21 - SaturnClientConfig.textRenderer.fontHeight) / 2,
|
||||
(21 - SaturnClient.client.textRenderer.fontHeight) / 2,
|
||||
color,
|
||||
false);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.saturnclient.ui.widgets;
|
||||
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||
import org.saturnclient.ui.SaturnUi;
|
||||
import org.saturnclient.ui.SaturnWidget;
|
||||
@@ -11,8 +13,8 @@ public class SaturnText extends SaturnWidget {
|
||||
|
||||
public SaturnText(String text) {
|
||||
this.text = text;
|
||||
this.width = SaturnClientConfig.textRenderer.getWidth(SaturnUi.text(text));
|
||||
this.height = SaturnClientConfig.textRenderer.fontHeight;
|
||||
this.width = SaturnClient.client.textRenderer.getWidth(SaturnUi.text(text));
|
||||
this.height = SaturnClient.client.textRenderer.fontHeight;
|
||||
}
|
||||
|
||||
public SaturnText(String text, int color) {
|
||||
@@ -26,7 +28,7 @@ public class SaturnText extends SaturnWidget {
|
||||
int mouseX,
|
||||
int mouseY) {
|
||||
context.drawText(
|
||||
SaturnClientConfig.textRenderer,
|
||||
SaturnClient.client.textRenderer,
|
||||
SaturnUi.text(text),
|
||||
0,
|
||||
0,
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"PlayerEntityRendererMixin",
|
||||
"WhoAmI",
|
||||
"SaturnReload",
|
||||
"Crosshair",
|
||||
"DrawContextAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
|
||||
Reference in New Issue
Block a user