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

Hey guys,

i have a easy problem, but i do not know how to fix this..i want to make a crafting recipe with a custom block i made in another class, but i do not know how to define the ItemStack for it. At the moment it looks like this:

 

 

@EventHandler

public void preInit (FMLPreInitializationEvent event){

 

//Materialien

ItemStack stackTNT = new ItemStack(Blocks.tnt);

ItemStack stackDirt = new ItemStack(Blocks.dirt);

ItemStack stackBetterBomb = new ItemStack(BlockBetterBomb.getBlockFromItem(betterbomb));

 

//Craftingrezept, BetterBomb

GameRegistry.addRecipe(stackDirt,

"ttt",

"tdt",

"ttt",

't', stackTNT, 'd', stackBetterBomb);

}

 

 

And this is my Class for the Block:

 

 

public class BlockBetterBomb extends Block{

 

private final String name = "betterbomb";

 

public BlockBetterBomb() {

 

super(Material.tnt);

 

this.setUnlocalizedName("betterbomb");

this.setCreativeTab(CreativeTabs.tabAllSearch);

 

}

 

public String getName() {

 

return name;

}

 

public static Block getBlockFromName(Block betterbomb) {

 

return betterbomb;

}

 

public static Block getBlockFromItem(Block betterbomb) {

 

return betterbomb;

}

 

 

}

 

 

How do i manage, that my ItemStack takes this block?

Thanks for help,

 

bastianum :)

ItemStack stackBetterBomb = new ItemStack(BlockBetterBomb.getBlockFromItem(betterbomb));

 

What?  No!  Stop that.  Do it like you did your other two stacks.

 

ItemStack stackBetterBomb = new ItemStack(betterbomb)

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.

I am not really understanding what you want to do but if you want to get more than 1 piece of the item you created you do this:

 

GameRegistry.addRecipe(new ItemStack(YourClass.YourItem, 1)); //this number here is the output

 

But if you want your item to take part in the crafting recipe to create a new item then you do this:

 

GameRegistry.addRecipe(new ItemStack(YourClass.YourItem, 1), new Object[]{"ABA","ABA","ABA", 'A', YourClass.YourItem, 'B', Items.Stick});

 

YourClass.YourItem is used to define the items that you created in the mod.

While Items.Stick (Stick is an example) is used to define the minecraft items in the recipe.

 

Hope it helped, but if this isn't what you wanted then i am sorry. I told you i didn't understand what you actually wanted.

  • Author

ItemStack stackBetterBomb = new ItemStack(BlockBetterBomb.getBlockFromItem(betterbomb));

 

What?  No!  Stop that.  Do it like you did your other two stacks.

 

ItemStack stackBetterBomb = new ItemStack(betterbomb)

 

well, this doesn't work :( i still cannot craft with my betterbomb ItemStack, if i put the items into the workbench the way i did in the source code i do not get an output :(

  • Author

I am not really understanding what you want to do but if you want to get more than 1 piece of the item you created you do this:

 

GameRegistry.addRecipe(new ItemStack(YourClass.YourItem, 1)); //this number here is the output

 

But if you want your item to take part in the crafting recipe to create a new item then you do this:

 

GameRegistry.addRecipe(new ItemStack(YourClass.YourItem, 1), new Object[]{"ABA","ABA","ABA", 'A', YourClass.YourItem, 'B', Items.Stick});

 

YourClass.YourItem is used to define the items that you created in the mod.

While Items.Stick (Stick is an example) is used to define the minecraft items in the recipe.

 

Hope it helped, but if this isn't what you wanted then i am sorry. I told you i didn't understand what you actually wanted.

 

No, this is not what i asked..:D i know how to make a recipe, but in my case it does not work, i do not know how to define the ItemStack for my custom block 'betterbomb' :)

Have you registered your item into the mod?

Try registering it like this:

 

GameRegistry.registerItem(nameofyouritem, youritem.getUnlocalizedName()); ==> that's for items

GameRegistry.registerBlock(nameofyouritem, youritem.getUnlocalizedName()); ==> that's for blocks

 

It may also be a problem that your mod files organize is bad.

Try creating a main class file wich loads all of your mod classes.

Also add a Strings class wich will be loaded in the main class.

Add a class for block, for items ... and so on.

This will help your mod a lot and also won't mess up the code.

  • Author

I registered my Items and i have a main class as well as a class for my block i want to craft with.

  • Author

package com.bastianum.betterbombs;

 

import com.bastianum.betterbombs.blocks.BlockBetterBomb;

 

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.client.resources.model.ModelResourceLocation;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.asm.transformers.ItemStackTransformer;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.registry.GameRegistry;

 

@Mod(modid = BetterBombs.MODID)

public class BetterBombs {

 

// STANDARD

public static final String MODID = "betterbombs";

 

// ITEMS

// public static Item fireresistance_stone = new ItemFireresistancestone();

 

// BLOCKS

public static Block betterbomb = new BlockBetterBomb();

 

/**

* PREINIT

* */

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

 

// Materialien

ItemStack stackTNT = new ItemStack(Blocks.tnt);

ItemStack stackDirt = new ItemStack(Blocks.dirt);

ItemStack stackBetterBomb = new ItemStack(betterbomb);

 

// Craftingrezept, BetterBomb

GameRegistry.addRecipe(stackDirt, "ttt", "tdt", "ttt", 't', stackTNT,

'd', stackBetterBomb);

}

 

/**

* INIT

* */

 

@EventHandler

public void init(FMLInitializationEvent event) {

 

// Item-Rendering

/*

* GameRegistry.registerItem(fireSword, "fireSword");

* ModelResourceLocation res1 = new

* ModelResourceLocation("bastianum:fireSword", "inventory");

* Minecraft.getMinecraft

* ().getRenderItem().getItemModelMesher().register(fireSword, 0, res1);

*/

 

// Block-Rendering

GameRegistry.registerBlock(betterbomb, "betterbomb");

Minecraft

.getMinecraft()

.getRenderItem()

.getItemModelMesher()

.register(

Item.getItemFromBlock(betterbomb),

0,

new ModelResourceLocation(MODID + ":"

+ ((BlockBetterBomb) betterbomb).getName(),

"inventory"));

}

 

/**

* POSTINIT

* */

 

@EventHandler

public void postInit(FMLPostInitializationEvent event) {

 

}

}

 

package com.bastianum.betterbombs;

 

import com.bastianum.betterbombs.blocks.BlockBetterBomb;

 

import net.minecraft.block.Block;

import net.minecraft.client.Minecraft;

import net.minecraft.client.resources.model.ModelResourceLocation;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.Mod.EventHandler;

import net.minecraftforge.fml.common.asm.transformers.ItemStackTransformer;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.registry.GameRegistry;

 

@Mod(modid = BetterBombs.MODID)

public class BetterBombs {

 

// STANDARD

public static final String MODID = "betterbombs";

 

// ITEMS

// public static Item fireresistance_stone = new ItemFireresistancestone();

 

// BLOCKS

[glow=red,2,300]public static Block YourBlockName;[/glow]

 

/**

* PREINIT

* */

 

@EventHandler

public void preInit(FMLPreInitializationEvent event) {

 

// Materialien

YourBlockName = new [glow=red,2,300]YourBlockName(Material.yourmaterial).setBlockName("YourDesiredName").setCreativeTab(CreativeTabs.tabBlock);[/glow]

ItemStack stackDirt = new ItemStack(Blocks.dirt);

ItemStack stackBetterBomb = new ItemStack(betterbomb);

 

// Craftingrezept, BetterBomb

GameRegistry.addRecipe(stackDirt, "ttt", "tdt", "ttt", 't', stackTNT,

'd', stackBetterBomb);

}

 

/**

* INIT

* */

 

@EventHandler

public void init(FMLInitializationEvent event) {

 

// Item-Rendering

/*

* GameRegistry.registerItem(fireSword, "fireSword");

* ModelResourceLocation res1 = new

* ModelResourceLocation("bastianum:fireSword", "inventory");

* Minecraft.getMinecraft

* ().getRenderItem().getItemModelMesher().register(fireSword, 0, res1);

*/

 

// Block-Rendering

[glow=red,2,300]GameRegistry.registerBlock(YourBlockName, YourBlockName.getUnlocalizedName());[/glow]

Minecraft

.getMinecraft()

.getRenderItem()

.getItemModelMesher()

.register(

Item.getItemFromBlock(betterbomb),

0,

new ModelResourceLocation(MODID + ":"

+ ((BlockBetterBomb) betterbomb).getName(),

"inventory"));

}

 

/**

* POSTINIT

* */

 

@EventHandler

public void postInit(FMLPostInitializationEvent event) {

 

}

}

 

Change the glowing code.

Also if this doesn't work, is your model name the same as it was in Techne or whatever program you used to create that model. Did you create the lang folder? Did you add the blocks into the lang folder? Try removing the custom model.

 

If none of these works then i am afraid i can't help you :/

I am new myself to this.

  • Author

Thanks for trying man, but my items/blocks work well..i just need to know how i get this crafting recipe with my betterbomb compatible..:D

Thanks for trying man, but my items/blocks work well..i just need to know how i get this crafting recipe with my betterbomb compatible..:D

 

No, they don't work, because you're trying to define/declare them outside of the correct mod lifecycle.

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.

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.