Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.