Jump to content

[1.14.4] Testing ForgeConfigSpec.BooleanValue in code


kwpugh

Recommended Posts

Hi All,

 

I'm looking for some guidance on how to test if ForgeConfigSpec.BooleanValue equals true in my item register class.  

 

I have setup an item value in my general mod config builder (e.g. SNIPER_SWORD):

package com.kwpugh.gobber2.world;

import net.minecraftforge.common.ForgeConfigSpec;

public class GeneralModConfig
{
    public static ForgeConfigSpec.BooleanValue GOBBER2_ORE_GENERATION;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_CHANCE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_SIZE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_MIN_HEIGHT;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_MAX_HEIGHT;

    public static ForgeConfigSpec.BooleanValue GOBBER2_LUCKY_BLOCK_GENERATION;
    public static ForgeConfigSpec.IntValue GOBBER2_LUCKY_BLOCK_CHANCE;
    public static ForgeConfigSpec.IntValue GOBBER2_LUCKY_BLOCK_SIZE;
    public static ForgeConfigSpec.IntValue GOBBER2_LUCKY_BLOCK_MIN_HEIGHT;
    public static ForgeConfigSpec.IntValue GOBBER2_LUCKY_BLOCK_MAX_HEIGHT;

    public static ForgeConfigSpec.BooleanValue GOBBER2_ORE_NETHER_GENERATION;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_NETHER_CHANCE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_NETHER_SIZE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_NETHER_MIN_HEIGHT;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_NETHER_MAX_HEIGHT;
    
    public static ForgeConfigSpec.BooleanValue GOBBER2_ORE_END_GENERATION;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_END_CHANCE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_END_SIZE;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_END_MIN_HEIGHT;
    public static ForgeConfigSpec.IntValue GOBBER2_ORE_END_MAX_HEIGHT;
    
    public static ForgeConfigSpec.BooleanValue SNIPER_SWORD;
    
    public static void init(ForgeConfigSpec.Builder SERVER_BUILDER)
    {
        SERVER_BUILDER.comment("Gobber Ore Generation").push("gobber2_ore");

        GOBBER2_ORE_GENERATION = SERVER_BUILDER.comment("Generate Gobber Ore in the world [true / false]").define("gobberOreGeneration", true);
        GOBBER2_ORE_SIZE = SERVER_BUILDER.comment("Size of Gobber Ore pockets [0-100, default: 3]").defineInRange("gobberOreSize", 3, 0, 100);
        GOBBER2_ORE_CHANCE = SERVER_BUILDER.comment("Chances of Gobber Ore pocket being generated [0-100, default: 10]").defineInRange("gobberOreChance", 10, 0, 100);
        GOBBER2_ORE_MIN_HEIGHT = SERVER_BUILDER.comment("Minimal height for Gobber Ore pocket generation, [0-255, default: 20]").defineInRange("gobberOReMinHeight", 20, 0, 255);
        GOBBER2_ORE_MAX_HEIGHT = SERVER_BUILDER.comment("Maximal height for Gobber Ore pocket generation [0-255, default: 30]").defineInRange("gobberOreMaxHeight", 30, 0, 255);

        SERVER_BUILDER.pop();
        
        
        SERVER_BUILDER.comment("Gobber Lucky Block Generation").push("gobber2_lucky_block");

        GOBBER2_LUCKY_BLOCK_GENERATION = SERVER_BUILDER.comment("Generate Gobber Lucky Block in the world [true / false]").define("gobberLuckyBlockGeneration", true);
        GOBBER2_LUCKY_BLOCK_SIZE = SERVER_BUILDER.comment("Size of Gobber Lucky Block pockets [0-100, default: 3]").defineInRange("gobberLuckyBlockSize", 3, 0, 100);
        GOBBER2_LUCKY_BLOCK_CHANCE = SERVER_BUILDER.comment("Chances of Gobber Lucky Block pocket being generated [0-100, default: 20]").defineInRange("gobberLuckyBlockChance", 20, 0, 100);
        GOBBER2_LUCKY_BLOCK_MIN_HEIGHT = SERVER_BUILDER.comment("Minimal height for Gobber Lucky Block pocket generation, [0-255, default: 1]").defineInRange("gobberLuckyBlockMinHeight", 1, 0, 255);
        GOBBER2_LUCKY_BLOCK_MAX_HEIGHT = SERVER_BUILDER.comment("Maximal height for Gobber Lucky Block pocket generation [0-255, default: 255]").defineInRange("gobberLuckyBlockMaxHeight", 255, 0, 255);

        SERVER_BUILDER.pop();
        
        
        SERVER_BUILDER.comment("Gobber Nether Ore Generation").push("gobber2_ore_nether");

        GOBBER2_ORE_NETHER_GENERATION = SERVER_BUILDER.comment("Generate Gobber Nether Ore in the world [true / false]").define("gobberOreNetherGeneration", true);
        GOBBER2_ORE_NETHER_SIZE = SERVER_BUILDER.comment("Size of Gobber Nether Ore pockets [0-100, default: 1]").defineInRange("gobberOreNetherSize", 3, 0, 100);
        GOBBER2_ORE_NETHER_CHANCE = SERVER_BUILDER.comment("Chances of Gobber Nether Ore pocket being generated [0-100, default: 10]").defineInRange("gobberOreNetherChance", 80, 0, 100);
        GOBBER2_ORE_NETHER_MIN_HEIGHT = SERVER_BUILDER.comment("Minimal height for Gobber Nether Ore pocket generation, [0-255, default: 5]").defineInRange("gobberOreNetherMinHeight", 20, 0, 255);
        GOBBER2_ORE_NETHER_MAX_HEIGHT = SERVER_BUILDER.comment("Maximal height for Gobber Nether Ore pocket generation [0-255, default: 50]").defineInRange("gobberOreNetherMaxHeight", 255, 0, 255);

        SERVER_BUILDER.pop();
        
        
        SERVER_BUILDER.comment("Gobber End Ore Generation").push("gobber2_ore_end");

        GOBBER2_ORE_END_GENERATION = SERVER_BUILDER.comment("Generate Gobber End Ore in the world [true / false]").define("gobberOreEndGeneration", true);
        GOBBER2_ORE_END_SIZE = SERVER_BUILDER.comment("Size of Gobber End Ore pockets [0-100, default: 5]").defineInRange("gobberOreEndSize", 5, 0, 100);
        GOBBER2_ORE_END_CHANCE = SERVER_BUILDER.comment("Chances of Gobber End Ore pocket being generated [0-100, default: 10]").defineInRange("gobberOreEndChance", 80, 0, 100);
        GOBBER2_ORE_END_MIN_HEIGHT = SERVER_BUILDER.comment("Minimal height for Gobber End Ore pocket generation, [0-255, default: 5]").defineInRange("gobberOreEndMinHeight", 0, 0, 255);
        GOBBER2_ORE_END_MAX_HEIGHT = SERVER_BUILDER.comment("Maximal height for Gobber End Ore pocket generation [0-255, default: 50]").defineInRange("gobberOreEndMaxHeight", 255, 0, 255);

        SERVER_BUILDER.pop();
        
        
        SERVER_BUILDER.comment("Sniper Sword Enablement").push("gobber2_sniper_sword");

        SNIPER_SWORD = SERVER_BUILDER.comment("Enable crafting of Sniper Sword [true / false]").define("sniperSwordEnablement", true);
       
        SERVER_BUILDER.pop();
    }
}

The value correctly writes to my config file.

 

In my item register class, doing a simple: if(GeneralModConfig.SNIPER_SWORD == true) yields an error: "Incompatible operand types ForgeConfigSpec.BooleanValue and boolean"

 

Looking through ForgeConfigSpec class, it is clear that this is a much more complex structure than just a boolean.  In reading the ForgeConfigSpec class code, I am not able to figure out how to navigate this structure to test the ForgeConfigSpec.BooleanValue I set.

 

Any guidance would be helpful.

 

Regards.

 

Link to comment
Share on other sites

Ok.  So I clearly did it the wrong way in my 1.12.2 version, since I used conditional statements to either register or not based on config values.

 

Can you provide some guidance on how I should accomplish this?   I am not aware of how I would "hide" an item or block from the game after it is already registered.

 

Thank you.

Link to comment
Share on other sites

Ok.  I assume disabling the recipes and removing from ItemGroup would still leave already created versions of the item in the game?  Is that correct?

 

My desire is that disabling the item in the config would also remove any of the items in the world as well.

 

 

Link to comment
Share on other sites

33 minutes ago, kwpugh said:

My desire is that disabling the item in the config would also remove any of the items in the world as well.

Then you will also have to do something else like when a chunk is loaded and by extension TileEntities remove them from their exposed IItemHandler capability. You'll also want to insert in Item#inventoryTick them removing themselves from the players inventory.And if Item#inventoryTick doesn't work you'll have to use the PlayerTickEvent.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Ok.  So that seems like a lot of work just to remove an item.

 

What exactly is the downside of my old method of conditional registration based on config values.   Looking at other mods source code, this seems to be a fairly common practice.

 

I am not clear on the negative implications.

 

 

Link to comment
Share on other sites

13 minutes ago, kwpugh said:

I am not clear on the negative implications.

Here is one. Items and Blocks are registered at the beginning of Minecraft/Forge launching. Now if you had that based off of config values certain items would register and certain items wouldn't. Now imagine a player trying to connect to a server who has a set up config file. One that is different from his. Disabling certain items. What do you think would happen. The player would not be able to connect because the Item/Block registries are different.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Yes, that would be bad.

 

Ok, back to original suggestion.

 

- I do not understand getSubItem, so I will need to research that.

- How does one disable recipes within a mod, programmatically?   I have only worked with adding or removing json file manually.

 

 

 

 

Link to comment
Share on other sites

11 minutes ago, kwpugh said:

- How does one disable recipes within a mod, programmatically?   I have only worked with adding or removing json file manually.

You can remove them from the forge registry it is one of the modifiable ones.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

5 minutes ago, kwpugh said:

IForgeRegistry<IRecipeSerializer<?>>.    This one?

 

 

Uhh no, as it turns out recipes are no longer a forge registry or at least not yet, There are recipe conditions which should let you disable the recipe based on config options.

Choonster explains how to  something similar to this here.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • This is a MacOs related issue: https://bugs.mojang.com/browse/MC-118506     Download this lib: https://libraries.minecraft.net/ca/weblite/java-objc-bridge/1.0.0/java-objc-bridge-1.0.0.jar and put it into ~/Library/Application Support/minecraft/libraries/ca/weblite/java-objc-bridge/1.0.0  
    • I use Bisect-Hosting, and I host a relatively modded server.  There is a mod I desperately want to have in a server. https://www.curseforge.com/minecraft/mc-mods/minehoplite This is MineHop. It's a mod that replicates the movement capabilities seen in Source Engine games, such as Half-Life, and such.  https://youtu.be/SbtLo7VbOvk - A video explaining the mod, if anyone is interested.  It is a clientside mod, meaning whoever is using it can change anything about the mod that they want, with no restrictions, even when they join a server with the same mod. They can change it to where they can go infinitely fast, or do some other overpowered thing. I don't want that to happen. So I just want to know if there is some way to force the SERVER'S configuration file, onto whoever is joining.  I'm not very savvy with all this modding stuff. There are two config files: minehop-common.txt, and minehop.txt I don't really know much about how each are different. I just know what the commands relating to acceleration and stuff mean.    
    • My journey into crypto trading began tentatively, with me dipping my toes into the waters by purchasing my first Bitcoin through a seasoned trader. With an initial investment of $5,000, I watched as my investment grew, proving to be both fruitful and lucrative. Encouraged by this success, I decided to increase my investment to $150,000, eager to capitalize on the growing popularity of cryptocurrency, However, as cryptocurrency gained mainstream attention, so too did the number of self-proclaimed "experts" in the field. Suddenly, everyone seemed to be a crypto guru, and more and more people were eager to jump on the bandwagon without fully understanding the intricacies of this complex world. With promises of quick and easy profits, these con artists preyed on the uninformed, luring them into schemes that often ended in disappointment and financial loss. Unfortunately, I fell victim to one such scheme. Seduced by the allure of easy money, I entrusted my hard-earned funds to a dubious trading platform, granting them access to my accounts in the hopes of seeing my investment grow. For a brief period, everything seemed to be going according to plan, with regular withdrawals and promising returns on my investment. However, my hopes were soon dashed when, without warning, communication from the platform ceased, and my Bitcoin holdings vanished into thin air. Feeling helpless and betrayed, I confided in a family member about my predicament. They listened sympathetically and offered a glimmer of hope in the form of a recommendation for Wizard Web Recovery. Intrigued by the possibility of reclaiming what I had lost, I decided to explore this option further. From the moment I reached out to Wizard Web Recovery, I was met with professionalism and empathy. They took the time to understand my situation and reassured me that I was not alone in my plight. With their guidance, I embarked on a journey to reclaim what was rightfully mine. Wizard Web Recovery's expertise and dedication were evident from the start. They meticulously analyzed the details of my case, uncovering crucial evidence that would prove invaluable in our quest for justice. With each step forward, they kept me informed and empowered, instilling in me a newfound sense of hope and determination. Through their tireless efforts and unwavering support, Wizard Web Recovery succeeded in recovering my lost Bitcoin holdings. It was a moment of triumph and relief, knowing that justice had been served and that I could finally put this chapter behind me. In conclusion, My experience with Wizard Web Recovery  was nothing short of transformative. Their professionalism, expertise, and unwavering commitment to their clients set them apart as true leaders in the field of cryptocurrency recovery. I am forever grateful for their assistance and would highly recommend their services to anyone in need of help navigating the treacherous waters of cryptocurrency scams. 
    • Ok so: Two things to note: It got stuck due to my dimension type. It was previously the same as the overworld dimension tpye but after changing it , it didn't freeze during spawn generation. ALSO, APPARENTLY, the way I'm doing things, the game can't have two extremely-rich dimensions or it will make the new chunk generation be veeery VEEERY slow. I'm doing the dimension file genreation all in the data generation step now, so it's all good. Mostly. If anybody has any tips regarding how can i more efficently generate a biome-rich dimension, im all ears.
    • https://mclo.gs/qTo3bUE  
  • Topics

×
×
  • Create New...

Important Information

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