Skip to content

Commit

Permalink
Getting config working
Browse files Browse the repository at this point in the history
  • Loading branch information
jiink committed May 12, 2024
1 parent 5ca852f commit df333ac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ base {
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { // to use YetAnotherConfigLib
name 'Xander Maven'
url 'https://maven.isxander.dev/releases'
}
}

loom {
Expand All @@ -38,7 +37,9 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"


// To make making a config easier
modImplementation 'dev.isxander:yet-another-config-lib:3.4.2+1.20.4-fabric'
}

processResources {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jiink/smeltinginapinch/SmeltingInAPinch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jiink.smeltinginapinch;

import jiink.smeltinginapinch.config.MyConfig;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
Expand Down Expand Up @@ -178,11 +179,10 @@ public class SmeltingInAPinch implements ModInitializer {

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
MyConfig.HANDLER.load();

LOGGER.info("Getting ready to smelt!");
LOGGER.info(">>>> myCoolString: %s{}", MyConfig.HANDLER.instance().myCoolString);
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> {
content.addAfter(Items.BLAST_FURNACE, GUNPOWDER_FURANCE_BLOCK_ITEM);
content.addAfter(Items.BLAST_FURNACE, LAVA_FURANCE_BLOCK_ITEM);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/jiink/smeltinginapinch/config/MyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package jiink.smeltinginapinch.config;

import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import net.fabricmc.loader.api.FabricLoader;

import static jiink.smeltinginapinch.SmeltingInAPinch.MOD_ID;

public class MyConfig {
public static ConfigClassHandler<MyConfig> HANDLER = ConfigClassHandler.createBuilder(MyConfig.class)
//.id(new ResourceLocation(MOD_ID, "my_config"))
.serializer(config -> GsonConfigSerializerBuilder.create(config)
.setPath(FabricLoader.getInstance().getConfigDir().resolve("smeltinginapinch.json"))
// .appendGsonBuilder(GsonBuilder::setPrettyPrint) // not needed, pretty print by default
// .setJson5(true)
.build())
.build();

@SerialEntry
public boolean myCoolBoolean = true;

@SerialEntry
public int myCoolInteger = 5;

@SerialEntry(comment = "This string is amazing")
public String myCoolString = "How amazing!";

}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"fabricloader": ">=0.15.9",
"minecraft": "~1.20.4",
"java": ">=17",
"fabric-api": "*"
"fabric-api": "*",
"yet_another_config_lib_v3": "*"
},
"suggests": {
"another-mod": "*"
Expand Down

0 comments on commit df333ac

Please sign in to comment.