Jump to content

Recommended Posts

Posted

While making my mod, i'm trying to make everything configurable in parameters file, including the ID of item that drops when mining the block. I've got an ID error. Trying to solve it, i've noticed that the item ID used in a game itself is given ID + 256. So, if I want to set specified ID of item, and use that ID correctly even before initialisation of item, should i use new MyItem(myItemID-256)? Will it always works (if ID is not yet occupied)?

Posted

This is correct. In my mod I do something similar, I found the following to be a fairly good way of handling my config if it helps you: (if you don't understand what's going on just say)

 

Item constructor.

public ItemBase(int id, String localName, String dispName)
{
	super(Config.getItem(id, localName));
	setUnlocalizedName(localName);
	setCreativeTab(Tabs.tabMTechWorld);

	subTypes.put(0, new String[]{localName, dispName});

	GameRegistry.registerItem(this, localName);
	LanguageRegistry.addName(this, dispName);
}

and

 

handling my config

package mtech.common;

import net.minecraftforge.common.Configuration;

public class Config
{
public static boolean		keepSand	= true;
public static Configuration	config;

public static int getBlock(int defaultId, String name)
{
	return config.getBlock(name, defaultId).getInt();
}

public static int getItem(int defaultId, String name)
{
	return config.getItem(name, defaultId + 256).getInt() - 256;
}

public static boolean generateOre(String name)
{
	return config.get(Configuration.CATEGORY_GENERAL, "generate_" + name,
		true).getBoolean(true);
}

public static void doInitialConfig(Configuration conf)
{
	config = conf;
	config.load();
}
}

 

Main mod file:

	@PreInit
public static void preInit(FMLPreInitializationEvent evt)
{
	Config.doInitialConfig(new Configuration(evt.getSuggestedConfigurationFile()));

	Blocks.addBlocks();
	Items.addItems();

	Config.config.save();

	Recipies.addRecipies();

	GameRegistry.registerWorldGenerator(new WorldGen());
	NetworkRegistry.instance().registerGuiHandler(instance, new MyGuiHandler());
}

Posted

Thanks for answer and for code, it seems to be very helpful. One more question, did you test your mod alongside with others? If I use your (or mine, when it's ready) mod and, for example, buildcraft - will the +-256 trick still be actual? More general question: is there a way for any external mod to break that +-256 trick from my mod (suppose absence of ID conflicts)?

Posted

Thanks for answer and for code, it seems to be very helpful. One more question, did you test your mod alongside with others? If I use your (or mine, when it's ready) mod and, for example, buildcraft - will the +-256 trick still be actual? More general question: is there a way for any external mod to break that +-256 trick from my mod (suppose absence of ID conflicts)?

 

The ID +/- 256 "trick" is a result of original vanilla's code, that block IDs were 0-255, and items were 0-255 (internally shifted by 256).

 

That translated into Forge supplying a getBlockID function separate from a getItemID function (the latter auto-incrementing the ID by 256).

 

And now we're stuck with it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.