potion display (needs dummy and proper dimensions)
This commit is contained in:
@@ -3,6 +3,7 @@ package org.saturnclient.modules;
|
|||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
|
||||||
import org.saturnclient.modules.mods.*;
|
import org.saturnclient.modules.mods.*;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
@@ -16,6 +17,7 @@ public class ModManager {
|
|||||||
new AutoSprint(),
|
new AutoSprint(),
|
||||||
new ArmorDisplay(),
|
new ArmorDisplay(),
|
||||||
new Fps(),
|
new Fps(),
|
||||||
|
new PotionDisplay()
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
@@ -47,6 +49,8 @@ public class ModManager {
|
|||||||
|
|
||||||
renderScope.drawRoundedRectangle(0, 0, dim.width, dim.height, dim.radius.value, dim.bgColor.value);
|
renderScope.drawRoundedRectangle(0, 0, dim.width, dim.height, dim.radius.value, dim.bgColor.value);
|
||||||
|
|
||||||
|
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||||
|
|
||||||
((HudMod) m).renderHud(renderScope);
|
((HudMod) m).renderHud(renderScope);
|
||||||
|
|
||||||
renderScope.matrices.pop();
|
renderScope.matrices.pop();
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import net.minecraft.client.render.RenderLayer;
|
|||||||
|
|
||||||
public class Crosshair extends Module {
|
public class Crosshair extends Module {
|
||||||
public static Property<Boolean> enabled = new Property<>(false);
|
public static Property<Boolean> enabled = new Property<>(false);
|
||||||
public static Property<Boolean> range_indicator = new Property<>(false);
|
|
||||||
|
|
||||||
public Crosshair() {
|
public Crosshair() {
|
||||||
super(
|
super(
|
||||||
@@ -19,14 +18,12 @@ public class Crosshair extends Module {
|
|||||||
.description("Changes the crosshair if you're aiming at a entity")
|
.description("Changes the crosshair if you're aiming at a entity")
|
||||||
.tags("Visuals", "Utility")
|
.tags("Visuals", "Utility")
|
||||||
.version("v0.1.0"),
|
.version("v0.1.0"),
|
||||||
enabled.named("Enabled"),
|
enabled.named("Enabled"));
|
||||||
range_indicator.named("Range Indicator"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderScope scope) {
|
public void render(RenderScope scope) {
|
||||||
if (enabled.value
|
if (enabled.value
|
||||||
&& range_indicator.value
|
|
||||||
&& SaturnClient.client.targetedEntity != null
|
&& SaturnClient.client.targetedEntity != null
|
||||||
&& SaturnClient.client.targetedEntity.isAlive()) {
|
&& SaturnClient.client.targetedEntity.isAlive()) {
|
||||||
int scaledWidth = 15;
|
int scaledWidth = 15;
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package org.saturnclient.modules.mods;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.HudMod;
|
||||||
|
import org.saturnclient.modules.ModDimensions;
|
||||||
|
import org.saturnclient.modules.Module;
|
||||||
|
import org.saturnclient.modules.ModuleDetails;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.ui2.RenderScope;
|
||||||
|
|
||||||
|
import net.minecraft.client.resource.language.I18n;
|
||||||
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.texture.StatusEffectSpriteManager;
|
||||||
|
import net.minecraft.entity.effect.StatusEffect;
|
||||||
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||||
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
public class PotionDisplay extends Module implements HudMod {
|
||||||
|
public static Property<Boolean> enabled = new Property<>(false);
|
||||||
|
private static ModDimensions dimensions = new ModDimensions(40, 60);
|
||||||
|
|
||||||
|
public PotionDisplay() {
|
||||||
|
super(new ModuleDetails("Potion Display", "potions")
|
||||||
|
.description("Displays potion effects")
|
||||||
|
.version("v0.1.0")
|
||||||
|
.tags("Utility"),
|
||||||
|
|
||||||
|
enabled.named("Enabled"),
|
||||||
|
dimensions.prop());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderHud(RenderScope scope) {
|
||||||
|
int row = 0;
|
||||||
|
|
||||||
|
StatusEffectSpriteManager statusEffectSpriteManager = SaturnClient.client.getStatusEffectSpriteManager();
|
||||||
|
|
||||||
|
for (StatusEffectInstance effect : SaturnClient.client.player.getStatusEffects()) {
|
||||||
|
if (effect.shouldShowIcon()) {
|
||||||
|
RegistryEntry<StatusEffect> registryEntry = effect.getEffectType();
|
||||||
|
Sprite sprite = statusEffectSpriteManager.getSprite(registryEntry);
|
||||||
|
scope.drawSpriteStretched(sprite, 0, 18 * row, 16, 16);
|
||||||
|
scope.drawText(0.6f, getDurationAsString(effect), 19, 18 * row + 2, dimensions.font.value, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This code was from: https://github.com/magicus/statuseffecttimer/blob/master/src/main/java/se/icus/mag/statuseffecttimer/mixin/StatusEffectTimerMixin.java
|
||||||
|
private String getDurationAsString(StatusEffectInstance statusEffectInstance) {
|
||||||
|
if (statusEffectInstance.isInfinite()) {
|
||||||
|
return I18n.translate("effect.duration.infinite");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ticks = MathHelper.floor((float) statusEffectInstance.getDuration());
|
||||||
|
int totalSeconds = ticks / 20;
|
||||||
|
|
||||||
|
if (totalSeconds >= 3600) {
|
||||||
|
return totalSeconds / 3600 + "h";
|
||||||
|
} else if (totalSeconds >= 60) {
|
||||||
|
int minutes = totalSeconds / 60;
|
||||||
|
int seconds = totalSeconds % 60;
|
||||||
|
return String.format("%d:%02d", minutes, seconds);
|
||||||
|
} else {
|
||||||
|
return String.valueOf(totalSeconds) + "s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderDummy(RenderScope scope) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModDimensions getDimensions() {
|
||||||
|
return dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean e) {
|
||||||
|
enabled.value = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import net.minecraft.client.render.RenderLayer;
|
|||||||
import net.minecraft.client.render.VertexConsumer;
|
import net.minecraft.client.render.VertexConsumer;
|
||||||
import net.minecraft.client.render.VertexConsumerProvider;
|
import net.minecraft.client.render.VertexConsumerProvider;
|
||||||
import net.minecraft.client.render.item.ItemRenderState;
|
import net.minecraft.client.render.item.ItemRenderState;
|
||||||
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.client.util.Window;
|
import net.minecraft.client.util.Window;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
@@ -356,4 +357,14 @@ public class RenderScope {
|
|||||||
this.matrices.pop();
|
this.matrices.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawSpriteStretched(Sprite sprite, int x, int y, int width, int height) {
|
||||||
|
this.drawSpriteStretched(sprite, x, y, width, height, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawSpriteStretched(Sprite sprite, int x, int y, int width, int height, int color) {
|
||||||
|
if (width != 0 && height != 0) {
|
||||||
|
this.drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), color);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user