Skip to content

Commit

Permalink
Merge pull request #500 from Emirlol/clientside-dungeon-score
Browse files Browse the repository at this point in the history
Add dungeon score calculation on client-side
  • Loading branch information
kevinthegreat1 authored Jan 21, 2024
2 parents 08444dc + cbf7f80 commit a092f33
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 99 deletions.
29 changes: 29 additions & 0 deletions src/main/java/de/hysky/skyblocker/config/SkyblockerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ public static class Dungeons {
@SerialEntry
public DungeonChestProfit dungeonChestProfit = new DungeonChestProfit();

@SerialEntry
public MimicMessage mimicMessage = new MimicMessage();

@SerialEntry
public boolean croesusHelper = true;

Expand Down Expand Up @@ -757,6 +760,18 @@ public static class DungeonScore {

@SerialEntry
public String dungeonScore300Message = "300 Score Reached!";

@SerialEntry
public boolean enableScoreHUD = true;

@SerialEntry
public int scoreX = 29;

@SerialEntry
public int scoreY = 134;

@SerialEntry
public float scoreScaling = 1f;
}

public static class DungeonChestProfit {
Expand Down Expand Up @@ -785,6 +800,14 @@ public static class DungeonChestProfit {
public Formatting incompleteColor = Formatting.BLUE;
}

public static class MimicMessage {
@SerialEntry
public boolean sendMimicMessage = true;

@SerialEntry
public String mimicMessage = "Mimic dead!";
}

public static class LividColor {
@SerialEntry
public boolean enableLividColorGlow = true;
Expand Down Expand Up @@ -969,6 +992,12 @@ public static class Messages {
@SerialEntry
public ChatFilterResult hideToggleSkyMall = ChatFilterResult.PASS;

@SerialEntry
public ChatFilterResult hideMimicKill = ChatFilterResult.PASS;

@SerialEntry
public ChatFilterResult hideDeath = ChatFilterResult.PASS;

@SerialEntry
public boolean hideMana = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.skyblock.dungeon.DungeonMapConfigScreen;
import de.hysky.skyblocker.utils.waypoint.Waypoint.Type;
import dev.isxander.yacl3.api.ButtonOption;
import dev.isxander.yacl3.api.ConfigCategory;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.OptionFlag;
import dev.isxander.yacl3.api.OptionGroup;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder;
import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder;
import dev.isxander.yacl3.api.controller.StringControllerBuilder;
import de.hysky.skyblocker.skyblock.dungeon.DungeonMapConfigScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
Expand Down Expand Up @@ -235,6 +230,25 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.locations.dungeons.dungeonScore.dungeonScore300Message = newValue)
.controller(StringControllerBuilder::create)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.dungeonScore.enableScoreHUD"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.dungeonScore.enableScoreHUD.@Tooltip"), Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.dungeonScore.enableScoreHUD.deathMessagesNote")))
.binding(defaults.locations.dungeons.dungeonScore.enableScoreHUD,
() -> config.locations.dungeons.dungeonScore.enableScoreHUD,
newValue -> config.locations.dungeons.dungeonScore.enableScoreHUD = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Float>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.dungeonScore.scoreScaling"))
.binding(defaults.locations.dungeons.dungeonScore.scoreScaling,
() -> config.locations.dungeons.dungeonScore.scoreScaling,
newValue -> {
config.locations.dungeons.dungeonScore.scoreX = config.locations.dungeons.dungeonScore.scoreX + (int) ((config.locations.dungeons.dungeonScore.scoreScaling - newValue) * 38.0);
config.locations.dungeons.dungeonScore.scoreY = config.locations.dungeons.dungeonScore.scoreY + (int) ((config.locations.dungeons.dungeonScore.scoreScaling - newValue) * MinecraftClient.getInstance().textRenderer.fontHeight / 2.0);
config.locations.dungeons.dungeonScore.scoreScaling = newValue;
})
.controller(FloatFieldControllerBuilder::create)
.build())
.build())

//Dungeon Chest Profit
Expand Down Expand Up @@ -419,7 +433,29 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.controller(ConfigUtils::createBooleanController)
.build())

// Livid Color
//Mimic Message
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.mimicMessage"))
.collapsed(true)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.mimicMessage.sendMimicMessage"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.mimicMessage.sendMimicMessage.@Tooltip")))
.binding(defaults.locations.dungeons.mimicMessage.sendMimicMessage,
() -> config.locations.dungeons.mimicMessage.sendMimicMessage,
newValue -> config.locations.dungeons.mimicMessage.sendMimicMessage = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<String>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.mimicMessage.mimicMessage"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.mimicMessage.mimicMessage.@Tooltip")))
.binding(defaults.locations.dungeons.mimicMessage.mimicMessage,
() -> config.locations.dungeons.mimicMessage.mimicMessage,
newValue -> config.locations.dungeons.mimicMessage.mimicMessage = newValue)
.controller(StringControllerBuilder::create)
.build())
.build())

//Livid Color
.group(OptionGroup.createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.locations.dungeons.lividColor"))
.collapsed(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.messages.hideMana = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<ChatFilterResult>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.messages.hideMimicKill"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.messages.hideMimicKill.@Tooltip")))
.binding(defaults.messages.hideMimicKill,
() -> config.messages.hideMimicKill,
newValue -> config.messages.hideMimicKill = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(Option.<ChatFilterResult>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.messages.hideDeath"))
.description(OptionDescription.of(Text.translatable("text.autoconfig.skyblocker.option.messages.hideDeath.@Tooltip")))
.binding(defaults.messages.hideDeath,
() -> config.messages.hideDeath,
newValue -> config.messages.hideDeath = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package de.hysky.skyblocker.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.skyblock.FishingHelper;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityStatuses;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket;
import net.minecraft.util.Identifier;

import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -49,12 +53,12 @@ public abstract class ClientPlayNetworkHandlerMixin {
private boolean skyblocker$cancelTeamWarning(Logger instance, String format, Object... arg) {
return !Utils.isOnHypixel();
}

@WrapWithCondition(method = { "onScoreboardScoreUpdate", "onScoreboardScoreReset" }, at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false))
private boolean skyblocker$cancelUnknownScoreboardObjectiveWarnings(Logger instance, String message, Object objectiveName) {
return !Utils.isOnHypixel();
}

@WrapWithCondition(method = "warnOnUnknownPayload", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false))
private boolean skyblocker$dropBadlionPacketWarnings(Logger instance, String message, Object identifier) {
return !(Utils.isOnHypixel() && ((Identifier) identifier).getNamespace().equals("badlion"));
Expand All @@ -64,4 +68,10 @@ 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);
return entity;
}
}
10 changes: 7 additions & 3 deletions src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.FancyStatusBars;
import de.hysky.skyblocker.skyblock.dungeon.DungeonMap;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScore;
import de.hysky.skyblocker.skyblock.dungeon.DungeonScoreHUD;
import de.hysky.skyblocker.skyblock.item.HotbarSlotLock;
import de.hysky.skyblocker.skyblock.item.ItemCooldowns;
import de.hysky.skyblocker.skyblock.dungeon.DungeonMap;
import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -64,8 +66,10 @@ public abstract class InGameHudMixin {
if (statusBars.render(context, scaledWidth, scaledHeight))
ci.cancel();

if (Utils.isInDungeons() && SkyblockerConfigManager.get().locations.dungeons.enableMap)
DungeonMap.render(context.getMatrices());
if (Utils.isInDungeons() && DungeonScore.isDungeonStarted()) {
if (SkyblockerConfigManager.get().locations.dungeons.enableMap) DungeonMap.render(context.getMatrices());
if (SkyblockerConfigManager.get().locations.dungeons.dungeonScore.enableScoreHUD) DungeonScoreHUD.render(context);
}
}

@Inject(method = "renderMountHealth", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.MapRenderer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.FilledMapItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.map.MapState;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.StringUtils;

public class DungeonMap {
private static final Identifier MAP_BACKGROUND = new Identifier("textures/map/map_background.png");

public static void render(MatrixStack matrices) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null || client.world == null) return;
Expand Down Expand Up @@ -46,13 +42,7 @@ public static void render(MatrixStack matrices) {
}
}

public static void renderHUDMap(DrawContext context, int x, int y) {
float scaling = SkyblockerConfigManager.get().locations.dungeons.mapScaling;
int size = (int) (128 * scaling);
context.drawTexture(MAP_BACKGROUND, x, y, 0, 0, size, size, size, size);
}

public static void init() {
public static void init() { //Todo: consider renaming the command to a more general name since it'll also have dungeon score and maybe other stuff in the future
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker")
.then(ClientCommandManager.literal("hud")
.then(ClientCommandManager.literal("dungeonmap")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.awt.*;

public class DungeonMapConfigScreen extends Screen {

private int hudX = SkyblockerConfigManager.get().locations.dungeons.mapX;
private int hudY = SkyblockerConfigManager.get().locations.dungeons.mapY;
private int mapX = SkyblockerConfigManager.get().locations.dungeons.mapX;
private int mapY = SkyblockerConfigManager.get().locations.dungeons.mapY;
private int scoreX = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreX;
private int scoreY = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreY;
private static final Identifier MAP_BACKGROUND = new Identifier("textures/map/map_background.png");
private final Screen parent;

protected DungeonMapConfigScreen() {
Expand All @@ -27,37 +31,57 @@ public DungeonMapConfigScreen(Screen parent) {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
renderBackground(context, mouseX, mouseY, delta);
DungeonMap.renderHUDMap(context, hudX, hudY);
renderHUDMap(context, mapX, mapY);
renderHUDScore(context, scoreX, scoreY);
context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width >> 1, height >> 1, Color.GRAY.getRGB());
}

@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
float scaling = SkyblockerConfigManager.get().locations.dungeons.mapScaling;
int size = (int) (128 * scaling);
if (RenderHelper.pointIsInArea(mouseX, mouseY, hudX, hudY, hudX + size, hudY + size) && button == 0) {
hudX = (int) Math.max(Math.min(mouseX - (size >> 1), this.width - size), 0);
hudY = (int) Math.max(Math.min(mouseY - (size >> 1), this.height - size), 0);
int mapSize = (int) (128 * SkyblockerConfigManager.get().locations.dungeons.mapScaling);
float scoreScaling = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreScaling;
int scoreWidth = (int) (textRenderer.getWidth(DungeonScoreHUD.getFormattedScoreText()) * scoreScaling);
int scoreHeight = (int) (textRenderer.fontHeight * scoreScaling);
if (RenderHelper.pointIsInArea(mouseX, mouseY, mapX, mapY, mapX + mapSize, mapY + mapSize) && button == 0) {
mapX = (int) Math.max(Math.min(mouseX - (mapSize >> 1), this.width - mapSize), 0);
mapY = (int) Math.max(Math.min(mouseY - (mapSize >> 1), this.height - mapSize), 0);
} else if (RenderHelper.pointIsInArea(mouseX, mouseY, scoreX, scoreY, scoreX + scoreWidth, scoreY + scoreHeight) && button == 0) {
scoreX = (int) Math.max(Math.min(mouseX - (scoreWidth >> 1), this.width - scoreWidth), 0);
scoreY = (int) Math.max(Math.min(mouseY - (scoreHeight >> 1), this.height - scoreHeight), 0);
}
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button == 1) {
hudX = 2;
hudY = 2;
mapX = 2;
mapY = 2;
scoreX = Math.max((int) ((mapX + (64 * SkyblockerConfigManager.get().locations.dungeons.mapScaling)) - textRenderer.getWidth(DungeonScoreHUD.getFormattedScoreText()) * SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreScaling / 2), 0);
scoreY = (int) (mapY + (128 * SkyblockerConfigManager.get().locations.dungeons.mapScaling) + 4);
}

return super.mouseClicked(mouseX, mouseY, button);
}

@Override
public void close() {
SkyblockerConfigManager.get().locations.dungeons.mapX = hudX;
SkyblockerConfigManager.get().locations.dungeons.mapY = hudY;
SkyblockerConfigManager.get().locations.dungeons.mapX = mapX;
SkyblockerConfigManager.get().locations.dungeons.mapY = mapY;
SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreX = scoreX;
SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreY = scoreY;
SkyblockerConfigManager.save();

this.client.setScreen(parent);
}

public void renderHUDMap(DrawContext context, int x, int y) {
float scaling = SkyblockerConfigManager.get().locations.dungeons.mapScaling;
int size = (int) (128 * scaling);
context.drawTexture(MAP_BACKGROUND, x, y, 0, 0, size, size, size, size);
}

public void renderHUDScore(DrawContext context, int x, int y) {
DungeonScoreHUD.render(context, x, y);
}
}
Loading

0 comments on commit a092f33

Please sign in to comment.