Jump to content

A dumb question


teratogenytale

Recommended Posts

I have seen that whenever a new block is created, people create a whole new class.

That seems like a lot of useless classes and code must be copy-pasted every time.

So I created only two classes, one for creating blocks, and one for creating items, and I just pass arguments to a constructor, and inside it runs methods: setMaxStackSize(), setUnlocalizedName() and a few more. That saves me from creating a new class every time I need to create a new block. So, since I haven't seen that aproach used anywhere, I just wonder is there something wrong with it? Does it create lag, or conflicts with some rules or conventions?

 

package packageName;

import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;


public class className extends Item{

public className(int itemID, int stackSize, String name, CreativeTabs tab, String texture) {
	super(itemID);

	setMaxStackSize(stackSize);
	setUnlocalizedName(name);
	setCreativeTab(tab);
	setTextureName("intercraft:"+texture);


}

public className(int itemID, int stackSize, String name, CreativeTabs tab) {
	super(itemID);

	setMaxStackSize(stackSize);
	setUnlocalizedName(name);
	setCreativeTab(tab);


}

}

 

There are many behind me, but still some ahead...

Link to comment
Share on other sites

its a good approach for basic items. If you want to do some complex stuff with behaviour of an item, then you have to make it a class. So you can override onItemUse in item A and onItemRightClick in class B.

 

In the end it really, really depends what you want that item to be able to do. If it's just a show item, you found the best approach.

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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