Jump to content

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


Recommended Posts

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.

Posted

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.

Posted

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.

Posted

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

×   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



×
×
  • Create New...

Important Information

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