Jump to content

Recommended Posts

Posted

So i was searching through the list of item classes i have and its about 100 of them as i have 12 types of pickaxes, hoes axes etc.

I was taking a look at ItemPickaxe and such trying to see what they did. And as i only have this code in almost each of the files :

I thought why not wrap it up into one classfile for each type of tool ? How can i do that the best way.


public class ItemBronzeAxe extends ItemAxe
{
public ItemBronzeAxe(int i, EnumToolMaterial bronze)
{
	super(i, bronze);
}
    public String getTextureFile()
    {
        return "/mod_Ores/gui/ItemsMe.png";
    }
}

 

Thanks for your time and effort!

Posted

Okay, so (if I am right) you want to create structure like this:

ItemAxe.class (which is builder for ALL axes)

ModBase.class (which is loader of mod)

and make all the axes loaded in ModBase use ItemAxe.class?

its quite simple, if you would actually know java (I am guessing you are just ,,Minecarft from tutorial coder" - no offense, thats a good beginning :) )

So I ll just paste and comment the code.

//Imports
public class ItemAxe extends Item
{
public ItemAxe(int id, String UName, String IGName) //id - item ID, UName - Unlocalized Name, IGName - IngameName
{
	super(id, UName); //This super will load item ID and UName
	setUnlocalizedName(UName); //This will set UName
	setCreativeTab(CreativeTabs.tabMisc); //Set Tab
	GameRegistry.registerItem(this, UName); //This is NOT required, you can actually remove registration part of your items
in ModBase.class and plase it here (with many items its VERY code-shortening), this will load unlocalized name
	LanguageRegistry.addName(this, IGName); //Same as above, this will load ingame name
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
	itemIcon = iconRegister.registerIcon("YourMod:"+this.getUnlocalizedName()); //Not sure if correctly written since I'm writing it here (not in Eclyple)
//Here, you can actually remove all this spam of code and place it in one function
}
}

Now you need to load whole stuff into a game (using ModBase of course).

public class RoAMain
{
//Your ModBase structure
public static final Item AxeBronze = new ItemAxe(1000, "AxeBronze", "Bronze Axe");
public static final Item AxeSteel    = new ItemAxe(1001, "AxeSteel", "Steel Axe");
//Your ModBase structure
}

Note: You can do whatever you want with this kind of stuff.

Eg.: Adding to ItemAxe this:

public ItemAxe(int id, String UName, String IGName, int damage) //damage

and this:

public int getDamageVsEntity(Entity par1Entity)

    {

        return this.damage;

    }

You can later set item damage, like this:

public static final Item AxeSteel    = new ItemAxe(1001, "AxeSteel", "Steel Axe", 20);

 

Don't thank me, go learn java, I am just bored so I wrote it :D

1.7.10 is no longer supported by forge, you are on your own.

Posted

Since you want all items be stored in one file (or few), you can do this by either extending class (create ItemBase with stuff i wrote in prev. post, and then crate ItemPickaxe, ItemShovel, etc. that will extend ItemBase and get additional variables like those what it can harvest or so... But i would recommend using extend on ItemPickaxe to do so (you can even do chained extends that will shorten code to minimum)) or by making one BIG class like ItemTools that will hold EVERY data on IF statement with ,,checker" here:

public ItemAxe(int id, String UName, String IGName, int type)

and then call: (let's sat 1 is a pickaxe and 2 is a shovel)

type == 1 ? pickaxe code

type == 2 ? shovel code

1.7.10 is no longer supported by forge, you are on your own.

Posted

Since tool classes have to subclass ItemPickaxe, ItemSword, etc, it's really not feasible to pack all five tool types into one class. For my mod, I made one base class for each type of tool, (pick, shovel, sword, axe, and hoe) and had them take a EnumToolMaterial in its constructor (passing it up to the respective superclass.) Anything else that is material-specific gets handled in the base classes with an if/else block.

Posted

That's why I wrote about chained extending. I personally use same system as you (5x base of Tools) but just wanted to point out that you can get shorter code with this ,,chained" extending :D

1.7.10 is no longer supported by forge, you are on your own.

Posted
if you would actually know java (I am guessing you are just ,,Minecarft from tutorial coder" - no offense, thats a good beginning  )

 

To answer your "question" i do understand the basics of java and i indeed started by watching tuts especially when it comes to forge stuff, Next to the tuts i also look through every method i see and try to understand what it does the best it can. I can find myself watching minecraft classes for a bit too long sometimes xD. What troubles me the most is that i do'nt simple make a method in this base class because thats what a normal game maker would do, but i would need a subclass or an extended class. That's were it gets to me to look at ItemPickaxe and ItemHoe, but when i look inside those i do see quite some methods that i don't have to copy over to my extended class.

 

I also have some knowledge of c# ( i know its a lot different from java) but i will get to learn java better next year on my school. But there are also a lot of things that work the same as  for constructors.

 

Thanks for your reply and i will look into that tomorrow because i don't have much time to do so now.

 

Since tool classes have to subclass ItemPickaxe, ItemSword, etc, it's really not feasible to pack all five tool types into one class.

 

Jeah i was indeed not intending to do a 5 in one tool class. Thanks for the help though.

 

 

Also i had been looking into "Multiple biomes in custom dimension" which is one of my biggest problems at the moment which has kept me stuck for over 2 weeks now. I have been going through every chain class in that from WorldChunkManager to BiomeCache, GenLayer and all the way to the base of base classes World.

So i thought let's just take a break of this quite complicated stuff at the moment and just do something much much much simpler and clean up my code a lot.

 

 

Overall i thank you all for your help, i think i will go (as i sayd earlier) create the ItemPickaxe etc and i will be able to delete about a 100 classes xD should've done that alot earlier but i simple never did :P

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.