ping, speedometer, and status effects
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package org.saturnclient.modules.interfaces;
|
||||||
|
|
||||||
|
public interface PingInterface {
|
||||||
|
|
||||||
|
/** Returns current player ping in milliseconds */
|
||||||
|
int getPing();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.saturnclient.modules.interfaces;
|
||||||
|
|
||||||
|
public interface SpeedometerInterface {
|
||||||
|
|
||||||
|
/** Returns the current player or vehicle velocity in blocks per tick */
|
||||||
|
Velocity getVelocity();
|
||||||
|
|
||||||
|
/** Returns true if player or vehicle is on ground */
|
||||||
|
boolean isOnGround();
|
||||||
|
|
||||||
|
class Velocity {
|
||||||
|
public final double x, y, z;
|
||||||
|
|
||||||
|
public Velocity(double x, double y, double z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package org.saturnclient.modules.interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.saturnclient.common.minecraft.bindings.SaturnSprite;
|
||||||
|
|
||||||
|
public interface StatusEffectsInterface {
|
||||||
|
|
||||||
|
/** Returns a list of currently active effects */
|
||||||
|
List<Effect> getActiveEffects();
|
||||||
|
|
||||||
|
/** Returns a dummy list of effects for dummy rendering */
|
||||||
|
List<Effect> getDummyEffects();
|
||||||
|
|
||||||
|
/** Represents a single effect for rendering purposes */
|
||||||
|
class Effect {
|
||||||
|
private final SaturnSprite icon;
|
||||||
|
private final int durationSeconds;
|
||||||
|
private final boolean infinite;
|
||||||
|
private final boolean showIcon;
|
||||||
|
private final String infiniteText;
|
||||||
|
|
||||||
|
public Effect(SaturnSprite icon, int durationSeconds, boolean infinite, boolean showIcon, String infiniteText) {
|
||||||
|
this.icon = icon;
|
||||||
|
this.durationSeconds = durationSeconds;
|
||||||
|
this.infinite = infinite;
|
||||||
|
this.showIcon = showIcon;
|
||||||
|
this.infiniteText = infiniteText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaturnSprite getIcon() { return icon; }
|
||||||
|
public int getDurationSeconds() { return durationSeconds; }
|
||||||
|
public boolean isInfinite() { return infinite; }
|
||||||
|
public boolean shouldShowIcon() { return showIcon; }
|
||||||
|
public String getInfiniteText() { return infiniteText; }
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-11
@@ -5,33 +5,32 @@ import org.saturnclient.modules.ModDimensions;
|
|||||||
import org.saturnclient.modules.Module;
|
import org.saturnclient.modules.Module;
|
||||||
import org.saturnclient.modules.ModuleDetails;
|
import org.saturnclient.modules.ModuleDetails;
|
||||||
import org.saturnclient.config.manager.Property;
|
import org.saturnclient.config.manager.Property;
|
||||||
|
import org.saturnclient.modules.interfaces.PingInterface;
|
||||||
import org.saturnclient.ui.RenderScope;
|
import org.saturnclient.ui.RenderScope;
|
||||||
import org.saturnclient.ui.resources.Fonts;
|
import org.saturnclient.ui.resources.Fonts;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
|
||||||
|
|
||||||
public class Ping extends Module implements HudMod {
|
public class Ping extends Module implements HudMod {
|
||||||
|
|
||||||
private static Property<Boolean> enabled = Property.bool(false);
|
private static Property<Boolean> enabled = Property.bool(false);
|
||||||
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight());
|
||||||
|
|
||||||
public Ping() {
|
private final PingInterface pingProvider;
|
||||||
|
|
||||||
|
public Ping(PingInterface pingProvider) {
|
||||||
super(new ModuleDetails("Ping Display", "ping")
|
super(new ModuleDetails("Ping Display", "ping")
|
||||||
.description("Displays ping")
|
.description("Displays ping")
|
||||||
.version("v0.1.0")
|
.version("v0.1.0")
|
||||||
.tags("Utility"),
|
.tags("Utility"),
|
||||||
enabled.named("Enabled"),
|
enabled.named("Enabled"),
|
||||||
dimensions.prop());
|
dimensions.prop());
|
||||||
|
|
||||||
|
this.pingProvider = pingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHud(RenderScope scope) {
|
public void renderHud(RenderScope scope) {
|
||||||
MinecraftClient client = MinecraftClient.getInstance();
|
int ping = pingProvider.getPing();
|
||||||
ClientPlayNetworkHandler handler = client.getNetworkHandler();
|
String text = ping + " ms";
|
||||||
String text = "0 ms";
|
|
||||||
if (handler != null) {
|
|
||||||
text = String.valueOf(handler.getPlayerListEntry(client.player.getUuid()).getLatency()) + " ms";
|
|
||||||
}
|
|
||||||
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||||
}
|
}
|
||||||
@@ -57,4 +56,4 @@ public class Ping extends Module implements HudMod {
|
|||||||
public ModDimensions getDimensions() {
|
public ModDimensions getDimensions() {
|
||||||
return dimensions;
|
return dimensions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+23
-40
@@ -4,25 +4,23 @@ import org.saturnclient.modules.HudMod;
|
|||||||
import org.saturnclient.modules.ModDimensions;
|
import org.saturnclient.modules.ModDimensions;
|
||||||
import org.saturnclient.modules.Module;
|
import org.saturnclient.modules.Module;
|
||||||
import org.saturnclient.modules.ModuleDetails;
|
import org.saturnclient.modules.ModuleDetails;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
|
||||||
import org.saturnclient.config.manager.Property;
|
import org.saturnclient.config.manager.Property;
|
||||||
|
import org.saturnclient.modules.interfaces.SpeedometerInterface;
|
||||||
import org.saturnclient.ui.RenderScope;
|
import org.saturnclient.ui.RenderScope;
|
||||||
import org.saturnclient.ui.resources.Fonts;
|
import org.saturnclient.ui.resources.Fonts;
|
||||||
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
|
|
||||||
public class Speedometer extends Module implements HudMod {
|
public class Speedometer extends Module implements HudMod {
|
||||||
|
|
||||||
private static Property<Boolean> enabled = Property.bool(false);
|
private static Property<Boolean> enabled = Property.bool(false);
|
||||||
private static Property<Integer> axis = Property.select(1, "Absolute", "X axis", "Y axis");
|
private static Property<Integer> axis = Property.select(1, "Absolute", "X axis", "Y axis");
|
||||||
private static Property<Integer> unitText = Property.select(0, "None", "Blocks/s", "blocks/s", "b/s");
|
private static Property<Integer> unitText = Property.select(0, "None", "Blocks/s", "blocks/s", "b/s");
|
||||||
private static Property<Boolean> speedText = Property.bool(true);
|
private static Property<Boolean> speedText = Property.bool(true);
|
||||||
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
private static ModDimensions dimensions = new ModDimensions(40, 18);
|
||||||
double speed = 0.;
|
|
||||||
Vec3d velocity;
|
|
||||||
double y = 0.;
|
|
||||||
|
|
||||||
public Speedometer() {
|
private final SpeedometerInterface provider;
|
||||||
|
private double speed = 0.;
|
||||||
|
|
||||||
|
public Speedometer(SpeedometerInterface provider) {
|
||||||
super(new ModuleDetails("Speedometer", "speed")
|
super(new ModuleDetails("Speedometer", "speed")
|
||||||
.description("Displays your current speed")
|
.description("Displays your current speed")
|
||||||
.version("v0.1.0")
|
.version("v0.1.0")
|
||||||
@@ -32,6 +30,8 @@ public class Speedometer extends Module implements HudMod {
|
|||||||
unitText.named("Unit text"),
|
unitText.named("Unit text"),
|
||||||
speedText.named("Show speed text"),
|
speedText.named("Show speed text"),
|
||||||
dimensions.prop());
|
dimensions.prop());
|
||||||
|
|
||||||
|
this.provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,57 +41,40 @@ public class Speedometer extends Module implements HudMod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHud(RenderScope scope) {
|
public void renderHud(RenderScope scope) {
|
||||||
Entity vehicle = SaturnClient.client.player.getVehicle();
|
SpeedometerInterface.Velocity velocity = provider.getVelocity();
|
||||||
Entity player = SaturnClient.client.player;
|
boolean onGround = provider.isOnGround();
|
||||||
|
|
||||||
if (vehicle == null) {
|
double y = onGround ? 0.0 : velocity.y;
|
||||||
velocity = player.getVelocity();
|
|
||||||
y = player.isOnGround() ? 0. : velocity.y;
|
|
||||||
} else {
|
|
||||||
velocity = vehicle.getVelocity();
|
|
||||||
y = vehicle.isOnGround() ? 0. : velocity.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (axis.value) {
|
switch (axis.value) {
|
||||||
case 0: // Absolute
|
case 0: // Absolute
|
||||||
speed = (Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(y, 2) + Math.pow(velocity.z, 2)));
|
speed = Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(y, 2) + Math.pow(velocity.z, 2));
|
||||||
break;
|
break;
|
||||||
|
case 1: // X axis
|
||||||
case 1: // x axis
|
speed = Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(velocity.z, 2));
|
||||||
speed = (Math.sqrt(Math.pow(velocity.x, 2) + Math.pow(velocity.z, 2)));
|
|
||||||
break;
|
break;
|
||||||
|
case 2: // Y axis
|
||||||
case 2: // y axis
|
speed = Math.abs(y);
|
||||||
speed = (Math.abs(y));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSpeed(speed * 20, scope); // blocks/tick to blocks/s
|
renderSpeed(speed * 20, scope); // blocks/tick to blocks/s
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderSpeed(double speed, RenderScope scope) {
|
public void renderSpeed(double speed, RenderScope scope) {
|
||||||
String f = String.format("%.2f ", speed);
|
String text = String.format("%.2f ", speed);
|
||||||
|
|
||||||
switch (unitText.value) {
|
switch (unitText.value) {
|
||||||
case 1:
|
case 1 -> text += "Blocks/s";
|
||||||
f += "Blocks/s";
|
case 2 -> text += "blocks/s";
|
||||||
break;
|
case 3 -> text += "b/s";
|
||||||
|
|
||||||
case 2:
|
|
||||||
f += "blocks/s";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
f += "b/s";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String text = f;
|
|
||||||
|
|
||||||
if (speedText.value) {
|
if (speedText.value) {
|
||||||
text = "Speed: " + text;
|
text = "Speed: " + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.drawText(text,
|
scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value);
|
||||||
0, 0, dimensions.font.value, dimensions.fgColor.value);
|
|
||||||
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
|
||||||
dimensions.height = 18 * text.split("\n").length;
|
dimensions.height = 18 * text.split("\n").length;
|
||||||
}
|
}
|
||||||
@@ -110,4 +93,4 @@ public class Speedometer extends Module implements HudMod {
|
|||||||
public void onEnabled(boolean e) {
|
public void onEnabled(boolean e) {
|
||||||
enabled.value = e;
|
enabled.value = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package org.saturnclient.modules.mods;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.HudMod;
|
||||||
|
import org.saturnclient.modules.ModDimensions;
|
||||||
|
import org.saturnclient.modules.Module;
|
||||||
|
import org.saturnclient.modules.ModuleDetails;
|
||||||
|
import org.saturnclient.modules.interfaces.StatusEffectsInterface;
|
||||||
|
import org.saturnclient.config.manager.Property;
|
||||||
|
import org.saturnclient.ui.RenderScope;
|
||||||
|
|
||||||
|
public class StatusEffects extends Module implements HudMod {
|
||||||
|
|
||||||
|
public static Property<Boolean> enabled = Property.bool(false);
|
||||||
|
private static ModDimensions dimensions = new ModDimensions(60, 0);
|
||||||
|
|
||||||
|
private final StatusEffectsInterface provider;
|
||||||
|
|
||||||
|
public StatusEffects(StatusEffectsInterface provider) {
|
||||||
|
super(new ModuleDetails("Status effects", "effect")
|
||||||
|
.description("Displays status effects")
|
||||||
|
.version("v0.1.0")
|
||||||
|
.tags("Utility"),
|
||||||
|
enabled.named("Enabled"),
|
||||||
|
dimensions.prop());
|
||||||
|
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderEffects(RenderScope scope, List<StatusEffectsInterface.Effect> effects) {
|
||||||
|
int row = 0;
|
||||||
|
|
||||||
|
for (StatusEffectsInterface.Effect effect : effects) {
|
||||||
|
if (!effect.shouldShowIcon()) continue;
|
||||||
|
|
||||||
|
scope.drawSpriteStretched(effect.getIcon(), 0, 18 * row, 16, 16);
|
||||||
|
scope.drawText(0.5f, getDurationAsString(effect), 18, 18 * row + 3, dimensions.font.value, -1);
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dimensions.height = 18 * row;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderHud(RenderScope scope) {
|
||||||
|
renderEffects(scope, provider.getActiveEffects());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderDummy(RenderScope scope) {
|
||||||
|
renderEffects(scope, provider.getDummyEffects());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDurationAsString(StatusEffectsInterface.Effect effect) {
|
||||||
|
if (effect.isInfinite()) {
|
||||||
|
return effect.getInfiniteText();
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalSeconds = effect.getDurationSeconds();
|
||||||
|
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 totalSeconds + "s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModDimensions getDimensions() {
|
||||||
|
return dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnabled(boolean e) {
|
||||||
|
enabled.value = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.saturnclient.impl.modules;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.interfaces.PingInterface;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
|
||||||
|
public class PingFabric implements PingInterface {
|
||||||
|
|
||||||
|
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPing() {
|
||||||
|
if (mc.player == null || mc.getNetworkHandler() == null) return 0;
|
||||||
|
ClientPlayNetworkHandler handler = mc.getNetworkHandler();
|
||||||
|
if (handler.getPlayerListEntry(mc.player.getUuid()) == null) return 0;
|
||||||
|
return handler.getPlayerListEntry(mc.player.getUuid()).getLatency();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.saturnclient.impl.modules;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.interfaces.SpeedometerInterface;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
|
public class SpeedometerFabric implements SpeedometerInterface {
|
||||||
|
|
||||||
|
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Velocity getVelocity() {
|
||||||
|
Entity entity = mc.player.getVehicle() != null ? mc.player.getVehicle() : mc.player;
|
||||||
|
return new Velocity(entity.getVelocity().x, entity.getVelocity().y, entity.getVelocity().z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOnGround() {
|
||||||
|
Entity entity = mc.player.getVehicle() != null ? mc.player.getVehicle() : mc.player;
|
||||||
|
return entity.isOnGround();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.saturnclient.impl.modules;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.interfaces.StatusEffectsInterface;
|
||||||
|
import org.saturnclient.common.minecraft.bindings.SaturnSprite;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.texture.StatusEffectSpriteManager;
|
||||||
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||||
|
|
||||||
|
public class StatusEffectsFabric implements StatusEffectsInterface {
|
||||||
|
|
||||||
|
private final MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Effect> getActiveEffects() {
|
||||||
|
StatusEffectSpriteManager manager = mc.getStatusEffectSpriteManager();
|
||||||
|
return mc.player.getStatusEffects().stream()
|
||||||
|
.filter(StatusEffectInstance::shouldShowIcon)
|
||||||
|
.map(se -> new Effect(
|
||||||
|
new SaturnSprite(manager.getSprite(se.getEffectType())),
|
||||||
|
se.getDuration() / 20,
|
||||||
|
se.isInfinite(),
|
||||||
|
se.shouldShowIcon(),
|
||||||
|
"Infinite"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Effect> getDummyEffects() {
|
||||||
|
return Arrays.asList(
|
||||||
|
new Effect(new SaturnSprite(null), 600, false, true, "Infinite"),
|
||||||
|
new Effect(new SaturnSprite(null), 600, false, true, "Infinite"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package org.saturnclient.modules.mods;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
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.common.minecraft.bindings.SaturnSprite;
|
|
||||||
import org.saturnclient.config.manager.Property;
|
|
||||||
import org.saturnclient.ui.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.Registries;
|
|
||||||
import net.minecraft.registry.entry.RegistryEntry;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
public class StatusEffects extends Module implements HudMod {
|
|
||||||
public static Property<Boolean> enabled = Property.bool(false);
|
|
||||||
private static ModDimensions dimensions = new ModDimensions(60, 0);
|
|
||||||
|
|
||||||
private final StatusEffectInstance[] dummyEffects = {
|
|
||||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("speed")).get(), 12000, 2),
|
|
||||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("strength")).get(), 12000,
|
|
||||||
2),
|
|
||||||
new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("fire_resistance")).get(),
|
|
||||||
12000, 2),
|
|
||||||
};
|
|
||||||
|
|
||||||
public StatusEffects() {
|
|
||||||
super(new ModuleDetails("Status effects", "effect")
|
|
||||||
.description("Displays status effects")
|
|
||||||
.version("v0.1.0")
|
|
||||||
.tags("Utility"),
|
|
||||||
|
|
||||||
enabled.named("Enabled"),
|
|
||||||
dimensions.prop());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderEffects(RenderScope scope, Iterable<StatusEffectInstance> effects) {
|
|
||||||
int row = 0;
|
|
||||||
|
|
||||||
StatusEffectSpriteManager statusEffectSpriteManager = SaturnClient.client.getStatusEffectSpriteManager();
|
|
||||||
|
|
||||||
for (StatusEffectInstance effect : effects) {
|
|
||||||
if (effect.shouldShowIcon()) {
|
|
||||||
RegistryEntry<StatusEffect> registryEntry = effect.getEffectType();
|
|
||||||
Sprite sprite = statusEffectSpriteManager.getSprite(registryEntry);
|
|
||||||
scope.drawSpriteStretched(new SaturnSprite(sprite), 0, 18 * row, 16, 16);
|
|
||||||
scope.drawText(0.5f, getDurationAsString(effect), 18, 18 * row + 3, dimensions.font.value, -1);
|
|
||||||
row++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dimensions.height = 18 * row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderHud(RenderScope scope) {
|
|
||||||
renderEffects(scope, SaturnClient.client.player.getStatusEffects());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderDummy(RenderScope scope) {
|
|
||||||
renderEffects(scope, Arrays.asList(dummyEffects));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 ModDimensions getDimensions() {
|
|
||||||
return dimensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnabled(boolean e) {
|
|
||||||
enabled.value = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user