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.

[1.7.10] How to make a toolmaterial that changes based on what mods are present

Featured Replies

Posted

Hi, I'm trying to make a material for tools that will have higher mining capabilities if certain mods are present. What I have working right now is the actual material (registered in EnumHelper, this part works fine and I've used the pick for mining in single player), and I know how to use Loader.isModLoaded properly (I got it working for the hardness of a block in a different section of my code.)

 

However, when I try to use the same type of if statement that I used for the block's hardness, I get a whole slew of errors. I'm not sure what I'm doing wrong with it though.

 

Here is my current code:

 

package com.hotmail.Billeh007.forceofwill.init;

 

import com.hotmail.Billeh007.forceofwill.items.ItemForesiaAxe;

import com.hotmail.Billeh007.forceofwill.items.ItemForesiaHoe;

import com.hotmail.Billeh007.forceofwill.items.ItemForesiaPick;

import com.hotmail.Billeh007.forceofwill.items.ItemForesiaShovel;

import com.hotmail.Billeh007.mods.forceofwill.help.RegisterHelper;

 

import net.minecraft.item.Item.ToolMaterial;

import net.minecraft.item.ItemAxe;

import net.minecraft.item.ItemHoe;

import net.minecraft.item.ItemPickaxe;

import net.minecraft.item.ItemSpade;

import net.minecraftforge.common.util.EnumHelper;

 

public class ModTools

{

//Tool Materials, name, harvestlevel, durability, minespeed, damage, enchantability

if (Loader.isModLoaded("Metallurgy"))

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 6, 5000, 10.0F, 4, 30);

}

else if (Loader.isModLoaded("TConstruct"))

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 5, 5000, 10.0F, 4, 30);

}

else

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 4, 5000, 10.0F, 4, 30);

}

 

 

//picks

public static ItemPickaxe ItemForesiaPick = new ItemForesiaPick(FORESIATOOL);

 

//shovels

public static ItemSpade ItemForesiaShovel = new ItemForesiaShovel(FORESIATOOL);

 

//axes

public static ItemAxe ItemForesiaAxe = new ItemForesiaAxe(FORESIATOOL);

 

//hoes

public static ItemHoe ItemForesiaHoe = new ItemForesiaHoe(FORESIATOOL);

 

public static void init()

{

//picks

RegisterHelper.registerItemPick(ItemForesiaPick);

 

//shovels

RegisterHelper.registerItemShovel(ItemForesiaShovel);

 

//axes

RegisterHelper.registerItemAxe(ItemForesiaAxe);

 

//hoes

RegisterHelper.registerItemHoe(ItemForesiaHoe);

}

}

 

 

 

Any help would be appreciated.

This is a basic Java error, you can't have regular statements in the main body of a class. Move the initialisation of all fields to a method (like the

init

method you already have) and call it in preInit.

 

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Okay, so I've added this to the top of my code:

 

public static void preinit()

{

if (Loader.isModLoaded("Metallurgy"))

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 6, 5000, 10.0F, 4, 30);

}

else if (Loader.isModLoaded("TConstruct"))

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 5, 5000, 10.0F, 4, 30);

}

else

{

public static ToolMaterial FORESIATOOL = EnumHelper.addToolMaterial("FORESIATOOL", 4, 5000, 10.0F, 4, 30);

}

}

 

 

And I get an error on the FORESIATOOL saying "only final is permitted". I've obviously messed something up here, but I'm not great at Java and very new to Forge so I'm not sure what.

Keep the field declaration in the main body of the class, only move the initialisation to the method.

 

You must have a solid understanding of Java and OO programming in general before you can make a mod.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.