diff --git a/build.gradle.kts b/build.gradle.kts index 02ffa7f..9f0d90d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,8 +20,8 @@ labyMod { displayName = "Death Finder" author = "RappyTV" description = "This addon saves your last death point, so you can find your items again." - minecraftVersion = "1.8<1.20.1" - version = System.getenv().getOrDefault("VERSION", "1.0.2") + minecraftVersion = "1.8<1.20.2" + version = System.getenv().getOrDefault("VERSION", "1.0.3") } minecraft { @@ -34,7 +34,8 @@ labyMod { "1.19.2", "1.19.3", "1.19.4", - "1.20.1" + "1.20.1", + "1.20.2" ) { version, provider -> configureRun(provider, version) } diff --git a/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java b/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java index 76c17bf..ee50c3e 100644 --- a/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java +++ b/core/src/main/java/com/rappytv/deathfinder/DeathFinderAddon.java @@ -2,6 +2,7 @@ import com.rappytv.deathfinder.commands.BackCommand; import com.rappytv.deathfinder.commands.CoordsCommand; +import com.rappytv.deathfinder.listeners.DeathListener; import com.rappytv.deathfinder.util.Location; import net.labymod.api.addon.LabyAddon; import net.labymod.api.client.component.Component; @@ -13,8 +14,8 @@ @AddonMain public class DeathFinderAddon extends LabyAddon { - public final static Component prefix = Component - .text("DF ", Style.builder().color(NamedTextColor.DARK_PURPLE).decorate(TextDecoration.BOLD).build()) + public final static Component prefix = Component.empty() + .append(Component.text("DF ", Style.builder().color(NamedTextColor.DARK_PURPLE).decorate(TextDecoration.BOLD).build())) .append(Component.text("» ", NamedTextColor.DARK_GRAY)); private static Location deathLocation; @@ -27,6 +28,7 @@ protected void enable() { registerSettingCategory(); registerCommand(new BackCommand(this)); registerCommand(new CoordsCommand(this)); + registerListener(new DeathListener(this)); } @Override diff --git a/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java b/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java index d1b2461..808a3bb 100644 --- a/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java +++ b/core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java @@ -1,51 +1,18 @@ package com.rappytv.deathfinder.events; -import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.util.Location; -import com.rappytv.deathfinder.util.Util; -import net.labymod.api.Laby; -import net.labymod.api.client.component.Component; -import net.labymod.api.client.component.TextComponent; -import net.labymod.api.client.component.event.ClickEvent; -import net.labymod.api.client.component.event.HoverEvent; -import net.labymod.api.client.component.format.NamedTextColor; -import net.labymod.api.client.component.format.Style; -import net.labymod.api.client.component.format.TextDecoration; +import net.labymod.api.event.Event; +import org.jetbrains.annotations.NotNull; +import java.util.Objects; -public class DeathEvent { +public record DeathEvent(Location location) implements Event { - public DeathEvent(Location location) { - if(!DeathFinderAddon.get().configuration().enabled().get()) return; - boolean backCommand = DeathFinderAddon.get().configuration().backCommand().get(); - boolean coordsCommand = DeathFinderAddon.get().configuration().coordsCommand().get(); - - DeathFinderAddon.setDeathLocation(location); - - // Message - - Component builder = Component - .text("»\n", NamedTextColor.DARK_GRAY) - .append(DeathFinderAddon.prefix) - .append(Component.translatable("deathfinder.messages.savedPoint", NamedTextColor.GREEN)) - .append(Component.text("\n")); + public DeathEvent { + Objects.requireNonNull(location, "Location cannot be null!"); + } - if(backCommand || coordsCommand) builder.append(DeathFinderAddon.prefix); - if(backCommand) builder.append( - Component - .text("[", NamedTextColor.DARK_GRAY) - .append(Component.text("TP", Style.builder().color(NamedTextColor.RED).decorate(TextDecoration.BOLD).build())) - .append(Component.text("]", NamedTextColor.DARK_GRAY)) - .hoverEvent(HoverEvent.showText(TextComponent.builder().text("§a" + Util.getTranslation("deathfinder.messages.clickToTeleport")).build())) - .clickEvent(ClickEvent.runCommand("/back")) - ); - if(backCommand && coordsCommand) builder.append(Component.text(" §7| ")); - if(coordsCommand) builder.append( - Component - .text("§8[§b§lINFO§8]") - .hoverEvent(HoverEvent.showText(TextComponent.builder().text("§a" + Util.getTranslation("deathfinder.messages.clickToShow")).build())) - .clickEvent(ClickEvent.runCommand("/coords")) - ); - builder.append(Component.text((backCommand || coordsCommand ? "\n" : "") + "§8»", NamedTextColor.DARK_GRAY)); - Laby.references().chatExecutor().displayClientMessage(builder); + @Override + public @NotNull Location location() { + return location; } } diff --git a/core/src/main/java/com/rappytv/deathfinder/listeners/DeathListener.java b/core/src/main/java/com/rappytv/deathfinder/listeners/DeathListener.java new file mode 100644 index 0000000..ab9f097 --- /dev/null +++ b/core/src/main/java/com/rappytv/deathfinder/listeners/DeathListener.java @@ -0,0 +1,57 @@ +package com.rappytv.deathfinder.listeners; + +import com.rappytv.deathfinder.DeathFinderAddon; +import com.rappytv.deathfinder.events.DeathEvent; +import com.rappytv.deathfinder.util.Util; +import net.labymod.api.client.component.Component; +import net.labymod.api.client.component.event.ClickEvent; +import net.labymod.api.client.component.event.HoverEvent; +import net.labymod.api.client.component.format.NamedTextColor; +import net.labymod.api.client.component.format.Style; +import net.labymod.api.client.component.format.TextDecoration; +import net.labymod.api.event.Subscribe; + +public class DeathListener { + + private final DeathFinderAddon addon; + + public DeathListener(DeathFinderAddon addon) { + this.addon = addon; + } + + @Subscribe + public void onDeath(DeathEvent event) { + if(!addon.configuration().enabled().get()) return; + boolean backCommand = addon.configuration().backCommand().get(); + boolean coordsCommand = addon.configuration().coordsCommand().get(); + + DeathFinderAddon.setDeathLocation(event.location()); + + Component info = Component.translatable("deathfinder.messages.savedPoint", NamedTextColor.GREEN); + if(!backCommand && !coordsCommand) { + Util.msg(info); + return; + } + + Component interactable = Component.empty(); + if(backCommand) interactable.append( + Component + .text("[", NamedTextColor.DARK_GRAY) + .append(Component.text("TP", Style.builder().color(NamedTextColor.RED).decorate(TextDecoration.BOLD).build())) + .append(Component.text("]", NamedTextColor.DARK_GRAY)) + .hoverEvent(HoverEvent.showText(Component.translatable("deathfinder.messages.clickToTeleport", NamedTextColor.GREEN))) + .clickEvent(ClickEvent.runCommand("/back")) + ); + if(backCommand && coordsCommand) interactable.append(Component.text(" | ", NamedTextColor.DARK_GRAY)); + if(coordsCommand) interactable.append( + Component + .text("[", NamedTextColor.DARK_GRAY) + .append(Component.text("INFOS", Style.builder().color(NamedTextColor.AQUA).decorate(TextDecoration.BOLD).build())) + .append(Component.text("]", NamedTextColor.DARK_GRAY)) + .hoverEvent(HoverEvent.showText(Component.translatable("deathfinder.messages.clickToShow", NamedTextColor.GREEN))) + .clickEvent(ClickEvent.runCommand("/coords")) + ); + Util.msg(info, interactable); + } + +} diff --git a/core/src/main/java/com/rappytv/deathfinder/util/Util.java b/core/src/main/java/com/rappytv/deathfinder/util/Util.java index aab17ee..08a8268 100644 --- a/core/src/main/java/com/rappytv/deathfinder/util/Util.java +++ b/core/src/main/java/com/rappytv/deathfinder/util/Util.java @@ -5,15 +5,8 @@ import com.rappytv.deathfinder.DeathFinderAddon; import net.labymod.api.client.component.Component; import net.labymod.api.client.component.format.NamedTextColor; -import net.labymod.api.util.I18n; public class Util { - public static String getTranslation(String key, Object... args) { - if(!I18n.has(key)) - return key; - return I18n.getTranslation(key, args); - } - public static void msg(Component... lines) { Component component = Component .text("»\n", NamedTextColor.DARK_GRAY); diff --git a/game-runner/src/v1_12_2/java/com/rappytv/deathfinder/v1_12_2/mixins/DeathScreenMixin.java b/game-runner/src/v1_12_2/java/com/rappytv/deathfinder/v1_12_2/mixins/DeathScreenMixin.java index 8188c09..d30d654 100644 --- a/game-runner/src/v1_12_2/java/com/rappytv/deathfinder/v1_12_2/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_12_2/java/com/rappytv/deathfinder/v1_12_2/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiGameOver; import net.minecraft.client.gui.GuiScreen; @@ -27,6 +28,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_16_5/java/com/rappytv/deathfinder/v1_16_5/mixins/DeathScreenMixin.java b/game-runner/src/v1_16_5/java/com/rappytv/deathfinder/v1_16_5/mixins/DeathScreenMixin.java index 3771ead..4baf364 100644 --- a/game-runner/src/v1_16_5/java/com/rappytv/deathfinder/v1_16_5/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_16_5/java/com/rappytv/deathfinder/v1_16_5/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_17_1/java/com/rappytv/deathfinder/v1_17_1/mixins/DeathScreenMixin.java b/game-runner/src/v1_17_1/java/com/rappytv/deathfinder/v1_17_1/mixins/DeathScreenMixin.java index fcf46a5..063c00c 100644 --- a/game-runner/src/v1_17_1/java/com/rappytv/deathfinder/v1_17_1/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_17_1/java/com/rappytv/deathfinder/v1_17_1/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_18_2/java/com/rappytv/deathfinder/v1_18_2/mixins/DeathScreenMixin.java b/game-runner/src/v1_18_2/java/com/rappytv/deathfinder/v1_18_2/mixins/DeathScreenMixin.java index c8a6307..f7dd36a 100644 --- a/game-runner/src/v1_18_2/java/com/rappytv/deathfinder/v1_18_2/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_18_2/java/com/rappytv/deathfinder/v1_18_2/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_19_2/java/com/rappytv/deathfinder/v1_19_2/mixins/DeathScreenMixin.java b/game-runner/src/v1_19_2/java/com/rappytv/deathfinder/v1_19_2/mixins/DeathScreenMixin.java index 945c351..1179aed 100644 --- a/game-runner/src/v1_19_2/java/com/rappytv/deathfinder/v1_19_2/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_19_2/java/com/rappytv/deathfinder/v1_19_2/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_19_3/java/com/rappytv/deathfinder/v1_19_3/mixins/DeathScreenMixin.java b/game-runner/src/v1_19_3/java/com/rappytv/deathfinder/v1_19_3/mixins/DeathScreenMixin.java index ad681aa..ccb8ec6 100644 --- a/game-runner/src/v1_19_3/java/com/rappytv/deathfinder/v1_19_3/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_19_3/java/com/rappytv/deathfinder/v1_19_3/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_19_4/java/com/rappytv/deathfinder/v1_19_4/mixins/DeathScreenMixin.java b/game-runner/src/v1_19_4/java/com/rappytv/deathfinder/v1_19_4/mixins/DeathScreenMixin.java index 8b4870c..fa66330 100644 --- a/game-runner/src/v1_19_4/java/com/rappytv/deathfinder/v1_19_4/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_19_4/java/com/rappytv/deathfinder/v1_19_4/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_20_1/java/com/rappytv/deathfinder/v1_20_1/mixins/DeathScreenMixin.java b/game-runner/src/v1_20_1/java/com/rappytv/deathfinder/v1_20_1/mixins/DeathScreenMixin.java index ee47da1..34b4e4c 100644 --- a/game-runner/src/v1_20_1/java/com/rappytv/deathfinder/v1_20_1/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_20_1/java/com/rappytv/deathfinder/v1_20_1/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.gui.screens.DeathScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.player.LocalPlayer; @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/game-runner/src/v1_20_2/java/com/rappytv/deathfinder/v1_20_2/mixins/DeathScreenMixin.java b/game-runner/src/v1_20_2/java/com/rappytv/deathfinder/v1_20_2/mixins/DeathScreenMixin.java new file mode 100644 index 0000000..1bf0875 --- /dev/null +++ b/game-runner/src/v1_20_2/java/com/rappytv/deathfinder/v1_20_2/mixins/DeathScreenMixin.java @@ -0,0 +1,42 @@ +package com.rappytv.deathfinder.v1_20_2.mixins; + +import com.rappytv.deathfinder.DeathFinderAddon; +import com.rappytv.deathfinder.events.DeathEvent; +import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; +import net.minecraft.client.gui.screens.DeathScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.network.chat.Component; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DeathScreen.class) +public class DeathScreenMixin extends Screen { + + protected DeathScreenMixin(Component title) { + super(title); + } + + @Inject(method = "init", at = @At("TAIL")) + public void onDeathScreen(CallbackInfo ci) { + System.out.println("\n\n1\n\n"); + if(this.minecraft == null || this.minecraft.player == null) return; + System.out.println("\n\n2\n\n"); + + LocalPlayer player = this.minecraft.player; + Location deathLocation = new Location(player.getX(), player.getY(), player.getZ()); + + if(DeathFinderAddon.get().configuration().saveRotation().get()) { + deathLocation.setYaw(player.getXRot()); + deathLocation.setPitch(player.getYRot()); + System.out.println("\n\n3\n\n"); + } + if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; + System.out.println("\n\n4\n\n"); + + Laby.fireEvent(new DeathEvent(deathLocation)); + } +} diff --git a/game-runner/src/v1_8_9/java/com/rappytv/deathfinder/v1_8_9/mixins/DeathScreenMixin.java b/game-runner/src/v1_8_9/java/com/rappytv/deathfinder/v1_8_9/mixins/DeathScreenMixin.java index 335ec9b..4d92ab8 100644 --- a/game-runner/src/v1_8_9/java/com/rappytv/deathfinder/v1_8_9/mixins/DeathScreenMixin.java +++ b/game-runner/src/v1_8_9/java/com/rappytv/deathfinder/v1_8_9/mixins/DeathScreenMixin.java @@ -3,6 +3,7 @@ import com.rappytv.deathfinder.DeathFinderAddon; import com.rappytv.deathfinder.events.DeathEvent; import com.rappytv.deathfinder.util.Location; +import net.labymod.api.Laby; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.GuiGameOver; import net.minecraft.client.gui.GuiScreen; @@ -27,6 +28,6 @@ public void onDeathScreen(CallbackInfo ci) { } if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return; - new DeathEvent(deathLocation); + Laby.fireEvent(new DeathEvent(deathLocation)); } } diff --git a/readme.md b/readme.md index 81a5c27..388ad7a 100644 --- a/readme.md +++ b/readme.md @@ -3,8 +3,8 @@ ### 📦 Installation 1. Press `Win` + `R` -2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter (This path may change when lm4 gets released) -3. It should open your Labymod addon directory; Paste the [Death-Finder.jar](https://github.com/RappyLabyAddons/Death-Finder/releases/download/v1.0.2/Death-Finder.jar) in there. +2. Paste this into the window that popped up: `%appdata%/.minecraft/LabyMod-neo/addons` and press enter +3. It should open your Labymod addon directory; Paste the [Death-Finder.jar](https://github.com/RappyLabyAddons/Death-Finder/releases/latest/download/Death-Finder.jar) in there. 4. Launch your Labymod client. If you have any problems with the addon/have update ideas, feel free to diff --git a/settings.gradle.kts b/settings.gradle.kts index 310f73a..3770190 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ rootProject.name = "deathfinder" pluginManagement { - val labyGradlePluginVersion = "0.3.28" + val labyGradlePluginVersion = "0.3.30" plugins { id("net.labymod.gradle") version (labyGradlePluginVersion) }