How to add a mod element to multiple ore dictionary entries

Started by SomeoneElse on

Topic category: User side tutorials

Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to add a mod element to multiple ore dictionary entries

The element creator currently supports only one ore dict entry, but with a little bit of code it's possible to add the same item to multiple entries. For this tutorial, we'll create an item that can be used both as a stick ("stickWood") and as a red dye ("dyeRed").

Step 1: create your block/item
You can add your element to one of the ore dict entries. It doesn't matter which one you choose, but keep it in mind for the next steps. In this case, I'll pick "stickWood".  Also remember the name of your mod element, as you'll need it for step 3.

Step 2: create a "Custom element" element
This is where the code will go: don't worry, it's not as difficult as it might sound. Start by removing some of the methods: all you need are the constructor and the "public void init". Your code should look like this once you remove the unnecessary parts:

// List of imports. Don't touch them!

@Elementstesting_workspace.ModElement.Tag
public class MCreatorOreDictRegistry extends Elementstesting_workspace.ModElement {
	/**
	 * Do not remove this constructor
	 */
	public MCreatorOreDictRegistry(Elementstesting_workspace instance) {
		super(instance, 2);
	}

	// Don't remove this one!
	@Override
	public void init(FMLInitializationEvent event) {
		// Your code will go here!
	}
}

Step 3: registering your blocks/items
To add your element to the ore dictionary, add this line of code inside the {} brackets of public void init:

OreDictionary.registerOre("oreDictEntry", MCreatorYourElement.block);

Replace oreDictEntry with the entry you want your item to be. Make sure not to use the one you picked in step 1! I already used "woodStick", so now I'll have to write "dyeRed".
Replace YourElement with the name of your mod element. In this tutorial, my item element was called RedStick, so "MCreatorYourElement.block" will become "MCreatorRedStick.block". The final code should look like this:

// List of imports. Don't touch them!

@Elementstesting_workspace.ModElement.Tag
public class MCreatorOreDictRegistry extends Elementstesting_workspace.ModElement {
	/**
	 * Do not remove this constructor
	 */
	public MCreatorOreDictRegistry(Elementstesting_workspace instance) {
		super(instance, 2);
	}

	// Don't remove this one!
	@Override
	public void init(FMLInitializationEvent event) {
		OreDictionary.registerOre("dyeRed", MCreatorRedStick.block);
		// I replaced "oreDictEntry" with "dyeRed", and "YourElement" with "RedStick"
		// You can add more entries here if you want
	}
}

Finally, press ctrl+w and save the element. If you did everything correctly, you should have recompilation errors.

Extra stuff
Once you set-up your custom code element, you won't have to create new ones. Just add more lines of code inside the init method. You can also use this system to add tools and foods to the ore dict.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is an amazing tutorial…
Wed, 10/02/2019 - 03:50

This is an amazing tutorial have not tried it yet but definitely bookmarking this thank you!

Joined Oct 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ive spent like the last hour…
Wed, 10/09/2019 - 17:56

Ive spent like the last hour trying to get this to work for and its just not working. im trying to add oredict tags to foods but they are not showing up in the game

	@Override
	public void init(FMLInitializationEvent event) {
		OreDictionary.registerOre("listAllmeatcooked", "foodRedmeatcooked", "foodMeatcooked", "listAllporkcooked" MCreatorPorkRoll.block);
		OreDictionary.registerOre("listAllmeatcooked", "foodRedmeatcooked", "foodMeatcooked", "listAllporkcooked" MCreatorPorkRollSlice.block);
		OreDictionary.registerOre("foodCheese", "foodCheeseslice" MCreatorAmericanCheese.block);
		OreDictionary.registerOre("foodFriedegg", MCreatorFriedEgg.block);
	}

I have this, may i get some help on whats going wrong? thanks

Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry for the really late…
Sun, 10/27/2019 - 00:08

Sorry for the really late answer, didn't get any notification about the reply. Anyway, the issue is that you're registering the same food to multiple entries on the same line. Each line can have only 1 oreDict entry. The fixed code would be:

@Override
public void init(FMLInitializationEvent event) {
	// Registering Pork Roll
	OreDictionary.registerOre("listAllmeatcooked", MCreatorPorkRoll.block);
	OreDictionary.registerOre("foodRedmeatcooked", MCreatorPorkRoll.block);
	OreDictionary.registerOre("foodMeatcooked", MCreatorPorkRoll.block);
	OreDictionary.registerOre("listAllporkcooked", MCreatorPorkRoll.block);
	// Registering Pork Roll Slice
	OreDictionary.registerOre("listAllmeatcooked", MCreatorPorkRollSlice.block);
	OreDictionary.registerOre("foodRedmeatcooked", MCreatorPorkRollSlice.block);
	OreDictionary.registerOre("foodMeatcooked", MCreatorPorkRollSlice.block);
	OreDictionary.registerOre("listAllporkcooked", MCreatorPorkRollSlice.block);
	// Registering American Cheese
	OreDictionary.registerOre("foodCheese", MCreatorAmericanCheese.block);
	OreDictionary.registerOre("foodCheeseslice", MCreatorAmericanCheese.block);
	// Registering Fried Egg
	OreDictionary.registerOre("foodFriedegg", MCreatorFriedEgg.block);
}

Also, make sure not to forget commas!

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
you accidently said crtl+W…
Mon, 03/09/2020 - 16:02

you accidently said crtl+W is save, and if it is right you should have recompilation errors, I think u got some mistakes there...

talking about which, I am getting recompilation errors.
it says it cannot find symbol mcreatorKardarioplanks.block .

i cant figure out what is wrong, and if it's a typo, isn't there anywhere I can copy paste this name/ID thing from the block's code itself?

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it also can't find the…
Mon, 03/09/2020 - 16:18

it also can't find the symbol for oreDictionary in the first place - now i'm confused

my code:

package net.mcreator.ridiculous_forests;

import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@Elementsridiculous_forests.ModElement.Tag
public class MCreatorAssignOreDict extends Elementsridiculous_forests.ModElement {
     
    public MCreatorAssignOreDict(Elementsridiculous_forests instance) {
        super(instance, 22);
    }
    
    @Override
    public void init(FMLCommonSetupEvent event) {
     OreDictionary.registerOre("plankWood", MCreatorkardarioplanks.block);
    }

}
 

bit of crashreport:

Executing gradle task: runClient
Build info: MCreator 2020.1.05419, 1.14.4, 64-bit, 16224 MB, Windows 10, JVM 1.8.0_232, JAVA_HOME: L:\Pylo\MCreator2020\jdk
> Configure project :
New Dep: net.minecraftforge:forge:1.14.4-28.1.117_mapped_snapshot_20190719-1.14.3
> Task :compileJava FAILED
C:\Users\reinv\MCreatorWorkspaces\ridiculous_forests\src\main\java\net\mcreator\ridiculous_forests\MCreatorAssignOreDict.java:32: error: cannot find symbol
    OreDictionary.registerOre("plankWood", MCreatorkardarioplanks.block);
                                           ^
  symbol:   variable MCreatorkardarioplanks
  location: class MCreatorAssignOreDict
C:\Users\reinv\MCreatorWorkspaces\ridiculous_forests\src\main\java\net\mcreator\ridiculous_forests\MCreatorAssignOreDict.java:32: error: cannot find symbol
    OreDictionary.registerOre("plankWood", MCreatorkardarioplanks.block);
    ^
  symbol:   variable OreDictionary
  location: class MCreatorAssignOreDict