Jump to content

[Answered]Questions about EnumHelper


Recommended Posts

I know there are easier ways to accomplish this but I want to continue trying it this way to learn a bit about how java works deep down and for general experience/knowledge.


My current Enum:

public static enum SWORDTYPES
	COAL("coalsword", 1, 131, 4.0F, 1.0F, 5, Blocks.coal_ore, new CoalEffect()),//oreswords_coalsword
	DIAMOND("diamondsword", 3, 1200, 8.0F, 3.0F, 30, Blocks.diamond_ore, null),//oreswords_diamondsword
	EMERALD("emeraldsword", 3, 2300, 8.0F, 4.0F, 10, Blocks.emerald_ore, null),//oreswords_emeraldsword
	GOLD("goldsword", 0, 25, 10.0F, 1.0F, 12, Blocks.gold_ore, null),//oreswords_goldsword
	IRON("ironsword", 2, 131, 6.0F, 2.0F, 14, Blocks.iron_ore, null),//oreswords_ironsword
	LAPIS("lapissword", 1, 131, 4.0F, 1.0F, 44, Blocks.lapis_ore, null),//oreswords_lapissword
	QUARTZ("quartzsword", 3, 131, 8.0F, 3.0F, 10, Blocks.quartz_ore, null),//oreswords_quartzsword
	REDSTONE("redstonesword", 2, 131, 6.0F, 2.0F, 14, Blocks.redstone_ore, null);//oreswords_redstonesword		

	private String name;
	private ToolMaterial mat;
	private Block cType;
	private OreSword sword;
	private SwordEffect effect;
	SWORDTYPES(String name, int hLevel, int mUse, float effic, float damage, int ench, Block cType, SwordEffect effect)
		this.name = name;
		this.cType = cType;
		this.mat = EnumHelper.addToolMaterial(name, hLevel, mUse, effic, damage, ench);
		this.effect = effect;

	public String getName(){return name;}
	public ToolMaterial getMaterial(){return mat;}
	public Block getCraftingMaterial(){return cType;}
	public void doEffect(ItemStack sword, EntityLivingBase target, EntityLivingBase self){effect.doEffect(sword, target, self);}
	public void setSword(OreSword sword)
		this.sword = sword;
		swordMap.put(sword.getUnlocalizedName(), this);

	public OreSword getSword(){return sword;}


I implement my swords this way because it made it very easy to add new swords and it made the registry look very clean!

in preInit()
for(SWORDTYPES sword : SWORDTYPES.values())
		GameRegistry.registerItem(new OreSword(sword), References.MODID + "_" + sword.getName());

in init()
for(SWORDTYPES sword : SWORDTYPES.values())
		GameRegistry.addRecipe(new ItemStack(sword.getSword()), " C ", " C ", " H ", 'C', sword.getCraftingMaterial(), 'H', hilt);


I am now running into a lot of confusion though. I want to make an api that allows people to make swords out of modded ores.

What I am trying to do to accomplish this is to let them add new enum values and my code would take care of the rest.


Looking through the EnumHelper class, it seems like I could use it if I had a way to add my enum to the commonTypes variable.

Is there a way to do this without setting up my own reflectionhelper just to add a variable or do I need to make my own SwordEnumHelper?


If this isn't currently possible, will there be support for mod enums later on?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

Better in my opinion: don't use an enum at all. Make your enum class a normal class, and make static references to the different materials. Then in the constructor, add the materials to a List, and iterate over that instead.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.


1.12 -> 1.13 primer by williewillus.


1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.



Link to comment
Share on other sites

Enums are just syntax sugar for classes that are only ever going to have a known number of instances.

EnumHelper* classes in Forge are a hacky workaround to allow modders to expand things that Vanilla has made enums when it shouldn't have.

In your case DO NOT MAKE YOUR CLASS A ENUM, that is the best option.

You can emulate the values() part of a enum simple enough by simply adding:

values.add(this); to your constructor.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Alright, I'll switch it up for the one I'll be maintaining, but I'm still going to work through it as an enum on the side so I can try and get an understanding of exactly how reflection works.


Thanks for the responses.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

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.

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.


  • Create New...

Important Information

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