Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title container #196

Merged
merged 17 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod_menu_version=7.0.1
## REI (https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items/files)
rei_version=12.0.625
## Renderer (https://github.com/0x3C50/Renderer)
renderer_version = master-SNAPSHOT
renderer_version = d687aced4c

# Mod Properties
mod_version = 1.10.0
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import me.xmrvizzy.skyblocker.skyblock.tabhud.TabHud;
import me.xmrvizzy.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import me.xmrvizzy.skyblocker.utils.*;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void onInitializeClient() {
TabHud.init();
DungeonMap.init();
TheRift.init();
TitleContainer.init();
containerSolverManager.init();
scheduler.scheduleCyclic(Utils::update, 20);
scheduler.scheduleCyclic(DiscordRPCManager::updateDataAndPresence, 100);
Expand Down
58 changes: 51 additions & 7 deletions src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.xmrvizzy.skyblocker.config;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
Expand All @@ -10,8 +11,6 @@
import me.xmrvizzy.skyblocker.chat.ChatFilterResult;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;

import java.util.ArrayList;
Expand Down Expand Up @@ -175,6 +174,11 @@ public static class General {
@ConfigEntry.Gui.CollapsibleObject()
public Hitbox hitbox = new Hitbox();

@ConfigEntry.Gui.Tooltip()
@ConfigEntry.Category("titleContainer")
@ConfigEntry.Gui.CollapsibleObject()
public TitleContainer titleContainer = new TitleContainer();

@ConfigEntry.Gui.Excluded
public List<Integer> lockedSlots = new ArrayList<>();
}
Expand Down Expand Up @@ -247,6 +251,45 @@ public static class Hitbox {
public boolean oldLeverHitbox = false;
}

public static class TitleContainer {
@ConfigEntry.BoundedDiscrete(min = 30, max = 140)
public float titleContainerScale = 100;
public int x = 540;
public int y = 10;
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public Direction direction = Direction.HORIZONTAL;
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
public Alignment alignment = Alignment.MIDDLE;
}

public enum Direction {
HORIZONTAL,
VERTICAL;

@Override
public String toString() {
return switch (this) {
case HORIZONTAL -> "Horizontal";
case VERTICAL -> "Vertical";
};
}
}

public enum Alignment {
LEFT,
RIGHT,
MIDDLE;

@Override
public String toString() {
return switch (this) {
case LEFT -> "Left";
case RIGHT -> "Right";
case MIDDLE -> "Middle";
};
}
}

public static class RichPresence {
public boolean enableRichPresence = false;
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
Expand Down Expand Up @@ -399,6 +442,10 @@ public static class VampireSlayer {
@ConfigEntry.BoundedDiscrete(min = 1, max = 10)
@ConfigEntry.Gui.Tooltip()
public int steakStakeUpdateFrequency = 5;
public boolean enableManiaIndicator = true;
@ConfigEntry.BoundedDiscrete(min = 1, max = 10)
@ConfigEntry.Gui.Tooltip()
public int maniaUpdateFrequency = 5;
}

public static class Messages {
Expand Down Expand Up @@ -452,11 +499,8 @@ public static void init() {
private static LiteralArgumentBuilder<FabricClientCommandSource> optionsLiteral(String name) {
return literal(name).executes(context -> {
// Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed
SkyblockerMod.getInstance().scheduler.schedule(() -> {
Screen a = AutoConfig.getConfigScreen(SkyblockerConfig.class, null).get();
MinecraftClient.getInstance().setScreen(a);
}, 0);
return 1;
SkyblockerMod.getInstance().scheduler.queueOpenScreen(AutoConfig.getConfigScreen(SkyblockerConfig.class, null));
return Command.SINGLE_SUCCESS;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.utils.RenderHelper;
import me.xmrvizzy.skyblocker.utils.title.Title;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.util.math.Vec3d;

public class FishingHelper {
private static final Title title = new Title("skyblocker.fishing.reelNow", Formatting.GREEN);
private static long startTime;
private static Vec3d normalYawVector;

Expand Down Expand Up @@ -49,7 +51,7 @@ public static void onSound(MinecraftClient client, PlaySoundS2CPacket packet) {
if (player != null && player.fishHook != null) {
Vec3d soundToFishHook = player.fishHook.getPos().subtract(packet.getX(), 0, packet.getZ());
if (Math.abs(normalYawVector.x * soundToFishHook.z - normalYawVector.z * soundToFishHook.x) < 0.2D && Math.abs(normalYawVector.dotProduct(soundToFishHook)) < 4D && player.getPos().squaredDistanceTo(packet.getX(), packet.getY(), packet.getZ()) > 1D) {
RenderHelper.displayTitleAndPlaySound(10, 5, "skyblocker.fishing.reelNow", Formatting.GREEN);
RenderHelper.displayInTitleContainerAndPlaySound(title, 10);
reset();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class EffigyWaypoints {
);
private static final List<BlockPos> unBrokenEffigies = new ArrayList<>();

public static void updateEffigies() {
protected static void updateEffigies() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableEffigyWaypoints || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) return;

unBrokenEffigies.clear();
Expand Down Expand Up @@ -61,7 +61,7 @@ public static void updateEffigies() {
}
}

public static void render(WorldRenderContext context) {
protected static void render(WorldRenderContext context) {
if (SkyblockerConfig.get().slayer.vampireSlayer.enableEffigyWaypoints && Utils.getLocation().contains("Stillgore Château")) {
for (BlockPos effigy : unBrokenEffigies) {
float[] colorComponents = DyeColor.RED.getColorComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.utils.RenderHelper;
import me.xmrvizzy.skyblocker.utils.Utils;
import me.xmrvizzy.skyblocker.utils.title.Title;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.Formatting;

public class HealingMelonIndicator {
private static long lastDisplayTime = 0;
private static final Title title = new Title("skyblocker.rift.healNow", Formatting.DARK_RED);

public static void updateHealth(MinecraftClient client) {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHealingMelonIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) return;
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHealingMelonIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château")) {
TitleContainer.removeTitle(title);
return;
}
ClientPlayerEntity player = client.player;
if (player != null && player.getHealth() <= SkyblockerConfig.get().slayer.vampireSlayer.healingMelonHealthThreshold * 2F && System.currentTimeMillis() - lastDisplayTime > 2500) {
lastDisplayTime = System.currentTimeMillis();
RenderHelper.displayTitleAndPlaySound(15, 5, "skyblocker.rift.healNow", Formatting.DARK_RED);
if (player != null && player.getHealth() <= SkyblockerConfig.get().slayer.vampireSlayer.healingMelonHealthThreshold * 2F) {
RenderHelper.displayInTitleContainerAndPlaySound(title);
} else {
TitleContainer.removeTitle(title);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.xmrvizzy.skyblocker.skyblock.rift;

import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.utils.RenderHelper;
import me.xmrvizzy.skyblocker.utils.SlayerUtils;
import me.xmrvizzy.skyblocker.utils.Utils;
import me.xmrvizzy.skyblocker.utils.title.Title;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;

public class ManiaIndicator {
private static final Title title = new Title("skyblocker.rift.mania", Formatting.RED);

protected static void updateMania() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableManiaIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) {
TitleContainer.removeTitle(title);
return;
}

Entity slayerEntity = SlayerUtils.getSlayerEntity();
if (slayerEntity == null) return;

boolean anyMania = false;
for (Entity entity : SlayerUtils.getEntityArmorStands(slayerEntity)) {
if (entity.getDisplayName().toString().contains("MANIA")) {
anyMania = true;
BlockPos pos = MinecraftClient.getInstance().player.getBlockPos().down();
boolean isGreen = MinecraftClient.getInstance().world.getBlockState(pos).getBlock() == Blocks.GREEN_TERRACOTTA;
title.setFormatting(isGreen ? Formatting.GREEN : Formatting.RED);
RenderHelper.displayInTitleContainerAndPlaySound(title);
}
}
if (!anyMania) {
TitleContainer.removeTitle(title);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MirrorverseWaypoints {
/**
* Loads the waypoint locations into memory
*/
public static void loadWaypoints() {
private static void loadWaypoints() {
try (BufferedReader reader = CLIENT.getResourceManager().openAsReader(WAYPOINTS_JSON)) {
JsonObject file = JsonParser.parseReader(reader).getAsJsonObject();
JsonArray sections = file.get("sections").getAsJsonArray();
Expand Down Expand Up @@ -69,7 +69,7 @@ public static void loadWaypoints() {
}
}

public static void render(WorldRenderContext wrc) {
protected static void render(WorldRenderContext wrc) {
//I would also check for the mirrorverse location but the scoreboard stuff is not performant at all...
if (Utils.isInTheRift() && SkyblockerConfig.get().locations.rift.mirrorverseWaypoints) {
for (BlockPos pos : LAVA_PATH_WAYPOINTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
import me.xmrvizzy.skyblocker.utils.RenderHelper;
import me.xmrvizzy.skyblocker.utils.SlayerUtils;
import me.xmrvizzy.skyblocker.utils.Utils;
import me.xmrvizzy.skyblocker.utils.title.Title;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class StakeIndicator {
private static long lastDisplayTime = 0;
private static final Title title = new Title("skyblocker.rift.stakeNow",Formatting.RED);

public static void updateStake() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableSteakStakeIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château") || !SlayerUtils.isInSlayer()) return;
protected static void updateStake() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableSteakStakeIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !Utils.getLocation().contains("Stillgore Château") || !SlayerUtils.isInSlayer()) {
TitleContainer.removeTitle(title);
return;
}
Entity slayerEntity = SlayerUtils.getSlayerEntity();
if (slayerEntity != null && slayerEntity.getDisplayName().toString().contains("҉") && System.currentTimeMillis() - lastDisplayTime > 2500) {
lastDisplayTime = System.currentTimeMillis();
RenderHelper.displayTitleAndPlaySound(25, 5, "skyblocker.rift.stakeNow", Formatting.RED);
if (slayerEntity != null && slayerEntity.getDisplayName().toString().contains("҉")) {
RenderHelper.displayInTitleContainerAndPlaySound(title);
} else {
TitleContainer.removeTitle(title);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void init() {
WorldRenderEvents.AFTER_TRANSLUCENT.register(EffigyWaypoints::render);
SkyblockerMod.getInstance().scheduler.scheduleCyclic(EffigyWaypoints::updateEffigies, SkyblockerConfig.get().slayer.vampireSlayer.effigyUpdateFrequency);
SkyblockerMod.getInstance().scheduler.scheduleCyclic(TwinClawsIndicator::updateIce, SkyblockerConfig.get().slayer.vampireSlayer.holyIceUpdateFrequency);
SkyblockerMod.getInstance().scheduler.scheduleCyclic(ManiaIndicator::updateMania, SkyblockerConfig.get().slayer.vampireSlayer.maniaUpdateFrequency);
SkyblockerMod.getInstance().scheduler.scheduleCyclic(StakeIndicator::updateStake, SkyblockerConfig.get().slayer.vampireSlayer.steakStakeUpdateFrequency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,40 @@
import me.xmrvizzy.skyblocker.utils.RenderHelper;
import me.xmrvizzy.skyblocker.utils.SlayerUtils;
import me.xmrvizzy.skyblocker.utils.Utils;
import me.xmrvizzy.skyblocker.utils.title.Title;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class TwinClawsIndicator {
private static long lastDisplayTime = 0;
private static final Title title = new Title("skyblocker.rift.iceNow",Formatting.AQUA);
private static boolean scheduled = false;

public static void updateIce() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHolyIceIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) return;
protected static void updateIce() {
if (!SkyblockerConfig.get().slayer.vampireSlayer.enableHolyIceIndicator || !Utils.isOnSkyblock() || !Utils.isInTheRift() || !(Utils.getLocation().contains("Stillgore Château")) || !SlayerUtils.isInSlayer()) {
TitleContainer.removeTitle(title);
return;
}

Entity slayerEntity = SlayerUtils.getSlayerEntity();
if (slayerEntity == null) return;

boolean anyClaws = false;
for (Entity entity : SlayerUtils.getEntityArmorStands(slayerEntity)) {
if (entity.getDisplayName().toString().contains("TWINCLAWS")) {
SkyblockerMod.getInstance().scheduler.schedule(() -> {
if (System.currentTimeMillis() - lastDisplayTime > 2500) {
lastDisplayTime = System.currentTimeMillis();
RenderHelper.displayTitleAndPlaySound(40, 5, "skyblocker.rift.iceNow", Formatting.AQUA);
}
}, SkyblockerConfig.get().slayer.vampireSlayer.holyIceIndicatorTickDelay);
anyClaws = true;
if (!TitleContainer.containsTitle(title) && !scheduled) {
scheduled = true;
SkyblockerMod.getInstance().scheduler.schedule(() -> {
RenderHelper.displayInTitleContainerAndPlaySound(title);
scheduled = false;
}, SkyblockerConfig.get().slayer.vampireSlayer.holyIceIndicatorTickDelay);
}
}
}

if (!anyClaws) {
TitleContainer.removeTitle(title);
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/me/xmrvizzy/skyblocker/utils/RenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import me.x150.renderer.render.Renderer3d;
import me.xmrvizzy.skyblocker.mixin.accessor.BeaconBlockEntityRendererInvoker;
import me.xmrvizzy.skyblocker.utils.title.Title;
import me.xmrvizzy.skyblocker.utils.title.TitleContainer;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer;
Expand Down Expand Up @@ -51,6 +53,31 @@ public static void displayTitleAndPlaySound(int stayTicks, int fadeOutTicks, Str
playNotificationSound();
}

/**
* Adds the title to {@link TitleContainer} and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already.
* No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller.
*
* @param title the title
*/
public static void displayInTitleContainerAndPlaySound(Title title) {
if (TitleContainer.addTitle(title)) {
playNotificationSound();
}
}

/**
* Adds the title to {@link TitleContainer} for a set number of ticks and {@link #playNotificationSound() plays the notification sound} if the title is not in the {@link TitleContainer} already.
* No checking needs to be done on whether the title is in the {@link TitleContainer} already by the caller.
*
* @param title the title
* @param ticks the number of ticks the title will remain
*/
public static void displayInTitleContainerAndPlaySound(Title title, int ticks) {
if (TitleContainer.addTitle(title, ticks)) {
playNotificationSound();
}
}

private static void playNotificationSound() {
if (MinecraftClient.getInstance().player != null) {
MinecraftClient.getInstance().player.playSound(SoundEvent.of(new Identifier("entity.experience_orb.pickup")), 100f, 0.1f);
Expand Down
Loading