Jump to content

Smelting


leosavi25

Recommended Posts

I'm creating a mod for 1.12 and I add the Copper Ore and the Ingot Copper, but when I put the Copper Ore in the Furnace nothing happen.

Here's the code:

 

Spoiler

@Mod(modid = Reference.MOD_ID, version = Reference.VERSION, name = Reference.NAME)
public class Modding{

    @Instance
    public Modding instance;
    
    @SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)
    public static CommonProxy proxy;
    
    @EventHandler
    public static void preInit(FMLPreInitializationEvent event){
        GameRegistry.addSmelting(BlockInit.ORE_COPPER_BLOCK, new ItemStack(ItemInit.COPPER_INGOT), 0.2f);
    }
    @EventHandler
    public static void init(FMLInitializationEvent event){}
    @EventHandler
    public static void postInit(FMLPostInitializationEvent event){}
}

 

Please help me!!!

Edited by leosavi25
Link to comment
Share on other sites

Spoiler

 

public class BlockInit {

    public static final List<Block> BLOCKS = new ArrayList<Block>();


    public static final Block ORE_COPPER_BLOCK = new Ore("ore_copper");

}

 

 

Spoiler

public class ItemInit {

    public static final List<Item> ITEMS = new ArrayList<Item>();
    
    public static final Item COPPER_INGOT = new ItemBase("copper_ingot", CreativeTabs.MATERIALS);

}

Spoiler

@EventBusSubscriber

public class RegistryHandler{

@SubscribeEvent
    public static void onItemRegister(RegistryEvent.Register<Item> event){
        event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));
    }
    
    @SubscribeEvent
    public static void onBlockRegister(RegistryEvent.Register<Block> event){
        event.getRegistry().registerAll(BlockInit.BLOCKS.toArray(new Block[0]));
    }

}

 

Link to comment
Share on other sites

I saw it in a tutorial on Internet and if I run the code it work(I don't know how it works) : I have the copper block and the copper ingot, but when i put the copper ore in the furnace, it didn't work. I try to change the code to GameRegistry.addSmelting(ItemInit.COPPER_INGOT, new ItemStack(ItemInit.COPPER_INGOT), 0.2f); and it work because if I smelt a copper ingot it makes a Copper Ingot, I try to change also with Blocks.DIRT and it work but with BlockInit.ORE_COPPER_ORE it doesn't work

Link to comment
Share on other sites

I found where I add the ore copper and the copper ingot

Spoiler

public class Ore{

  public Ore(String name){
        setRegistryName(name);
        setUnlocalizedName(name);
        
        BlockInit.BLOCKS.add(this);
        ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }

}

Spoiler

public ItemBase(String name, CreativeTabs tab){
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(tab);

ItemInit.ITEMS.add(this);

}

 

Edited by leosavi25
Link to comment
Share on other sites

1 minute ago, leosavi25 said:

But if it isn't static I can't have access of it in other classes

How are you structuring your mod overall? Are you registering each item in their specific class, or do you have a main class like "ModItem" or "ModBlocks" where you list them all? It's unclear from the code you've given us.

Follow these rules when talking to me, and we'll get along fine.

1).I know Java fairly well. I don't know as much about modding. They are not the same, don't compare them.

2). I consider myself to always be learning. I make mistakes, you make mistakes. Who doesn't?

3). Insult me, and I will leave the thread. I have a real life, I don't have time to throw petty insults in a Minecraft Modding forum.

 

ModMCdl - Co-Founder and Director of Design for Artemis Game Studios

Link to comment
Share on other sites

44 minutes ago, leosavi25 said:
  Reveal hidden contents

 

public class BlockInit {

    public static final List<Block> BLOCKS = new ArrayList<Block>();


    public static final Block ORE_COPPER_BLOCK = new Ore("ore_copper");

}

 

 

  Reveal hidden contents

public class ItemInit {

    public static final List<Item> ITEMS = new ArrayList<Item>();
    
    public static final Item COPPER_INGOT = new ItemBase("copper_ingot", CreativeTabs.MATERIALS);

}

  Reveal hidden contents

@EventBusSubscriber

public class RegistryHandler{

@SubscribeEvent
    public static void onItemRegister(RegistryEvent.Register<Item> event){
        event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));
    }
    
    @SubscribeEvent
    public static void onBlockRegister(RegistryEvent.Register<Block> event){
        event.getRegistry().registerAll(BlockInit.BLOCKS.toArray(new Block[0]));
    }

}

A Block/Item Init class where I put all blocks and Items and a RegistryHandler that register all Block and Item.

 

Edited by leosavi25
Link to comment
Share on other sites

25 minutes ago, leosavi25 said:

ok but what I have to do exactly?

Follow these steps and everything will work out:

1) Go learn Java

2) Come back and look at your code

3) Profit

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

This is what you need to do:

2 hours ago, diesieben07 said:

Do not create your items in a static initializer.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

22 hours ago, Draco18s said:

This is what you need to do:

I dont't think that this is the problem: if I change BlockInit.ORE_COPPER_BLOCK with ItemInit.COPPER_INGOT and I put the Copper Ingot in the furnace it works and if I change it with Blocks.DIRT and I put a dirt block in the furnace it works. It doesn't work with BlockInit.ORE_COPPER_BLOCK. I try also to create another block and it doesn't work too. Could it be the BlockInit class that have some problem?

Link to comment
Share on other sites

On 1/15/2018 at 7:08 AM, leosavi25 said:

public class BlockInit {

    public static final List<Block> BLOCKS = new ArrayList<Block>();


    public static final Block ORE_COPPER_BLOCK = new Ore("ore_copper");

}

 

2 minutes ago, leosavi25 said:

Could it be the BlockInit class that have some problem?

Yes.

Specifically:

On 1/15/2018 at 7:45 AM, diesieben07 said:

Do not create your items in a static initializer.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Spoiler

public class BlockInit {

    public static final List<Block> BLOCKS = new ArrayList<Block>();


    public static final Block ORE_COPPER_BLOCK = new Ore("ore_copper");

}

Spoiler

public class Ore extends BlockOre{
    
    public Ore(String name){
        setRegistryName(name);
        setUnlocalizedName(name);
        
        BlockInit.BLOCKS.add(this);
        ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
    }

what mustn't be static? If BLOCKS or ORE_COPPER_BLOCK are not static it give me error in Ore class

Link to comment
Share on other sites

That is not what D7 said.

Do not create your items in a static initializer.

 

He said nothing about having static fields. He said static initializer.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Preferably in the registry event. It must not happen in a static initializer because then Forge will not be able to detect that the code belongs to your mod and won't be able to set the registry name properly.

 

 

1 minute ago, diesieben07 said:

What for?

I did this but when I try to enter in a world it says that ore copper block and ore copper item miss

Link to comment
Share on other sites

I'll take a stab at this - sorry I'm pretty new to modding but I can answer the Java-ish related question for you.

 

When they say don't register in the static initializer, they mean that you shouldn't be creating the items as part of static initialization, which is what happens when you assign static fields a value as part of the declaration.  In your code:

 public class BlockInit {
    public static final List<Block> BLOCKS = new ArrayList<Block>();

    public static final Block ORE_COPPER_BLOCK = new Ore("ore_copper");
} 

 

Both of those fields are static initializer fields.  Now, if you want to be able to access them statically but not initialize them statically, do something like this (which you can find by examining a number of mods source code on Github; see for example Vazkii's relatively clean Psi mod here):

public class BlockInit {
	public static final List<Block> BLOCKS = new ArrayList<Block>();
    public static final Block ORE_COPPER_BLOCK;  // DO NOT ASSIGN HERE!
      
    public static void preInit() {
      ORE_COPPER_BLOCK = new Ore("ore_copper");
      BLOCKS.add(ORE_COPPER_BLOCK); // Not sure why you are keeping the list, but if you want to add, you can do so here.
    }
  
    public static void init() {
      OreDictionary.registerOre("<your block ore dict id here>", new ItemStack(ORE_COPPER_BLOCK, 1, 0));
    }
}

 

Then, when handling the FMLPreInitializationEvent , call BlockInit.preInit().  When handling the FMLInitializationEvent , call BlockInit.init().

 

Hope this helps more than harms.  I strongly recommend following one of the other mods' patterns rather than rolling your own Vazkii's more or less follows the Forge documentation recommended guidelines, and it will help your future questions here if you have followed the documentation patterns so you won't have to explain yourself :)

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.