Jump to content

[1.7] Any Item In Crafting Recipe


tattyseal

Recommended Posts

Hello.

 

So basically I want to be able to craft my block with any blocks, then use a CraftingEvent to check if it is valid for my block.

 

So I want it to be like:

 

BDB

 

B being the block

D being my block

 

But I cannot figure out how to make it B to be any block, does anyone know how to do this?

Link to comment
Share on other sites

Code

 

 

package org.db.block;

 

import net.minecraft.block.Block;

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.item.ItemBlock;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

 

import org.db.DynamicBlocks;

 

public class GlassRecipe implements IRecipe

{

 

@Override

public boolean matches(InventoryCrafting i, World w)

{

if(i != null && i.getStackInSlot(0) != null && i.getStackInSlot(1) != null && i.getStackInSlot(2) != null && i.getStackInSlot(0).getItem() instanceof ItemBlock && DynamicGlass.isBlockValidForInv(i.getStackInSlot(0)) && i.getStackInSlot(2).getItem() instanceof ItemBlock && DynamicGlass.isBlockValidForInv(i.getStackInSlot(2)))

{

ItemStack is = i.getStackInSlot(1);

 

if(is != null && is.getItem() != null && is.getItem().getUnlocalizedName() == DynamicBlocks.dynGlass.getUnlocalizedName())

{

return true;

}

}

return false;

}

 

@Override

public ItemStack getCraftingResult(InventoryCrafting i)

{

ItemStack is = new ItemStack(DynamicBlocks.dynGlass, 1);

 

NBTTagCompound tag = new NBTTagCompound();

 

tag.setInteger("meta", Block.getIdFromBlock(Block.getBlockFromName(i.getStackInSlot(0).getUnlocalizedName())));

tag.setInteger("blockMeta", Block.getIdFromBlock(Block.getBlockFromName(i.getStackInSlot(2).getUnlocalizedName())));

 

is.stackTagCompound = tag;

 

return is;

}

 

@Override

public int getRecipeSize()

{

return 9;

}

 

@Override

public ItemStack getRecipeOutput()

{

return null;

}

 

}

 

Main mod file in preInit:

 

GameRegistry.addRecipe(new GlassRecipe());

 

 

 

 

But the recipe does not work ingame

Link to comment
Share on other sites

s.getItem().getUnlocalizedName() == DynamicBlocks.dynGlass.getUnlocalizedName()
You can't compare strings like that.

 

Block.getBlockFromName(i.getStackInSlot(0).getUnlocalizedName())
WHAT?

 

I got it working

 

CODE:

 

 

package org.db.block;

 

import net.minecraft.block.Block;

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.item.ItemBlock;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.world.World;

 

import org.db.DynamicBlocks;

 

public class DynamicBlockRecipe implements IRecipe

{

 

@Override

public boolean matches(InventoryCrafting i, World w)

{

if(i != null && i.getStackInSlot(0) != null && i.getStackInSlot(1) != null && i.getStackInSlot(2) != null && i.getStackInSlot(0).getItem() instanceof ItemBlock && DynamicBlock.isBlockValidForInv(i.getStackInSlot(0)) && i.getStackInSlot(2).getItem() instanceof ItemBlock && DynamicBlock.isBlockValidForInv(i.getStackInSlot(2)))

{

ItemStack is = i.getStackInSlot(1);

 

if(is != null && is.getItem() != null && is.getItem().getUnlocalizedName().contains(DynamicBlocks.dynBlock.getUnlocalizedName()))

{

return true;

}

}

return false;

}

 

@Override

public ItemStack getCraftingResult(InventoryCrafting i)

{

ItemStack is = new ItemStack(DynamicBlocks.dynBlock, 1);

 

NBTTagCompound tag = new NBTTagCompound();

 

tag.setInteger("meta", Block.getIdFromBlock(Block.getBlockFromItem(i.getStackInSlot(0).getItem())));

tag.setInteger("blockMeta", Block.getIdFromBlock(Block.getBlockFromItem(i.getStackInSlot(2).getItem())));

 

is.stackTagCompound = tag;

 

return is;

}

 

@Override

public int getRecipeSize()

{

return 9;

}

 

@Override

public ItemStack getRecipeOutput()

{

return null;

}

 

}

 

 

 

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.