Jump to content

Config File Conventions for 1.16.X or latest versions


Cryoexn

Recommended Posts

Hello Forge Community,

I am relatively new to modding so please be patient, also I apologize if I make beginner mistakes. Currently I'm re-writing a 1.8.9 HUD mod that would display various text and items to the screen. When I wrote the original mod I didn't follow config file conventions, because I was more focused on making my first mod. But now I would like to understand the convention and the correct way of using ".cfg" files. I have been googling to see if others have any tutorials, or have asked on the forums about config files but I cant find any up to date resources (I'm not sure what the latest config convention is).

My Goal:

What I am trying to accomplish is, be able to read in values from a config file such as (int x, int y, boolean enabled, String name, int color) for different HUD sub-mods. Then update them via chat commands and save them to the config file again. I am willing to write this mod in 1.16.x if the config implementation has been upgraded since 1.12.2 and would appreciate any information/tutorials for doing so.

Steps I've Taken:

I began with the Forge Documentation but was unable to see any information of config files for 1.16.x , I might have been just looking in the wrong place.

I did look back at the 1.12.x Documentation and found config annotations. (I also followed the link to the annotation testing GitHub repo)

When I made an attempt to implement these I was able to create a "ModConfig.java" that created a ".cfg" file that was correctly structured for how it was defined, but I was unable to update the values and save them to the config file when running the mod. I was using `ConfigManager.sync(MODID, Type.INSTANCE)` to attempt to write the updated values to the file but It would overwrite the values in the code before saving, I think this is due to me modifying it by just setting the fields and not using GUI but I'm not sure. 

I appreciate any and all help on this topic and if you require more information I can provide it. Thank you in advance for your time!

Files:

Here is the mod entry point file ->"CryoHudMod.java", and my config annotated file -> "ModConfig.java", and the generated "cryo-hud-mod.cfg".

Spoiler


package com.cryoexn.hudmod.util;

import com.cryoexn.hudmod.CryoHudMod;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Config(modid= CryoHudMod.MODID, type=Config.Type.INSTANCE, category="sub-mods")
public class ModConfig {

    private static final int DEFAULT_FG = 0xffffffff;
    private static final int DEFAULT_BG = 0x4f000000;

    public static SubModConfig fpsConf = new SubModConfig(false, new Position(10, 10),"fps", DEFAULT_FG, DEFAULT_BG);;
    public static SubModConfig memConf = new SubModConfig(true, new Position(0, 0),"mem", DEFAULT_FG, DEFAULT_BG);;

    public static class SubModConfig {

        public boolean isEnabled;
        public ModConfig.PositionConfig pos;
        public String name;

        @Config.Name("foreground-color")
        public int fgColor;

        @Config.Name("background-color")
        public int bgColor;

        public SubModConfig(boolean isEnabled, Position pos, String name, int fgColor, int bgColor) {
            this.isEnabled = isEnabled;
            this.pos = new ModConfig.PositionConfig(pos);
            this.name = name;
            this.fgColor = fgColor;
            this.bgColor = bgColor;
        } // end Constructor.

    } // end FpsConfig.

    public static class PositionConfig {
        public int x;
        public int y;

        public PositionConfig(Position pos) {
            this.x = pos.getXpos();
            this.y = pos.getYpos();
        } // end Default Constructor.

    } // end PositionConfig.

    @Mod.EventBusSubscriber(modid=CryoHudMod.MODID)
    private static class EventHandler {

        /**
         * Inject the new values and save to the config file when the config has been changed from the GUI.
         *
         * @param event The event
         */
        @SubscribeEvent
        public static void onConfigChanged(final ConfigChangedEvent.OnConfigChangedEvent event) {
            if (event.getModID().equals(CryoHudMod.MODID)) {
                ConfigManager.sync(CryoHudMod.MODID, Config.Type.INSTANCE);
            }
        }

    } // end EventHandler.

} //end ModConfig.

 

Spoiler



package com.cryoexn.hudmod;

import com.cryoexn.hudmod.commands.CommandHud;
import com.cryoexn.hudmod.submods.fps.ModFpsCounter;
import com.cryoexn.hudmod.util.ModConfig;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import com.cryoexn.hudmod.commands.CommandAbstract;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;

/**
 * Mod for HUD
 *
 * experimenting and learning coding practices and interfacing with existing libraries.
 */
@Mod(modid = CryoHudMod.MODID, name = CryoHudMod.NAME, version = CryoHudMod.VERSION)
public class CryoHudMod {

    public static final String MODID = "cryo-hud-mod";
    public static final String NAME = "Cryo-Hud-Mod";
    public static final String VERSION = "1.0.0";

    private static Logger logger;
    public static ModFpsCounter fpsCounter;

    /**
     * Initialize all event, and command handlers.
     *
     * @param event Initialization event.
     */
    @EventHandler
    public void init(FMLInitializationEvent event) {
        logger.debug("Old: {}", ModConfig.fpsConf.isEnabled);
        ModConfig.fpsConf.isEnabled = !ModConfig.fpsConf.isEnabled;
        logger.debug("New: {}", ModConfig.fpsConf.isEnabled);

        fpsCounter = new ModFpsCounter();
        // EventHandlers are auto registered.
        // Register CommandHandler(s).
        this.registerCommands(new CommandHud());

    } // end init.

    @EventHandler
    public void serverStopping(FMLServerStoppingEvent event) {
        ModConfig.fpsConf = fpsCounter.getValues();
    } // end serverStopping.

    /**
     * Register all commands with the Forge ClientCommandHandler.
     *
     * @param commands Command handlers to register.
     */
    private void registerCommands(Object... commands) {

        Arrays.asList(commands).forEach((command) -> {
            ClientCommandHandler.instance.registerCommand((CommandAbstract)command);
        });

    } // end registerCommands.

} // end CryoHudMod.

 

Spoiler



# Configuration file

sub-mods {

    fpsconf {
        I:background-color=1325400064
        I:foreground-color=-1
        B:isEnabled=false
        S:name=fps

        pos {
            I:x=10
            I:y=10
        }

    }

    memconf {
        I:background-color=1325400064
        I:foreground-color=-1
        B:isEnabled=true
        S:name=mem

        pos {
            I:x=0
            I:y=0
        }

    }

}


 

 

Edited by Cryoexn
Syntax Highlighting was off for a code block.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Here's the link: https://mclo.gs/7L5FibL Here's the link: https://mclo.gs/7L5FibL
    • Also the mod "Connector Extras" modifies Reach-entity-attributes and can cause fatal errors when combined with ValkrienSkies mod. Disable this mod and continue to use Syntra without it.
    • Hi everyone. I was trying modify the vanilla loot of the "short_grass" block, I would like it drops seeds and vegetal fiber (new item of my mod), but I don't found any guide or tutorial on internet. Somebody can help me?
    • On 1.20.1 use ValkrienSkies mod version 2.3.0 Beta 1. I had the same issues as you and it turns out the newer beta versions have tons of unresolved incompatibilities. If you change the version you will not be required to change the versions of eureka or any other additions unless prompted at startup. This will resolve Reach-entity-attributes error sound related error and cowardly errors.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.