Posted April 13, 201411 yr 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?
April 13, 201411 yr Author 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
April 13, 201411 yr Author 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; } }
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.