Skip to content

Commit

Permalink
Add mod menu support for config and implement #3 as a toggleable option
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru21 committed Jun 11, 2023
1 parent 894e413 commit 1bfd0bd
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 27 deletions.
9 changes: 5 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ group = mavenGroup
repositories {
mavenCentral()
maven("https://maven.shedaniel.me/")
maven("https://maven.terraformersmc.com/releases/")
}
dependencies {
val minecraftVersion: String by project
Expand All @@ -33,11 +34,11 @@ dependencies {
val fabricKotlinVersion: String by project
modImplementation("net.fabricmc:fabric-language-kotlin:$fabricKotlinVersion")
val clothConfigVersion: String by project
modApi("me.shedaniel.cloth:cloth-config-fabric:$clothConfigVersion") {
exclude("net.fabricmc.fabric-api")
}
modApi("me.shedaniel.cloth:cloth-config-fabric:$clothConfigVersion")
val modMenuVersion: String by project
modApi("com.terraformersmc:modmenu:$modMenuVersion")

modImplementation("blue.endless:jankson:1.2.1")
modImplementation("blue.endless:jankson:1.2.2")
}
tasks {
val javaVersion = JavaVersion.VERSION_17
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ archivesBaseName = waxednotwaxed
systemProp.kotlinVersion = 1.6.10
fabricKotlinVersion = 1.8.7+kotlin.1.7.22

clothConfigVersion = 11.0.99
clothConfigVersion = 11.0.99
modMenuVersion = 7.0.1
9 changes: 0 additions & 9 deletions src/main/kotlin/me/iru/waxednotwaxed/ToggleConfig.kt

This file was deleted.

13 changes: 5 additions & 8 deletions src/main/kotlin/me/iru/waxednotwaxed/WaxedNotWaxed.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.iru.waxednotwaxed

import me.iru.waxednotwaxed.config.WaxedNotWaxedConfig
import me.iru.waxednotwaxed.events.EndClientTickHandler
import me.iru.waxednotwaxed.events.HudRenderHandler
import me.shedaniel.autoconfig.AutoConfig
import me.shedaniel.autoconfig.ConfigHolder
import me.shedaniel.autoconfig.annotation.Config
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer
import net.fabricmc.api.ClientModInitializer
Expand All @@ -14,24 +14,21 @@ import net.minecraft.client.option.KeyBinding
import net.minecraft.client.util.InputUtil
import org.lwjgl.glfw.GLFW


object WaxedNotWaxed : ClientModInitializer {

var keyBinding: KeyBinding? = null
var config: ConfigHolder<ToggleConfig>? = null
var toggledCached: Boolean = false
lateinit var config: WaxedNotWaxedConfig

override fun onInitializeClient() {
AutoConfig.register(
ToggleConfig::class.java
) { definition: Config?, configClass: Class<ToggleConfig?>? ->
WaxedNotWaxedConfig::class.java
) { definition: Config?, configClass: Class<WaxedNotWaxedConfig?>? ->
JanksonConfigSerializer(
definition,
configClass
)
}
this.config = AutoConfig.getConfigHolder(ToggleConfig::class.java)
this.toggledCached = this.config!!.get().toggled
this.config = AutoConfig.getConfigHolder(WaxedNotWaxedConfig::class.java).get()

this.keyBinding = KeyBindingHelper.registerKeyBinding(
KeyBinding(
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/me/iru/waxednotwaxed/config/ModMenuIntegration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.iru.waxednotwaxed.config

import com.terraformersmc.modmenu.api.ConfigScreenFactory
import com.terraformersmc.modmenu.api.ModMenuApi
import me.shedaniel.autoconfig.AutoConfig
import net.minecraft.client.gui.screen.Screen

class ModMenuIntegration: ModMenuApi {
override fun getModConfigScreenFactory(): ConfigScreenFactory<*> {
return ConfigScreenFactory { parent: Screen? ->
AutoConfig.getConfigScreen(
WaxedNotWaxedConfig::class.java, parent
).get()
}
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/me/iru/waxednotwaxed/config/WaxedNotWaxedConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.iru.waxednotwaxed.config

import me.shedaniel.autoconfig.AutoConfig
import me.shedaniel.autoconfig.ConfigData
import me.shedaniel.autoconfig.annotation.Config

@Config(name = "waxednotwaxed")
class WaxedNotWaxedConfig : ConfigData {
var enabled: Boolean = false
var onlyShowWhenHoldingAxe: Boolean = false

fun save() {
AutoConfig.getConfigHolder(this::class.java).save()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import net.minecraft.sound.SoundEvents
fun EndClientTickHandler(): ClientTickEvents.EndTick {
return ClientTickEvents.EndTick {
while(WaxedNotWaxed.keyBinding!!.wasPressed()) {
val newValue = !WaxedNotWaxed.toggledCached
WaxedNotWaxed.toggledCached = newValue
WaxedNotWaxed.config!!.config.toggled = newValue
WaxedNotWaxed.config!!.save()
val newValue = !WaxedNotWaxed.config.enabled
WaxedNotWaxed.config.enabled = newValue
WaxedNotWaxed.config.save()
val mc = MinecraftClient.getInstance()
val p = mc.player!!
mc.world!!.playSound(p, p.blockPos, SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.1f, 1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ import net.minecraft.block.OxidizableSlabBlock
import net.minecraft.block.OxidizableStairsBlock
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawContext
import net.minecraft.item.AxeItem
import net.minecraft.util.Identifier

class HudRenderHandler : HudRenderCallback {

override fun onHudRender(drawContext: DrawContext?, tickDelta: Float) {
if(drawContext == null || !WaxedNotWaxed.toggledCached) return
if(drawContext == null ||
!WaxedNotWaxed.config.enabled ||
(WaxedNotWaxed.config.onlyShowWhenHoldingAxe && MinecraftClient.getInstance().player!!.mainHandStack.item !is AxeItem)
) return
val lookingAt = Utils.getBlockAtCrosshair() ?: return
if (lookingAt.name.toString().lowercase().contains("waxed")) render(drawContext, true)
else if(lookingAt is OxidizableBlock || lookingAt is OxidizableSlabBlock || lookingAt is OxidizableStairsBlock) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/waxednotwaxed/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"text.autoconfig.waxednotwaxed.title": "Waxed Not Waxed Config",
"text.autoconfig.waxednotwaxed.option.enabled": "Enabled",
"text.autoconfig.waxednotwaxed.option.onlyShowWhenHoldingAxe": "Only show when holding an axe",
"key.waxednotwaxed.toggle": "Toggle Indicator",
"category.waxednotwaxed.keybindcategory": "Waxed Not Waxed"
}
10 changes: 10 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"adapter": "kotlin",
"value": "me.iru.waxednotwaxed.WaxedNotWaxed"
}
],
"modmenu": [
"me.iru.waxednotwaxed.config.ModMenuIntegration"
]
},
"depends": {
Expand All @@ -29,5 +32,12 @@
"fabric-language-kotlin": ">=1.8.7+kotlin.1.7.22",
"minecraft": ">=1.20",
"java": ">=17"
},
"custom": {
"modmenu": {
"links": {
"modmenu.discord": "https://discord.gg/jrebrmDD5X"
}
}
}
}

0 comments on commit 1bfd0bd

Please sign in to comment.