generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from RappyLabyAddons/feat/update
Add support for `1.20.2`
- Loading branch information
Showing
17 changed files
with
138 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 10 additions & 43 deletions
53
core/src/main/java/com/rappytv/deathfinder/events/DeathEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
core/src/main/java/com/rappytv/deathfinder/listeners/DeathListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
game-runner/src/v1_20_2/java/com/rappytv/deathfinder/v1_20_2/mixins/DeathScreenMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters