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

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?

  • 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

  • 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.

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.