[*] Introduce Fabric helper and adjust a bunch of stuff
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package de.siphalor.tweed5.fabric.helper.testmod;
|
||||
|
||||
import de.siphalor.tweed5.attributesextension.api.serde.filter.AttributesReadWriteFilterExtension;
|
||||
import de.siphalor.tweed5.core.api.container.ConfigContainer;
|
||||
import de.siphalor.tweed5.data.hjson.HjsonSerde;
|
||||
import de.siphalor.tweed5.data.hjson.HjsonWriter;
|
||||
import de.siphalor.tweed5.fabric.helper.api.FabricConfigCommentLoader;
|
||||
import de.siphalor.tweed5.fabric.helper.api.FabricConfigContainerHelper;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.TweedPojoWeaverBootstrapper;
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
|
||||
@CommonsLog
|
||||
public class FabricHelperTestMod implements ModInitializer {
|
||||
public static final String MOD_ID = "tweed5_fabric_helper_testmod";
|
||||
|
||||
private TestModConfig config;
|
||||
private ConfigContainer<TestModConfig> configContainer;
|
||||
private FabricConfigContainerHelper<TestModConfig> configContainerHelper;
|
||||
private AttributesReadWriteFilterExtension configFilterExtension;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
configContainer = TweedPojoWeaverBootstrapper.create(TestModConfig.class).weave();
|
||||
configContainer.extension(AttributesReadWriteFilterExtension.class)
|
||||
.orElseThrow(() -> new IllegalStateException("AttributesReadWriteFilterExtension not found"))
|
||||
.markAttributeForFiltering("reload");
|
||||
configFilterExtension = configContainer.extension(AttributesReadWriteFilterExtension.class)
|
||||
.orElseThrow(() -> new IllegalStateException("AttributesReadWriteFilterExtension not found"));
|
||||
|
||||
configContainer.initialize();
|
||||
|
||||
configContainerHelper = FabricConfigContainerHelper.create(
|
||||
configContainer,
|
||||
new HjsonSerde(new HjsonWriter.Options()),
|
||||
MOD_ID
|
||||
);
|
||||
FabricConfigCommentLoader.builder()
|
||||
.configContainer(configContainer)
|
||||
.modId(MOD_ID)
|
||||
.prefix(MOD_ID + ".config")
|
||||
.build()
|
||||
.loadCommentsFromLanguageFile("en_us");
|
||||
|
||||
config = configContainerHelper.loadAndUpdateInConfigDirectory(TestModConfig::new);
|
||||
|
||||
log.info("Hello " + config.helloStart() + config.helloEnd());
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(_server -> onServerStarted());
|
||||
}
|
||||
|
||||
private void onServerStarted() {
|
||||
configContainerHelper.readPartialConfigInConfigDirectory(config, patchwork ->
|
||||
configFilterExtension.addFilter(patchwork, "scope", "game")
|
||||
);
|
||||
|
||||
log.info("Hello " + config.helloInGame() + config.helloEnd());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package de.siphalor.tweed5.fabric.helper.testmod;
|
||||
|
||||
import de.siphalor.tweed5.attributesextension.api.AttributesExtension;
|
||||
import de.siphalor.tweed5.attributesextension.api.serde.filter.AttributesReadWriteFilterExtension;
|
||||
import de.siphalor.tweed5.commentloaderextension.api.CommentLoaderExtension;
|
||||
import de.siphalor.tweed5.data.extension.api.ReadWriteExtension;
|
||||
import de.siphalor.tweed5.defaultextensions.patch.api.PatchExtension;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.CompoundWeaving;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.DefaultWeavingExtensions;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.PojoWeaving;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.annotation.PojoWeavingExtension;
|
||||
import de.siphalor.tweed5.weaver.pojoext.attributes.api.Attribute;
|
||||
import de.siphalor.tweed5.weaver.pojoext.attributes.api.AttributesPojoWeavingProcessor;
|
||||
import de.siphalor.tweed5.weaver.pojoext.serde.api.auto.AutoReadWritePojoWeavingProcessor;
|
||||
import de.siphalor.tweed5.weaver.pojoext.serde.api.auto.DefaultReadWriteMappings;
|
||||
import lombok.Data;
|
||||
|
||||
@PojoWeaving(extensions = {
|
||||
CommentLoaderExtension.class,
|
||||
ReadWriteExtension.class,
|
||||
PatchExtension.class,
|
||||
AttributesExtension.class,
|
||||
AttributesReadWriteFilterExtension.class,
|
||||
})
|
||||
@PojoWeavingExtension(AutoReadWritePojoWeavingProcessor.class)
|
||||
@PojoWeavingExtension(AttributesPojoWeavingProcessor.class)
|
||||
@DefaultWeavingExtensions
|
||||
@DefaultReadWriteMappings
|
||||
@CompoundWeaving(namingFormat = "kebab_case")
|
||||
@Data
|
||||
public class TestModConfig {
|
||||
private String helloStart = "Minecraft";
|
||||
@Attribute(key = "scope", values = "game")
|
||||
private String helloInGame = "Game";
|
||||
private String helloEnd = "!";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"tweed5_fabric_helper_testmod.config.hello-start": "Whom to greet when the game starts",
|
||||
"tweed5_fabric_helper_testmod.config.hello-in-game": "Whom to greet when the player joins a game"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "tweed5_fabric_helper_testmod",
|
||||
"version": "0.1.0",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"de.siphalor.tweed5.fabric.helper.testmod.FabricHelperTestMod"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user