diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index b96907658..6744fad88 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -8,7 +8,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -87,6 +89,8 @@ public final class OverdriveThatMatters { modBus.addListener(EventPriority.HIGHEST, this::setup); modBus.addListener(EventPriority.NORMAL, this::setupClient); modBus.addListener(EventPriority.NORMAL, MatteryCapability::register); + + ClientConfig.INSTANCE.register(); } private void setup(final FMLCommonSetupEvent event) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/MConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/MConfig.kt new file mode 100644 index 000000000..9ad0783e3 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/MConfig.kt @@ -0,0 +1,45 @@ + +@file:Suppress("ObjectPropertyName") + +package ru.dbotthepony.mc.otm + +import net.minecraftforge.common.ForgeConfigSpec +import net.minecraftforge.common.ForgeConfigSpec.IntValue +import net.minecraftforge.fml.ModLoadingContext +import net.minecraftforge.fml.config.ModConfig +import kotlin.reflect.KProperty + +object ClientConfig { + private val spec: ForgeConfigSpec + private var registered = false + + private val _exosuitInventoryRows: IntValue + + init { + val specBuilder = ForgeConfigSpec.Builder() + specBuilder.comment("Clientside Config").push("client") + + _exosuitInventoryRows = specBuilder + .comment("Amount of inventory rows to show when wearing Exosuit") + .defineInRange("exosuitInventoryRows", 3, 3, 6) + + specBuilder.pop() + spec = specBuilder.build() + } + + var exosuitInventoryRows: Int by _exosuitInventoryRows + + fun register() { + check(!registered) { "Already registered config" } + registered = true + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, spec) + } +} + +private operator fun ForgeConfigSpec.ConfigValue.setValue(config: ClientConfig, property: KProperty<*>, value: T) { + set(value) +} + +private operator fun ForgeConfigSpec.ConfigValue.getValue(config: Any, property: KProperty<*>): T { + return get() +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt index e723ad13e..85b4fdd3d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/screen/MatteryScreen.kt @@ -16,6 +16,7 @@ import net.minecraftforge.client.event.ContainerScreenEvent.Render.Foreground import net.minecraftforge.common.MinecraftForge import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL13 +import ru.dbotthepony.mc.otm.ClientConfig import ru.dbotthepony.mc.otm.client.moveMousePosScaled import ru.dbotthepony.mc.otm.client.screen.panels.* import ru.dbotthepony.mc.otm.core.maxScrollDivision @@ -552,6 +553,6 @@ abstract class MatteryScreen(menu: T, inventory: Inventory, tit const val MAX_ROWS = 6 var lastScroll = 0 - var lastRows = 3 + var lastRows by ClientConfig::exosuitInventoryRows } -} \ No newline at end of file +}