Skip to content

Commit 61bda72

Browse files
committed
feat: implement configuration
1 parent 7570baa commit 61bda72

15 files changed

Lines changed: 285 additions & 52 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ loaderVersion = 0.13.3
99
fabricVersion = 0.42.0+1.16
1010
loomVersion = 0.7-SNAPSHOT
1111
# Mod Properties
12-
modVersion = 1.4.0-beta.1
12+
modVersion = 1.4.0
1313
mavenGroup = io.github.samarium150
1414
archivesBaseName = structures_compass
1515
# Kotlin

src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/StructuresCompass.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package io.github.samarium150.minecraft.mod.structures_compass
1818

19+
import io.github.samarium150.minecraft.mod.structures_compass.config.StructuresCompassConfig
1920
import io.github.samarium150.minecraft.mod.structures_compass.init.CommandRegistry
2021
import io.github.samarium150.minecraft.mod.structures_compass.init.ItemRegistry
2122
import io.github.samarium150.minecraft.mod.structures_compass.network.StructuresCompassServerNetwork
@@ -26,5 +27,6 @@ object StructuresCompass: ModInitializer {
2627
CommandRegistry.init()
2728
ItemRegistry.init()
2829
StructuresCompassServerNetwork.init()
30+
StructuresCompassConfig.load()
2931
}
3032
}

src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/gui/hud/StructuresCompassHud.kt

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ package io.github.samarium150.minecraft.mod.structures_compass.client.gui.hud
1919
import io.github.samarium150.minecraft.mod.structures_compass.client.util.drawConfiguredStringOnHud
2020
import io.github.samarium150.minecraft.mod.structures_compass.client.util.getLocalizedDimensionName
2121
import io.github.samarium150.minecraft.mod.structures_compass.client.util.getLocalizedStructureName
22+
import io.github.samarium150.minecraft.mod.structures_compass.config.ClientConfig
23+
import io.github.samarium150.minecraft.mod.structures_compass.config.StructuresCompassConfig
2224
import io.github.samarium150.minecraft.mod.structures_compass.init.ItemRegistry
2325
import io.github.samarium150.minecraft.mod.structures_compass.util.*
2426
import net.fabricmc.api.EnvType
2527
import net.fabricmc.api.Environment
2628
import net.minecraft.client.font.TextRenderer
29+
import net.minecraft.client.gui.screen.ChatScreen
2730
import net.minecraft.client.resource.language.I18n
2831
import net.minecraft.client.util.math.MatrixStack
2932

@@ -33,8 +36,12 @@ object StructuresCompassHud {
3336
private val textRenderer: TextRenderer
3437
get() = minecraftClient.textRenderer
3538

39+
private val config: ClientConfig
40+
get() = StructuresCompassConfig.configData.client
41+
3642
fun render(matrixStack: MatrixStack) {
37-
if (minecraftClient.currentScreen == null) {
43+
if (minecraftClient.currentScreen == null ||
44+
(config.displayWithChatOpen && minecraftClient.currentScreen is ChatScreen)) {
3845
val player = minecraftClient.player
3946
if (player != null) {
4047
val itemStack = if (player.mainHandStack.item == ItemRegistry.STRUCTURES_COMPASS) {
@@ -78,50 +85,53 @@ object StructuresCompassHud {
7885
)
7986
relLineOffset++
8087

81-
// TODO: Add if statement for checking information level
82-
textRenderer.drawConfiguredStringOnHud(
83-
matrixStack, I18n.translate("${prefix}hud_pos") +
84-
" [${position.x}, ${if (position.y == 0) "X" else "${position.y}"}, ${position.z}]",
85-
5, 5, 0x4AFF4A, ++relLineOffset
86-
)
88+
if (config.HudInfoLevel == 3)
89+
textRenderer.drawConfiguredStringOnHud(
90+
matrixStack, I18n.translate("${prefix}hud_pos") +
91+
" [${position.x}, ${if (position.y == 0) "X" else "${position.y}"}, ${position.z}]",
92+
5, 5, 0x4AFF4A, ++relLineOffset
93+
)
8794

8895
if (player.world.registryKey.value == dimension) {
8996
val distanceVector = position.getDistanceVector(player)
9097
val x = distanceVector.x
9198
val y = distanceVector.y
9299
val z = distanceVector.z
93100
val distance = distanceVector.getLength()
94-
if (x > 0.3)
95-
textRenderer.drawConfiguredStringOnHud(
96-
matrixStack, "${I18n.translate("${prefix}hud_east")} $x",
97-
5, 5, 0xFFFFFF, ++relLineOffset
98-
)
99-
else if (x < -0.3)
100-
textRenderer.drawConfiguredStringOnHud(
101-
matrixStack, "${I18n.translate("${prefix}hud_west")} ${-x}",
102-
5, 5, 0xFFFFFF, ++relLineOffset
103-
)
104-
if (z > 0.3)
105-
textRenderer.drawConfiguredStringOnHud(
106-
matrixStack, "${I18n.translate("${prefix}hud_south")} $z",
107-
5, 5, 0xFFFFFF, ++relLineOffset
108-
)
109-
else if (z < -0.3)
110-
textRenderer.drawConfiguredStringOnHud(
111-
matrixStack, "${I18n.translate("${prefix}hud_north")} ${-z}",
112-
5, 5, 0xFFFFFF, ++relLineOffset
113-
)
114-
if (y > 0.3)
115-
textRenderer.drawConfiguredStringOnHud(
116-
matrixStack, "${I18n.translate("${prefix}hud_up")} $y",
117-
5, 5, 0xFFFFFF, ++relLineOffset
118-
)
119-
else if (y < -0.3)
120-
textRenderer.drawConfiguredStringOnHud(
121-
matrixStack, "${I18n.translate("${prefix}hud_down")} ${-y}",
122-
5, 5, 0xFFFFFF, ++relLineOffset
123-
)
124-
if (relLineOffset > 6 || distance > 0.5) {
101+
if (config.HudInfoLevel == 3) {
102+
if (x > 0.3)
103+
textRenderer.drawConfiguredStringOnHud(
104+
matrixStack, "${I18n.translate("${prefix}hud_east")} $x",
105+
5, 5, 0xFFFFFF, ++relLineOffset
106+
)
107+
else if (x < -0.3)
108+
textRenderer.drawConfiguredStringOnHud(
109+
matrixStack, "${I18n.translate("${prefix}hud_west")} ${-x}",
110+
5, 5, 0xFFFFFF, ++relLineOffset
111+
)
112+
if (z > 0.3)
113+
textRenderer.drawConfiguredStringOnHud(
114+
matrixStack, "${I18n.translate("${prefix}hud_south")} $z",
115+
5, 5, 0xFFFFFF, ++relLineOffset
116+
)
117+
else if (z < -0.3)
118+
textRenderer.drawConfiguredStringOnHud(
119+
matrixStack, "${I18n.translate("${prefix}hud_north")} ${-z}",
120+
5, 5, 0xFFFFFF, ++relLineOffset
121+
)
122+
if (y > 0.3)
123+
textRenderer.drawConfiguredStringOnHud(
124+
matrixStack, "${I18n.translate("${prefix}hud_up")} $y",
125+
5, 5, 0xFFFFFF, ++relLineOffset
126+
)
127+
else if (y < -0.3)
128+
textRenderer.drawConfiguredStringOnHud(
129+
matrixStack, "${I18n.translate("${prefix}hud_down")} ${-y}",
130+
5, 5, 0xFFFFFF, ++relLineOffset
131+
)
132+
}
133+
if ((config.HudInfoLevel == 3 && relLineOffset > 6) ||
134+
(config.HudInfoLevel >= 3 && distance > config.closedEnough)) {
125135
relLineOffset++
126136
textRenderer.drawConfiguredStringOnHud(
127137
matrixStack, "${I18n.translate("${prefix}hud_distance")} %.3f".format(distance),

src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/util/IdentifierHelper.kt renamed to src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/util/LocalizationHelper.kt

File renamed without changes.

src/main/kotlin/io/github/samarium150/minecraft/mod/structures_compass/client/util/RenderHelper.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package io.github.samarium150.minecraft.mod.structures_compass.client.util
1818

1919
import com.mojang.blaze3d.platform.GlStateManager
2020
import com.mojang.blaze3d.systems.RenderSystem
21+
import io.github.samarium150.minecraft.mod.structures_compass.config.HudSide
22+
import io.github.samarium150.minecraft.mod.structures_compass.config.StructuresCompassConfig
2123
import io.github.samarium150.minecraft.mod.structures_compass.util.Rect
2224
import io.github.samarium150.minecraft.mod.structures_compass.util.minecraftClient
2325
import net.fabricmc.api.EnvType
@@ -34,24 +36,22 @@ fun TextRenderer.drawConfiguredStringOnHud(
3436
string: String, xOffset: Int, yOffset: Int,
3537
color: Int, relLineOffset: Int
3638
) {
37-
// TODO: replace 1 with StructuresCompassConfig.overlayLineOffset
38-
val configuredYOffset = yOffset + (relLineOffset + 1) * 9
39-
// TODO: replace ture with StructuresCompassConfig.hudPosition
40-
if (true)
39+
val clientConfig = StructuresCompassConfig.configData.client
40+
val configuredYOffset = yOffset + (relLineOffset + clientConfig.overlayLineOffset) * 9
41+
if (clientConfig.HudPosition == HudSide.RIGHT)
4142
draw(
4243
matrixStack,
4344
string,
44-
(xOffset + 7 - 5).toFloat(), // TODO: replace 7 with StructuresCompassConfig.xOffset
45-
(configuredYOffset + 16 - 14).toFloat(), // TODO: replace 16 with StructuresCompassConfig.yOffset
45+
(minecraftClient.window.scaledWidth - getWidth(string) - xOffset - clientConfig.xOffset + 5).toFloat(),
46+
(configuredYOffset + clientConfig.yOffset - 14).toFloat(),
4647
color
4748
)
4849
else
4950
draw(
5051
matrixStack,
5152
string,
52-
// TODO: replace 7 with StructuresCompassConfig.xOffset
53-
(minecraftClient.window.scaledWidth - getWidth(string) - xOffset - 7 + 5).toFloat(),
54-
(configuredYOffset + 0 - 14).toFloat(), // TODO: replace 0 with StructuresCompassConfig.yOffset
53+
(xOffset + clientConfig.xOffset - 5).toFloat(),
54+
(configuredYOffset + clientConfig.yOffset - 14).toFloat(),
5555
color
5656
)
5757
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2022 Samarium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
16+
*/
17+
package io.github.samarium150.minecraft.mod.structures_compass.config
18+
19+
data class ClientConfig(
20+
val HudInfoLevel: Int = 3,
21+
val HudPosition: HudSide = HudSide.LEFT,
22+
val displayWithChatOpen: Boolean = true,
23+
val xOffset: Int = 7,
24+
val yOffset: Int = 16,
25+
val overlayLineOffset: Int = 1,
26+
val closedEnough: Double = 0.3
27+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2022 Samarium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
16+
*/
17+
package io.github.samarium150.minecraft.mod.structures_compass.config
18+
19+
data class CommonConfig(
20+
val filterMode: FilterMode = FilterMode.BLACKLIST,
21+
val filterList: MutableList<String> = mutableListOf(),
22+
val maxDistance: Double = 5000.0,
23+
val radius: Int = 64,
24+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2022 Samarium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
16+
*/
17+
package io.github.samarium150.minecraft.mod.structures_compass.config
18+
19+
data class ConfigComments(
20+
val _filterMode: String = "The mode of the filter, either blacklist or whitelist, default is blacklist",
21+
val _filter: String = "A list of structures that the compass will not search in blacklist mode " +
22+
"or will only search in whitelist mode, specified by resource location, supporting regex",
23+
val _maxDistance: String = "The pseudo maximum searching radius. " +
24+
"If the distance to the structure exceeds this value, HUD would display 'Not Found'",
25+
val _radius: String = "The real maximum searching radius used by the underlying method (no idea how it works.)" +
26+
"If you still couldn't find a structure with a big enough MaxSearchRadius, increase this one." +
27+
"If you think searching makes the server slow, decrease this one.",
28+
val _HudInfoLevel: String = "HUD information detail level. 0: Nothing." +
29+
"1+: Structure and Dimension name." +
30+
"2+: Distance to the structure." +
31+
"3: Position of the structure and distance in x/y/z axis.",
32+
val _HudPosition: String = "The side of the information HUD. Either LEFT or RIGHT.",
33+
val _displayWithChatOpen: String = "Displays the compass information HUD even while chat is open.",
34+
val _xOffset: String = "The X offset for information rendered on the HUD. (default:7)",
35+
val _yOffset: String = "The Y offset for information rendered on the HUD. (default:16)",
36+
val _overlayLineOffset: String = "The line offset for information rendered on the HUD. (default:1)",
37+
val _closedEnough: String = "The X/Y/Z-distance won't be shown " +
38+
"if the distance is smaller than the value. (default:0.3)"
39+
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2022 Samarium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
16+
*/
17+
package io.github.samarium150.minecraft.mod.structures_compass.config
18+
19+
enum class FilterMode {
20+
BLACKLIST, WHITELIST
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2022 Samarium
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
16+
*/
17+
package io.github.samarium150.minecraft.mod.structures_compass.config
18+
19+
enum class HudSide {
20+
LEFT, RIGHT
21+
}

0 commit comments

Comments
 (0)