Skip to content

Commit

Permalink
Merge pull request #12 from RappyLabyAddons/feat/update
Browse files Browse the repository at this point in the history
Add support for `1.20.2`
  • Loading branch information
RappyTV authored Sep 27, 2023
2 parents 0875a6a + cb1c2fc commit 34eedfb
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 67 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,8 +14,8 @@
@AddonMain
public class DeathFinderAddon extends LabyAddon<DeathFinderConfig> {

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;
Expand All @@ -27,6 +28,7 @@ protected void enable() {
registerSettingCategory();
registerCommand(new BackCommand(this));
registerCommand(new CoordsCommand(this));
registerListener(new DeathListener(this));
}

@Override
Expand Down
53 changes: 10 additions & 43 deletions core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
7 changes: 0 additions & 7 deletions core/src/main/java/com/rappytv/deathfinder/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,6 +33,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,6 @@ public void onDeathScreen(CallbackInfo ci) {
}
if(deathLocation.equals(DeathFinderAddon.getDeathLocation())) return;

new DeathEvent(deathLocation);
Laby.fireEvent(new DeathEvent(deathLocation));
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down

0 comments on commit 34eedfb

Please sign in to comment.