Jump to content

[1.18.2] Config field does not work


Sweetmimike

Recommended Posts

Hello, I'm currently working on a mod and I'm using a configuration field to determine the durability of an item. But I don't understand why when I change the config in the .toml file, the durability of the item stay at the default value.

Here is how I set the durability (MOB_SHARD_DURABILITY) : 

/**
 * Manager for the mod items
 */
public class ItemManager {

    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, PerfectMobFarm.MODID);

  	// Use of CommonConfig
    public static final RegistryObject<Item> MOB_SHARD = ITEMS.register("mob_shard",
            () -> new MobShard(new Item.Properties().tab(PerfectMobFarm.PERFECT_MOB_FARM_TAB), CommonConfigs.MOB_SHARD_DURABILITY.get()));

    public static void register(IEventBus eventBus) {
        ITEMS.register(eventBus);
    }
}

/////////////////
// Item class //
////////////////
public MobShard(Properties pProperties, int pDurability) 
{
        this(pProperties.durability(pDurability));
}

 

Of course I have others config fields and they work properly.

Link to comment
Share on other sites

Those item registrations only happen at startup. Your durability is fixed then.

If you want something more dynamic you would need to do something like this in your item class:

Quote

    @Override 

     public int getMaxDamage(ItemStack stack)
    {
        return fromTheConfiguration();
    }
 

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Thanks for your answers. I managed to use a server config and to override the function 

@Override
    public int getMaxDamage(ItemStack stack) {
        return ServerConfigs.MOB_SHARD_DURABILITY.get();
    }

But now, the durability bar seems to be hidden since I removed the .durability(int) in the properties. How can I show it again ?

 

EDIT :

I found the solution to display it again. I just had to use the .durability(int) function on the properties, and the value taken for the durability is the one that come from the configs.

Edited by Sweetmimike
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.



×
×
  • Create New...

Important Information

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