Skip to content

Commit

Permalink
more translatable text
Browse files Browse the repository at this point in the history
mixins changes
shows now previous personalBest
and more
  • Loading branch information
7azeemm committed Nov 6, 2024
1 parent d8ca611 commit 4f4a15b
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 119 deletions.
56 changes: 56 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixins/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,84 @@

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.skyblock.slayers.SlayerManager;
import de.hysky.skyblocker.skyblock.slayers.boss.voidgloom.LazerTimer;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.UUID;

@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow
@Final
private EntityType<?> type;

@Shadow
public abstract UUID getUuid();

@Shadow
public abstract EntityType<?> getType();

@Shadow
public abstract BlockPos getBlockPos();

@Shadow
public abstract Vec3d getPos();

@Shadow
public abstract @Nullable Entity getVehicle();

@Shadow
public abstract boolean isInvisible();

@ModifyExpressionValue(method = "isInvisibleTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isSpectator()Z"))
public boolean skyblocker$showInvisibleArmorStands(boolean isSpectator, PlayerEntity player) {
return isSpectator || (isInvisible() && Utils.isOnHypixel() && Debug.debugEnabled() && SkyblockerConfigManager.get().debug.showInvisibleArmorStands && type.equals(EntityType.ARMOR_STAND));
}

@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("RETURN"))
private void onStartRiding(Entity entity, boolean force, CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValue()) {
if (SkyblockerConfigManager.get().slayers.endermanSlayer.lazerTimer && SlayerManager.isBossSpawned() && this.getType() == EntityType.ENDERMAN && entity.getType() == EntityType.ARMOR_STAND) {
MobEntity slayer = SlayerManager.getSlayerEntity(EndermanEntity.class);
if (slayer != null) {
if (slayer.getUuid().equals(getUuid()) && !LazerTimer.isRiding()) {
LazerTimer.bossUUID = getUuid();
LazerTimer.bossLocation = getPos();
LazerTimer.resetTimer();
LazerTimer.setRiding(true);
}
}
}
}
}

@Inject(method = "tick", at = @At("TAIL"))
private void onTick(CallbackInfo ci) {
if (this.getType() == EntityType.ENDERMAN) {
if (LazerTimer.isRiding() && LazerTimer.bossUUID.equals(getUuid()) && getVehicle() == null) {
if (LazerTimer.remainingTime > 5.0) return;
LazerTimer.bossUUID = null;
LazerTimer.bossLocation = null;
LazerTimer.setRiding(false);
}
}
}
}
68 changes: 0 additions & 68 deletions src/main/java/de/hysky/skyblocker/mixins/EntityRideMixin.java

This file was deleted.

16 changes: 15 additions & 1 deletion src/main/java/de/hysky/skyblocker/mixins/SoundSystemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,41 @@
import de.hysky.skyblocker.skyblock.slayers.SlayerManager;
import de.hysky.skyblocker.utils.LocationUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.title.Title;
import de.hysky.skyblocker.utils.render.title.TitleContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.client.sound.SoundSystem;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
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;

@Mixin(SoundSystem.class)
public class SoundSystemMixin {

@Unique
private static long lastWarningTime = 0;

@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At("TAIL"))
private void onPlayTail(SoundInstance soundInstance, CallbackInfo ci) {
if (SkyblockerConfigManager.get().slayers.miniBossSpawnAlert && Utils.isOnSkyblock() && soundInstance.getSound() != null && soundInstance.getId().equals(Identifier.ofVanilla("entity.generic.explode"))) {
if (SlayerManager.isInSlayer() && SlayerManager.getSlayerQuest().isLfMinis() && soundInstance.getPitch() == 9 / 7f && soundInstance.getVolume() == 0.6f) {
//Checks if MiniBoss is within a radius of the client's location
if (LocationUtils.isWithinRadius(BlockPos.ofFloored(soundInstance.getX(), soundInstance.getY(), soundInstance.getZ()), 15)) {
Utils.warn(I18n.translate("skyblocker.slayer.miniBossSpawnAlert"));
long currentTime = System.currentTimeMillis();
if (currentTime - lastWarningTime >= 1000) {
TitleContainer.addTitle(new Title(Text.literal(I18n.translate("skyblocker.slayer.miniBossSpawnAlert")).formatted(Formatting.RED)), 20);
MinecraftClient.getInstance().player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING.value(), 0.5f, 0.1f);
lastWarningTime = currentTime;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import de.hysky.skyblocker.skyblock.slayers.features.SlainTime;
import de.hysky.skyblocker.utils.RomanNumerals;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.title.Title;
import de.hysky.skyblocker.utils.render.title.TitleContainer;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
Expand All @@ -16,7 +18,9 @@
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.mob.CaveSpiderEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -109,8 +113,10 @@ private static void bossSpawnAlert() {
for (String line : Utils.STRING_SCOREBOARD) {
if (line.contains("Slay the boss!")) {
if (quest != null && !bossSpawned && !quest.slain) {
if (SkyblockerConfigManager.get().slayers.bossSpawnAlert)
Utils.warn(I18n.translate("skyblocker.slayer.bossSpawnAlert"));
if (SkyblockerConfigManager.get().slayers.bossSpawnAlert) {
TitleContainer.addTitle(new Title(Text.literal(I18n.translate("skyblocker.slayer.bossSpawnAlert")).formatted(Formatting.RED)), 20);
MinecraftClient.getInstance().player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING.value(), 0.5f, 0.1f);
}
bossSpawned = true;
quest.lfMinis = false;
startTime = Instant.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

public class LazerTimer {

public static UUID BossUUID = null;
public static Vec3d BossLocation = null;
public static UUID bossUUID = null;
public static Vec3d bossLocation = null;

public static double remainingTime = 0;
private static boolean isRiding = false;

@Init
public static void Init() {
public static void init() {
WorldRenderEvents.AFTER_TRANSLUCENT.register(LazerTimer::render);
Scheduler.INSTANCE.scheduleCyclic(LazerTimer::updateTimer, 1);
}
Expand All @@ -38,8 +38,8 @@ private static void updateTimer() {
if (remainingTime <= 0) {
remainingTime = 0;
isRiding = false;
BossUUID = null;
BossLocation = null;
bossUUID = null;
bossLocation = null;
}
}
}
Expand All @@ -52,8 +52,8 @@ public static boolean isRiding() {
return isRiding;
}

public static void setRiding(boolean Riding) {
isRiding = Riding;
public static void setRiding(boolean riding) {
isRiding = riding;
}

private static void render(WorldRenderContext context) {
Expand All @@ -62,7 +62,7 @@ private static void render(WorldRenderContext context) {
Text renderText = Text.literal("Lazer: ").formatted(Formatting.WHITE)
.append(Text.literal(timeText).formatted(Formatting.GREEN).formatted(Formatting.BOLD));

RenderHelper.renderText(context, renderText, BossLocation.add(0, 2, 0), true);
RenderHelper.renderText(context, renderText, bossLocation.add(0, 2, 0), true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ private static void save() {
});
}

public static boolean isPersonalBest(String slayer, Duration time) {
public static Duration getPersonalBest(String slayer) {
String profileId = Utils.getProfileId();
Object2ObjectOpenHashMap<String, SlayerInfo> profileData = CACHED_SLAYER_STATS.computeIfAbsent(profileId, _uuid -> new Object2ObjectOpenHashMap<>());

SlayerInfo currentBest = profileData.get(slayer);
return currentBest == null || time.toMillis() < currentBest.bestTime().toMillis();
return currentBest != null ? currentBest.bestTime() : null;
}

public static void updateBestTime(String slayerType, Duration duration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.hysky.skyblocker.skyblock.slayers.SlayerManager;
import de.hysky.skyblocker.utils.Constants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

Expand All @@ -16,19 +17,27 @@ public static void onBossDeath(Instant startTime) {
if (SkyblockerConfigManager.get().slayers.slainTime & startTime != null) {
Instant slainTime = Instant.now();
Duration timeElapsed = Duration.between(startTime, slainTime);
String duration = formatTime(timeElapsed);

long totalSeconds = timeElapsed.getSeconds();
long milliseconds = timeElapsed.toMillis() % 1000;
Duration currentPB = PersonalBest.getPersonalBest(SlayerManager.getSlayerType() + SlayerManager.getSlayerTier());

String duration = String.format("%d.%02ds", totalSeconds, milliseconds / 10);

Text message = Text.of(Constants.PREFIX.get().append("Slayer Boss has been killed in " + duration));
if (PersonalBest.isPersonalBest(SlayerManager.getSlayerType() + SlayerManager.getSlayerTier(), timeElapsed)) {
message = Text.of(Constants.PREFIX.get().append("Slayer Boss has been killed in " + duration).append(Text.literal(" PERSONAL BEST").formatted(Formatting.LIGHT_PURPLE)));
if(currentPB != null && (currentPB.toMillis() > timeElapsed.toMillis())) {
MinecraftClient.getInstance().player.sendMessage(Text.of(Constants.PREFIX.get().append(I18n.translate("skyblocker.slayer.slainTime")).append(Text.literal(duration).formatted(Formatting.YELLOW)).append("! ").append(Text.literal(I18n.translate("skyblocker.slayer.personalBest")).formatted(Formatting.LIGHT_PURPLE)).append(Text.literal("!"))), false);
MinecraftClient.getInstance().player.sendMessage(Text.of(Constants.PREFIX.get().append(I18n.translate("skyblocker.slayer.previousPB")).append(Text.literal(formatTime(currentPB)).formatted(Formatting.YELLOW)).append(".")), false);
PersonalBest.updateBestTime(SlayerManager.getSlayerType() + SlayerManager.getSlayerTier(), timeElapsed);
} else {
MinecraftClient.getInstance().player.sendMessage(Text.of(Constants.PREFIX.get().append(I18n.translate("skyblocker.slayer.slainTime")).append(Text.literal(duration).formatted(Formatting.YELLOW)).append("!")), false);
if(currentPB == null) {
PersonalBest.updateBestTime(SlayerManager.getSlayerType() + SlayerManager.getSlayerTier(), timeElapsed);
}
}

MinecraftClient.getInstance().player.sendMessage(message, false);
}
}

private static String formatTime(Duration timeElapsed) {
long totalSeconds = timeElapsed.getSeconds();
long milliseconds = timeElapsed.toMillis() % 1000;

return String.format("%d.%02ds", totalSeconds, milliseconds / 10);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

Expand All @@ -32,24 +33,24 @@ public void updateContent() {
addSimpleIcoText(Ico.NETHER_STAR, " ", Formatting.GOLD, type + " " + tier);
if (level != -1) {
boolean isMaxed = switch (type) {
case "Riftstalker Bloodfiend" -> level == 5;
case SlayerConstants.VAMPIRE -> level == 5;
default -> level == 9;
};
if (isMaxed) {
addSimpleIcoText(Ico.ENCHANTING_TABLE, "Level up in: ", Formatting.GREEN, "MAXED OUT");
addSimpleIcoText(Ico.ENCHANTING_TABLE, I18n.translate("skyblocker.slayer.hud.lvlUpIn"), Formatting.GREEN, I18n.translate("skyblocker.slayer.hud.lvlMaxed"));
} else {
int nextMilestone = switch (type) {
case "Revenant Horror" -> SlayerConstants.ZombieLevelMilestones[level];
case "Tarantula Broodfather" -> SlayerConstants.SpiderLevelMilestones[level];
case "Riftstalker Bloodfiend" -> SlayerConstants.VampireLevelMilestones[level];
case SlayerConstants.REVENANT -> SlayerConstants.ZombieLevelMilestones[level];
case SlayerConstants.TARA -> SlayerConstants.SpiderLevelMilestones[level];
case SlayerConstants.VAMPIRE -> SlayerConstants.VampireLevelMilestones[level];
default -> SlayerConstants.RegularLevelMilestones[level];
};
int currentXP = nextMilestone - SlayerManager.xpRemaining;
addSimpleIcoText(Ico.ENCHANTING_TABLE, "Level up in: ", Formatting.AQUA, numberFormat.format(currentXP) + "/" + numberFormat.format(nextMilestone));
addSimpleIcoText(Ico.ENCHANTING_TABLE, I18n.translate("skyblocker.slayer.hud.lvlUpIn"), Formatting.AQUA, numberFormat.format(currentXP) + "/" + numberFormat.format(nextMilestone));
}
}
if (SlayerManager.xpRemaining > 0) {
addSimpleIcoText(Ico.DIASWORD, "bosses until level up: ", Formatting.AQUA, numberFormat.format(SlayerManager.calculateBossesNeeded()));
addSimpleIcoText(Ico.DIASWORD, I18n.translate("skyblocker.slayer.hud.bossesNeeded"), Formatting.AQUA, numberFormat.format(SlayerManager.calculateBossesNeeded()));
}
}
}
Loading

0 comments on commit 4f4a15b

Please sign in to comment.