Skip to content

Commit

Permalink
Add End HUD Widget (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
viciscat authored Feb 15, 2024
1 parent 41d02da commit 9c10606
Show file tree
Hide file tree
Showing 10 changed files with 537 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.hysky.skyblocker.skyblock.dwarven.CrystalsHud;
import de.hysky.skyblocker.skyblock.dwarven.CrystalsLocationsManager;
import de.hysky.skyblocker.skyblock.dwarven.DwarvenHud;
import de.hysky.skyblocker.skyblock.end.TheEnd;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
import de.hysky.skyblocker.skyblock.item.*;
import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview;
Expand Down Expand Up @@ -121,6 +122,7 @@ public void onInitializeClient() {
FireFreezeStaffTimer.init();
GuardianHealth.init();
TheRift.init();
TheEnd.init();
SearchOverManager.init();
TitleContainer.init();
ScreenMaster.init();
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package de.hysky.skyblocker.config;

import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.utils.render.RenderHelper;
import it.unimi.dsi.fastutil.ints.IntIntImmutablePair;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

import java.awt.*;

public abstract class HudConfigScreen extends Screen {
private final Widget widget;
private final Screen parent;

private int hudX = 0;
private int hudY = 0;
public HudConfigScreen(Text title, Widget widget, Screen parent) {
super(title);
this.widget = widget;
this.parent = parent;

int[] posFromConfig = getPosFromConfig(SkyblockerConfigManager.get());
hudX = posFromConfig[0];
hudY = posFromConfig[1];
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
renderBackground(context, mouseX, mouseY, delta);
renderWidget(context, hudX, hudY);
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB());
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
IntIntPair dims = getDimensions();
if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + dims.leftInt(), hudY + dims.rightInt()) && button == 0) {
hudX = (int) Math.max(Math.min(mouseX - (double) dims.leftInt() / 2, this.width - dims.leftInt()), 0);
hudY = (int) Math.max(Math.min(mouseY - (double) dims.rightInt() / 2, this.height - dims.rightInt()), 0);
}
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button == 1) {
IntIntPair dims = getDimensions();
hudX = this.width / 2 - dims.leftInt();
hudY = this.height / 2 - dims.rightInt();
}
return super.mouseClicked(mouseX, mouseY, button);
}

abstract protected int[] getPosFromConfig(SkyblockerConfig config);

protected IntIntPair getDimensions() {
return new IntIntImmutablePair(widget.getHeight(), widget.getWidth());
}

@Override
public void close() {
SkyblockerConfig skyblockerConfig = SkyblockerConfigManager.get();
savePos(skyblockerConfig, hudX, hudY);
SkyblockerConfigManager.save();

client.setScreen(parent);
}

/**
* This method should save the passed position to the config
* <p>
* NOTE: The parent class will call {@link SkyblockerConfigManager#save()} right after this method
* @param configManager the config so you don't have to get it
* @param x x
* @param y y
*/
abstract protected void savePos(SkyblockerConfig configManager, int x, int y);

abstract protected void renderWidget(DrawContext context, int x, int y);
}
21 changes: 21 additions & 0 deletions src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ public static class Locations {
@SerialEntry
public Rift rift = new Rift();

@SerialEntry
public TheEnd end = new TheEnd();

@SerialEntry
public SpidersDen spidersDen = new SpidersDen();

Expand Down Expand Up @@ -1042,6 +1045,24 @@ public static class Rift {
public int mcGrubberStacks = 0;
}

public static class TheEnd {

@SerialEntry
public boolean hudEnabled = true;

@SerialEntry
public boolean enableBackground = true;

@SerialEntry
public boolean waypoint = true;

@SerialEntry
public int x = 10;

@SerialEntry
public int y = 10;
}

public static class SpidersDen {
@SerialEntry
public Relics relics = new Relics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.OptionGroup;
import de.hysky.skyblocker.skyblock.end.EndHudConfigScreen;
import de.hysky.skyblocker.skyblock.end.TheEnd;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;

public class LocationsCategory {
Expand Down Expand Up @@ -79,6 +79,49 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.build())
.build())

// The end
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end"))
.collapsed(false)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.hudEnabled"))
.binding(defaults.locations.end.hudEnabled,
() -> config.locations.end.hudEnabled,
newValue -> config.locations.end.hudEnabled = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.dwarvenHud.enableBackground")) // Reusing that string cuz sure
.binding(defaults.locations.end.enableBackground,
() -> config.locations.end.enableBackground,
newValue -> config.locations.end.enableBackground = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.waypoint"))
.binding(defaults.locations.end.waypoint,
() -> config.locations.end.waypoint,
newValue -> config.locations.end.waypoint = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(ButtonOption.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.screen"))
.text(Text.translatable("text.skyblocker.open")) // Reusing again lol
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new EndHudConfigScreen(screen)))
.build())
.option(ButtonOption.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.end.resetName"))
.text(Text.translatable("text.autoconfig.skyblocker.option.locations.end.resetText"))
.action((screen, opt) -> {
TheEnd.zealotsKilled = 0;
TheEnd.zealotsSinceLastEye = 0;
TheEnd.eyes = 0;
})
.build())
.build()

)

//Spider's Den
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.spidersDen"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.skyblock.FishingHelper;
import de.hysky.skyblocker.skyblock.end.TheEnd;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.end.BeaconHighlighter;
Expand Down Expand Up @@ -52,12 +53,6 @@ public abstract class ClientPlayNetworkHandlerMixin {
return !Utils.isOnHypixel();
}

@ModifyExpressionValue(method = "onEntityStatus", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityStatusS2CPacket;getEntity(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"))
private Entity skyblocker$onEntityDeath(Entity entity, @Local(argsOnly = true) EntityStatusS2CPacket packet) {
if (packet.getStatus() == EntityStatuses.PLAY_DEATH_SOUND_OR_ADD_PROJECTILE_HIT_PARTICLES) DungeonScore.handleEntityDeath(entity);
return entity;
}

@WrapWithCondition(method = "onPlayerList", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false))
private boolean skyblocker$cancelPlayerListWarning(Logger instance, String format, Object arg1, Object arg2) {
return !Utils.isOnHypixel();
Expand Down Expand Up @@ -87,4 +82,13 @@ public abstract class ClientPlayNetworkHandlerMixin {
private void skyblocker$onParticle(ParticleS2CPacket packet, CallbackInfo ci) {
MythologicalRitual.onParticle(packet);
}

@ModifyExpressionValue(method = "onEntityStatus", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/EntityStatusS2CPacket;getEntity(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"))
private Entity skyblocker$onEntityDeath(Entity entity, @Local(argsOnly = true) EntityStatusS2CPacket packet) {
if (packet.getStatus() == EntityStatuses.PLAY_DEATH_SOUND_OR_ADD_PROJECTILE_HIT_PARTICLES) {
DungeonScore.handleEntityDeath(entity);
TheEnd.onEntityDeath(entity);
}
return entity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.hysky.skyblocker.skyblock.end;

import de.hysky.skyblocker.config.HudConfigScreen;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;

public class EndHudConfigScreen extends HudConfigScreen {
public EndHudConfigScreen(Screen parent) {
super(Text.literal("End HUD Config"), EndHudWidget.INSTANCE, parent);
}

@Override
protected int[] getPosFromConfig(SkyblockerConfig config) {
return new int[]{
config.locations.end.x,
config.locations.end.y,
};
}

@Override
protected void savePos(SkyblockerConfig configManager, int x, int y) {
configManager.locations.end.x = x;
configManager.locations.end.y = y;
}

@Override
protected void renderWidget(DrawContext context, int x, int y) {
EndHudWidget.INSTANCE.setX(x);
EndHudWidget.INSTANCE.setY(y);
EndHudWidget.INSTANCE.render(context, SkyblockerConfigManager.get().locations.end.enableBackground);
}
}
65 changes: 65 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/end/EndHudWidget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.hysky.skyblocker.skyblock.end;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

import java.text.NumberFormat;

public class EndHudWidget extends Widget {
private static final MutableText TITLE = Text.literal("The End").formatted(Formatting.LIGHT_PURPLE, Formatting.BOLD);

public static final EndHudWidget INSTANCE = new EndHudWidget(TITLE, Formatting.DARK_PURPLE.getColorValue());

public EndHudWidget(MutableText title, Integer colorValue) {
super(title, colorValue);
this.setX(5);
this.setY(5);
this.update();
}

private static final ItemStack ENDERMAN_HEAD = new ItemStack(Items.PLAYER_HEAD);
private static final ItemStack POPPY = new ItemStack(Items.POPPY);

static {
ENDERMAN_HEAD.getOrCreateNbt().putString("SkullOwner", "MHF_Enderman");
POPPY.addEnchantment(Enchantments.INFINITY, 1);

INSTANCE.setX(SkyblockerConfigManager.get().locations.end.x);
INSTANCE.setY(SkyblockerConfigManager.get().locations.end.y);
}


@Override
public void updateContent() {
// Zealots
addComponent(new IcoTextComponent(ENDERMAN_HEAD, Text.literal("Zealots").formatted(Formatting.BOLD)));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsSinceLastEye", TheEnd.zealotsSinceLastEye)));
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.zealotsTotalKills", TheEnd.zealotsKilled)));
NumberFormat instance = NumberFormat.getInstance();
instance.setMinimumFractionDigits(0);
instance.setMaximumFractionDigits(2);
String avg = TheEnd.eyes == 0 ? "???" : instance.format((float)TheEnd.zealotsKilled / TheEnd.eyes);
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.avgKillsPerEye", avg)));

// Endstone protector
addComponent(new IcoTextComponent(POPPY, Text.literal("Endstone Protector").formatted(Formatting.BOLD)));
if (TheEnd.stage == 5) {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.stage", "IMMINENT")));
} else {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.stage", String.valueOf(TheEnd.stage))));
}
if (TheEnd.currentProtectorLocation == null) {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.location", "?")));
} else {
addComponent(new PlainTextComponent(Text.translatable("skyblocker.end.hud.location", TheEnd.currentProtectorLocation.name())));
}
}
}
Loading

0 comments on commit 9c10606

Please sign in to comment.