Jump to content

[1.7.2]Custom Items / Custom Blocks


vandy22

Recommended Posts

I am making multiple blocks and items, so what I wanted was a class for items and for blocks that I could call multiple times for each item and block in code, instead of having a class for every item and block just because it has a different unlocalizedname. Is there a way I can do this?

 

This is my current item class (Just for a pickaxe):

package com.mjj.colormod.items;

import com.mjj.colormod.ColorMod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;

public class GreenPickaxe extends ItemPickaxe
{
public GreenPickaxe(ToolMaterial material) 
{
	super(material);
	setUnlocalizedName("greenPickaxe");
	setTextureName(ColorMod.modid + ":" + getUnlocalizedName().substring(5));
	setCreativeTab(CreativeTabs.tabTools);
}
}

Link to comment
Share on other sites

What you are asking makes no sense. You can make as many blocks or items from a class as you want. As long as they each get registered with separate names... and should probably have unique textures as well.

Link to comment
Share on other sites

You could

 

1) be stupid and put everything in the constructor;

 

2) be smart and use chaining(i.e., when initializing your Item object, chain on methods to the end

 public static Item item = new ItemExample(ToolMaterialExample).setUnlocalizedName("name").method(args)

);

 

3) (this is if you already have 2 done) Cast your Item object to your item class when initializing it so you can chain on methods that you make for setters that you add, that aren't in the vanilla game, or change something for your item.;

 

(and sequituri, I think his question was how to do multiple names and textures and such from one class. ^this answers that.)

Link to comment
Share on other sites

Alix,

 

Thanks for your response, but I'm misunderstanding one thing, can you give me an example on what you mean by casting my item object to my item class when initializing? Here is my green pickaxe now (in the mod file):

greenPickaxe = new GreenPickaxe(greenMaterial).setUnlocalizedName("greenMaterial").setTextureName("greenMaterial");

 

The thing is, which I'm assuming gets fixed in step 3, whenever I launch the game it doesn't understand .setUnlocalizedName. It want's it in the constructor for some reason. I assume you already know all of this and I'm stupid for typing it, but I don't understand so If you could give an example of what I need to change.

 

I know that in the actual Item class they call .setUnlocalizedName from out of the constructor on the actual object but I'm not sure how I need to do that myself. I hope you understand what I'm saying here and can answer my question.

 

Thanks

Link to comment
Share on other sites

As long as each method in the chain ends with "return this", you should be able to chain as you were told. The constructor does that automatically, so does setUnlocalizedName and a couple others.

Link to comment
Share on other sites

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.