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.

Featured Replies

Posted

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);
}
}

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.

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

  • Author

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

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.

  • Author

Turns out, all you have to do is keep setUnlocalizedName in the constructor, but when you chain it onto the end of the item it will override the constructor, so in that way you can use one class for multiple items. Thanks :D

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.