Skip to content

Commit 66673d4

Browse files
committed
feat: config
1 parent 9700a16 commit 66673d4

File tree

9 files changed

+55
-17
lines changed

9 files changed

+55
-17
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ sourceSets {
4747
}
4848

4949
repositories {
50+
maven { url "https://maven.shedaniel.me/" }
51+
maven { url "https://maven.terraformersmc.com/releases/" }
5052
maven {
5153
url "https://squiddev.cc/maven/"
5254
content {
@@ -62,6 +64,10 @@ dependencies {
6264
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
6365
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
6466

67+
modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") {
68+
exclude(group: "net.fabricmc.fabric-api")
69+
}
70+
6571
// Fabric API. This is technically optional, but you probably want it anyway.
6672
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
6773
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}"

gradle.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ org.gradle.parallel=true
66
# check these on https://fabricmc.net/develop
77
minecraft_version=1.20.1
88
yarn_mappings=1.20.1+build.10
9-
loader_version=0.16.7
9+
loader_version=0.14.22
1010
fabric_kotlin_version=1.10.8+kotlin.1.9.0
1111

1212
# Mod Properties
@@ -16,4 +16,5 @@ archives_base_name=roadworks
1616

1717
# Dependencies
1818
fabric_version=0.87.0+1.20.1
19-
cct_version=1.107.0
19+
cct_version=1.107.0
20+
cloth_config_version = 11.1.136

src/client/kotlin/me/znepb/roadworks/RoadworksClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object RoadworksClient : ClientModInitializer {
2121

2222
override fun onInitializeClient() {
2323
logger.info("Roadworks Client Init")
24-
ModelLoadingPlugin.register( me.znepb.roadworks.ModelLoader())
24+
ModelLoadingPlugin.register( me.znepb.roadworks.ModelLoader() )
2525

2626
// Item Groups
2727
ItemGroupEvents.modifyEntriesEvent(Registry.itemGroup).register {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package me.znepb.roadworks
2+
3+
import me.shedaniel.autoconfig.ConfigData
4+
import me.shedaniel.autoconfig.annotation.Config
5+
import me.shedaniel.autoconfig.annotation.ConfigEntry
6+
7+
@Config(name = "roadworks")
8+
class Config : ConfigData {
9+
@ConfigEntry.Gui.CollapsibleObject
10+
var trafficCabinet = TrafficCabinetConfiguration()
11+
12+
class TrafficCabinetConfiguration {
13+
var maxDevices: Int = 24
14+
var maxLinkDistance: Double = 48.0
15+
}
16+
}

src/main/kotlin/me/znepb/roadworks/RoadworksMain.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package me.znepb.roadworks
33
import com.google.gson.JsonParser
44
import com.mojang.serialization.JsonOps
55
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
6+
import me.shedaniel.autoconfig.AutoConfig
7+
import me.shedaniel.autoconfig.ConfigHolder
8+
import me.shedaniel.autoconfig.serializer.ConfigSerializer
9+
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer
610
import me.znepb.roadworks.block.Linkable
711
import me.znepb.roadworks.block.cabinet.TrafficCabinetBlockEntity
812
import me.znepb.roadworks.block.sign.SignType
@@ -27,6 +31,7 @@ object RoadworksMain : ModInitializer {
2731
val logger = LoggerFactory.getLogger(NAMESPACE)
2832

2933
val SIGN_TYPES = Object2ObjectOpenHashMap<Identifier, SignType>()
34+
var CONFIG: Config? = null
3035

3136
fun ModId(id: String): Identifier {
3237
return Identifier(NAMESPACE, id)
@@ -35,8 +40,11 @@ object RoadworksMain : ModInitializer {
3540
override fun onInitialize() {
3641
logger.info("Roadworks is initalizing")
3742

43+
AutoConfig.register(Config::class.java, ::Toml4jConfigSerializer)
3844
Registry.init()
3945

46+
CONFIG = AutoConfig.getConfigHolder(Config::class.java).config
47+
4048
PlayerBlockBreakEvents.BEFORE.register { world: World, player: PlayerEntity, pos: BlockPos, state: BlockState, blockEntity: BlockEntity? ->
4149
if (blockEntity is Linkable) {
4250
blockEntity.remove()

src/main/kotlin/me/znepb/roadworks/item/Linker.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.znepb.roadworks.item
22

33
import me.znepb.roadworks.Registry
4+
import me.znepb.roadworks.RoadworksMain
45
import me.znepb.roadworks.block.Linkable
56
import me.znepb.roadworks.block.cabinet.TrafficCabinetBlockEntity
67
import net.minecraft.block.entity.BlockEntity
@@ -20,11 +21,6 @@ class Linker(settings: Settings) : Item(settings) {
2021
var linking: BlockPos? = null
2122
var linkingWith: BlockEntityType<*>? = null
2223

23-
companion object {
24-
const val MAX_DEVICES = 24
25-
val MAX_DEVICE_DISTANCE = 48.0
26-
}
27-
2824
private fun getCabinet(blockEntity: Linkable, context: ItemUsageContext): TrafficCabinetBlockEntity? {
2925
val be = context.world?.getBlockEntity(blockEntity.getLinkPos())
3026
return if(be is TrafficCabinetBlockEntity) { be } else null
@@ -61,9 +57,9 @@ class Linker(settings: Settings) : Item(settings) {
6157
}
6258

6359
private fun linkCabinet(cabinet: TrafficCabinetBlockEntity, context: ItemUsageContext): ActionResult {
64-
if(cabinet.getTotalDevices() > MAX_DEVICES) {
60+
if(cabinet.getTotalDevices() > RoadworksMain.CONFIG!!.trafficCabinet.maxDevices) {
6561
// Too many devices connected to this box!
66-
context.player?.sendMessage(Text.literal("There are too many devices connected to this box! Max is $MAX_DEVICES"), true)
62+
context.player?.sendMessage(Text.literal("There are too many devices connected to this box! Max is ${RoadworksMain.CONFIG!!.trafficCabinet.maxDevices}"), true)
6763
return ActionResult.SUCCESS
6864
}
6965

@@ -83,9 +79,9 @@ class Linker(settings: Settings) : Item(settings) {
8379
return
8480
}
8581

86-
if(!linkedFrom.pos.isWithinDistance(block.pos, MAX_DEVICE_DISTANCE)) {
82+
if(!linkedFrom.pos.isWithinDistance(block.pos, RoadworksMain.CONFIG!!.trafficCabinet.maxLinkDistance)) {
8783
// Device is too far!
88-
context.player?.sendMessage(Text.literal("This device is too far! Max distance is $MAX_DEVICE_DISTANCE blocks"), true)
84+
context.player?.sendMessage(Text.literal("This device is too far! Max distance is ${RoadworksMain.CONFIG!!.trafficCabinet.maxLinkDistance} blocks"), true)
8985
return
9086
}
9187

@@ -133,9 +129,9 @@ class Linker(settings: Settings) : Item(settings) {
133129
return
134130
}
135131

136-
if(cabinet.getTotalDevices() >= MAX_DEVICES) {
132+
if(cabinet.getTotalDevices() >= RoadworksMain.CONFIG!!.trafficCabinet.maxDevices) {
137133
// Too many devices connected to this box!
138-
context.player?.sendMessage(Text.literal("There are too many devices connected to this box! Max is $MAX_DEVICES"), true)
134+
context.player?.sendMessage(Text.literal("There are too many devices connected to this box! Max is ${RoadworksMain.CONFIG!!.trafficCabinet.maxDevices}"), true)
139135
return
140136
}
141137

@@ -147,9 +143,9 @@ class Linker(settings: Settings) : Item(settings) {
147143
return
148144
}
149145

150-
if(!linkedFrom.pos.isWithinDistance(cabinet.pos, MAX_DEVICE_DISTANCE)) {
146+
if(!linkedFrom.pos.isWithinDistance(cabinet.pos, RoadworksMain.CONFIG!!.trafficCabinet.maxLinkDistance)) {
151147
// Device is too far!
152-
context.player?.sendMessage(Text.literal("This device is too far! Max distance is $MAX_DEVICE_DISTANCE blocks"), true)
148+
context.player?.sendMessage(Text.literal("This device is too far! Max distance is ${RoadworksMain.CONFIG!!.trafficCabinet.maxLinkDistance} blocks"), true)
153149
return
154150
}
155151

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"variants": {
3+
"": {
4+
"model": "roadworks:block/sign"
5+
}
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"parent": "roadworks:block/sign"
3+
}

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"minecraft": "~1.20.1",
4343
"java": ">=17",
4444
"fabric-api": "*",
45-
"fabric-language-kotlin": ">=1.9.0"
45+
"fabric-language-kotlin": ">=1.9.0",
46+
"cloth-config": ">=11.1.136"
4647
}
4748
}

0 commit comments

Comments
 (0)