Skip to content

Commit c507e3b

Browse files
authored
Update mod to include Fishing related features
* Add Fishing Islands to reportable places * Add a hotkey to copy a fishing spot and its perks
1 parent 0c2aef0 commit c507e3b

File tree

9 files changed

+111
-20
lines changed

9 files changed

+111
-20
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ You need Minecraft 1.21.1 and at least [Noxesium 2.3.1](https://modrinth.com/mod
88

99
### Usage
1010

11-
This mod adds the ``/buildbug`` command and two hotkeys, the first hotkey (default ``U``) is used to quickly gather
11+
This mod adds the ``/buildbug`` command and three hotkeys, the first hotkey (default ``U``) is used to quickly gather
1212
information about your location.
1313
The second hotkey (default ``I``) is used to quickly generate a /bugreport.
14+
The third hotkey (default ``J``) is used to copy a fishing spot (including its perks) to the clipboard.
1415

1516
- ``/buildbug`` - Prints out location information, same as the hotkey.
1617
- ``/buildbug config clipboard <true/false>`` (default: ``false``) - If set to true, automatically copies

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yarn_mappings=1.21.1+build.3
77
loader_version=0.16.5
88
fabric_kotlin_version=1.11.0+kotlin.2.0.0
99
fabric_api_version=0.105.0+1.21.1
10-
mod_version=1.13
10+
mod_version=1.14.0
1111
noxesium_version=2.3.1
1212
adventure_version=5.14.1
1313
cloud_version=2.0.0-beta.7

src/main/kotlin/de/derniklaas/buildbugs/BugCreator.kt

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import de.derniklaas.buildbugs.utils.ServerState
55
import de.derniklaas.buildbugs.utils.Utils
66
import net.minecraft.client.MinecraftClient
77
import net.minecraft.client.util.Clipboard
8+
import net.minecraft.entity.decoration.DisplayEntity
89
import net.minecraft.util.math.BlockPos
10+
import net.minecraft.util.math.Box
911

1012
object BugCreator {
1113

@@ -43,17 +45,66 @@ object BugCreator {
4345
Utils.sendMiniMessage(
4446
"<click:copy_to_clipboard:'${
4547
discordMessage.replace(
46-
"'",
47-
"\\\'"
48+
"'", "\\\'"
4849
)
4950
}'>$minecraftMessage <yellow><bold>[CLICK TO COPY]</bold></yellow></click>", true
5051
)
5152

5253
if (BuildBugsClientEntrypoint.config.copyToClipboard) {
53-
setClipboard(client, discordMessage)
54+
setClipboard(discordMessage)
5455
}
5556
}
5657

58+
fun shareFishingSpot() {
59+
val client = MinecraftClient.getInstance()
60+
val server = client.currentServerEntry ?: return
61+
val player = client.player ?: return
62+
63+
// Check if the player is connected to a server
64+
if (server.isLocal) {
65+
Utils.sendErrorMessage("You are not connected to a server.")
66+
return
67+
}
68+
69+
// Check if the player is connected to a MCC related server
70+
if (!Utils.isOnMCCServer()) {
71+
Utils.sendErrorMessage("You are not connected to a MCC related server.")
72+
return
73+
}
74+
75+
// Get the "area" of the player
76+
val area = gameState.getFancyName()
77+
val blockPos = player.blockPos
78+
val map = gameState.mapName
79+
80+
val box = Box.of(blockPos.toCenterPos(), 12.0, 12.0, 12.0)
81+
val entities = player.world.getOtherEntities(null, box) { entity ->
82+
entity is DisplayEntity.TextDisplayEntity
83+
}
84+
85+
if (entities.isNotEmpty()) {
86+
val textDisplay = entities.first() as DisplayEntity.TextDisplayEntity
87+
val text = textDisplay.data!!.text.asTruncatedString(Int.MAX_VALUE)
88+
89+
val perks = text.split("\n").filter { it.contains("+") }.map { "+" + it.split("+")[1] }.joinToString(", ")
90+
if (perks.isNotEmpty()) {
91+
val minecraftMessage = getCopyMessage(area, map, blockPos).trim() + " $perks"
92+
Utils.sendMiniMessage(
93+
"<click:copy_to_clipboard:'${
94+
minecraftMessage.replace(
95+
"'", "\\\'"
96+
)
97+
}'>$minecraftMessage <yellow><bold>[CLICK TO COPY]</bold></yellow></click>", true
98+
)
99+
if (BuildBugsClientEntrypoint.config.copyToClipboard) {
100+
setClipboard(minecraftMessage)
101+
}
102+
return
103+
}
104+
}
105+
Utils.sendErrorMessage("Could not find a fishing spot.")
106+
}
107+
57108
/**
58109
* Updates [gameState] when a new packet is received.
59110
*/
@@ -88,8 +139,8 @@ object BugCreator {
88139
/**
89140
* Sets the content of the Clipboard to [text].
90141
*/
91-
fun setClipboard(client: MinecraftClient, text: String) {
92-
clipboard.setClipboard(client.window.handle, text)
142+
fun setClipboard(text: String) {
143+
clipboard.setClipboard(MinecraftClient.getInstance().window.handle, text)
93144
Utils.sendMiniMessage("<i>Copied </i>${if (BuildBugsClientEntrypoint.config.debugMode) "<green>${text.trim()}</green> " else ""}<i>to clipboard.</i>")
94145
}
95146

src/main/kotlin/de/derniklaas/buildbugs/BuildBugsClientEntrypoint.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ class BuildBugsClientEntrypoint : ClientModInitializer {
4040
)
4141
)
4242

43+
val shareFishingSpotKeybinding = KeyBindingHelper.registerKeyBinding(
44+
KeyBinding(
45+
"key.buildbugs.share_fishing_spot",
46+
InputUtil.Type.KEYSYM,
47+
GLFW.GLFW_KEY_J,
48+
"category.buildbugs"
49+
)
50+
)
51+
4352
ClientTickEvents.END_CLIENT_TICK.register {
4453
if (reportKeybinding.wasPressed()) {
4554
BugCreator.report()
4655
}
56+
if (shareFishingSpotKeybinding.wasPressed()) {
57+
BugCreator.shareFishingSpot()
58+
}
4759
if (bugreportKeybinding.wasPressed()) {
4860
if (!Utils.isOnMCCServer()) {
4961
Utils.sendErrorMessage("You are not connected to a MCC related server.")

src/main/kotlin/de/derniklaas/buildbugs/Constants.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ object Constants {
1212
const val ROCKET_SPLEEF_RUSH = "rocket-spleef"
1313
const val LIMBO = "limbo"
1414

15+
/* Fishing Islands & Grottos */
16+
const val VERDANT_WOODS = "temperate_1"
17+
const val FLORAL_FOREST = "temperate_2"
18+
const val DARK_GROVE = "temperate_3"
19+
const val SUNKEN_SWAMP = "temperate_grotto"
20+
21+
const val TROPICAL_OVERGROWTH = "tropical_1"
22+
const val CORAL_SHORES = "tropical_2"
23+
const val TWISTED_SWAMP = "tropical_3"
24+
const val MIRRORED_OASIS = "tropical_grotto"
25+
26+
const val ANCIENT_SANDS = "barren_1"
27+
const val BLAZING_CANYON = "barren_2"
28+
const val ASHEN_WASTES = "barren_3"
29+
const val VOLCANIC_SPRINGS = "barren_grotto"
30+
1531
/* Event Types */
1632
const val HUB = "hub"
1733
const val ACE_RACE = "ace-race"

src/main/kotlin/de/derniklaas/buildbugs/mixin/ChatMixin.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package de.derniklaas.buildbugs.mixin
33
import de.derniklaas.buildbugs.BugCreator
44
import de.derniklaas.buildbugs.Constants
55
import de.derniklaas.buildbugs.utils.Utils
6-
import net.minecraft.client.MinecraftClient
76
import net.minecraft.client.gui.hud.ChatHud
87
import net.minecraft.text.ClickEvent
98
import net.minecraft.text.Text
@@ -22,16 +21,15 @@ abstract class ChatMixin {
2221

2322
message.style.clickEvent?.let {
2423
if (it.action == ClickEvent.Action.COPY_TO_CLIPBOARD && it.value.startsWith(Constants.BUG_REPORT_URL)) {
25-
BugCreator.setClipboard(MinecraftClient.getInstance(), it.value)
24+
BugCreator.setClipboard(it.value)
2625
}
2726
}
2827
message.siblings.forEach {
2928
it.style.clickEvent?.let { event ->
3029
if (event.action == ClickEvent.Action.COPY_TO_CLIPBOARD && event.value.startsWith(Constants.BUG_REPORT_URL)) {
31-
BugCreator.setClipboard(MinecraftClient.getInstance(), event.value)
30+
BugCreator.setClipboard(event.value)
3231
}
3332
}
34-
3533
}
3634
}
3735
}

src/main/kotlin/de/derniklaas/buildbugs/mixin/InGameHudMixin.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package de.derniklaas.buildbugs.mixin
33
import de.derniklaas.buildbugs.BugCreator
44
import de.derniklaas.buildbugs.Constants
55
import de.derniklaas.buildbugs.utils.Utils
6-
import java.util.Optional
76
import net.minecraft.client.gui.hud.InGameHud
87
import net.minecraft.text.Text
98
import org.spongepowered.asm.mixin.Mixin
@@ -31,11 +30,11 @@ abstract class InGameHudMixin {
3130
// Only check titles in Parkour Warrior
3231
if (BugCreator.gameState.serverType != Constants.PARKOUR_WARRIOR) return
3332

34-
// Check if the first element matches the regex defined above
35-
val start = title.content.toString()
36-
if (!leapRegex.containsMatchIn(start)) return
33+
val courseTitle = title.asTruncatedString(Int.MAX_VALUE)
34+
if (!leapRegex.containsMatchIn(courseTitle)) return
3735

38-
val name = title.siblings.first().content.visit { Optional.of(it) }.get()
36+
// Extract the name from the title
37+
val name = courseTitle.split("] ")[1]
3938

4039
Utils.sendDebugMessage("Found course segment <green>$name</green>.")
4140
BugCreator.updateMap(name)

src/main/kotlin/de/derniklaas/buildbugs/utils/ServerState.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ data class ServerState(
2424
*/
2525
fun getFancyName(type: String = this.serverType): String = when (type) {
2626
Constants.LOBBY -> {
27-
if (subType == "main") "Main Lobby"
28-
else if (type == subType) "Lobby Lobby?"
29-
else "${getFancyName(subType)} Lobby"
27+
if(type == this.subType) "Lobby Lobby?"
28+
when(subType) {
29+
"main" -> "Main Lobby"
30+
Constants.VERDANT_WOODS -> "Verdant Woods"
31+
Constants.FLORAL_FOREST -> "Floral Forest"
32+
Constants.DARK_GROVE -> "Dark Grove"
33+
Constants.SUNKEN_SWAMP -> "Sunken Swamp"
34+
Constants.TROPICAL_OVERGROWTH -> "Tropical Overgrowth"
35+
Constants.CORAL_SHORES -> "Coral Shores"
36+
Constants.TWISTED_SWAMP -> "Twisted Swamp"
37+
Constants.MIRRORED_OASIS -> "Mirrored Oasis"
38+
Constants.ANCIENT_SANDS -> "Ancient Sands"
39+
Constants.BLAZING_CANYON -> "Blazing Canyon"
40+
Constants.ASHEN_WASTES -> "Ashen Wastes"
41+
Constants.VOLCANIC_SPRINGS -> "Volcanic Springs"
42+
else -> "${getFancyName(subType)} Lobby"
43+
}
3044
}
3145

3246
// Game modes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"key.buildbugs.report": "Generate a build bug report",
33
"key.buildbugs.bugreport": "Generate a /bugreport",
4-
"key.buildbugs.debug": "Toggle debug mode",
4+
"key.buildbugs.share_fishing_spot": "Share fishing spot",
55
"category.buildbugs": "#build-bugs"
66
}

0 commit comments

Comments
 (0)