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

I want to be able to craft my custom item with any other sword/pickaxe/etc and

set the output to the same item which it was crafted with, but add an NBT tag to it.

 

Is it possible to make a recipe with 1 certain item and other one just has to have a specific string in its name?

Hi

 

Yes it's possible.

 

You can add your own complicated recipes (eg like Fireworks recipes) by implementing IRecipe and registering it using GameRegistry.addRecipe(myRecipe implements IRecipe);

 

-TGG

  • Author

How to do that?

 

I have this code that i have written, but i don't know what to do now.

 

 

package com.supersalty.randomstuff;

 

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

 

import com.google.common.collect.Lists;

import com.supersalty.randomstuff.init.ModItems;

 

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.world.World;

 

public class RecipeStrangify implements IRecipe

{

 

private ItemStack recipeOutput;

 

public List recipeItems;

 

    public RecipeStrangify()

    {

      recipeItems.add(ModItems.strangifier);

    }

 

@Override

public boolean matches(InventoryCrafting inv, World w)

{

 

ArrayList arraylist = Lists.newArrayList(this.recipeItems);

 

        for (int i = 0; i < inv.getHeight(); ++i)

        {

            for (int j = 0; j < inv.getWidth(); ++j)

            {

                ItemStack itemstack = inv.getStackInRowAndColumn(j, i);

 

                if (itemstack != null)

                {

                    boolean flag = false;

                    Iterator iterator = arraylist.iterator();

 

                    while (iterator.hasNext())

                    {

                        ItemStack itemstack1 = (ItemStack)iterator.next();

 

                        if (itemstack.getItem() == itemstack1.getItem() && (itemstack1.getMetadata() == 32767 || itemstack.getMetadata() == itemstack1.getMetadata()))

                        {

                            flag = true;

                            arraylist.remove(itemstack1);

                            break;

                        }

                    }

 

                    if (!flag)

                    {

                        return false;

                    }

                }

            }

        }

 

        return arraylist.isEmpty();

 

}

 

@Override

public ItemStack getCraftingResult(InventoryCrafting inv)

{

 

for (int i = 0; i < 8; i++)

{

 

if (inv.getStackInSlot(i).getUnlocalizedName().contains("sword"))

{

 

ItemStack stck = inv.getStackInSlot(i);

stck.getTagCompound().setInteger("strange", 0);

stck.setStackDisplayName("strange");

recipeOutput = stck;

return stck;

 

}

 

}

 

return null;

 

}

 

@Override

public int getRecipeSize()

{

 

return this.recipeItems.size();

 

}

 

@Override

public ItemStack getRecipeOutput()

{

 

return this.recipeOutput;

 

}

 

@Override

public ItemStack[] getRemainingItems(InventoryCrafting inv)

{

 

ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

 

        for (int i = 0; i < aitemstack.length; ++i)

        {

            ItemStack itemstack = inv.getStackInSlot(i);

            aitemstack = net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack);

        }

 

        return aitemstack;

 

}

 

}

 

 

Also for some reason this code returns a nullPointerException on game launch.

 

Can you post the stacktrace so we can see what line is causing the NullPointerException?

 

I'm going to assume however that this line is going to cause problems:

 

for (int i = 0; i < 8; i++) 
{
    if (inv.getStackInSlot(i).getUnlocalizedName().contains("sword"))
    {
        ...
    }
}

inv.getStackInSlot(i) may return null there, and then you're calling null.getUnlocalizedName(). This may be causing your exception. you should add another null check there.

Also for some reason this code returns a nullPointerException on game launch.

 

Can you post the stacktrace so we can see what line is causing the NullPointerException?

 

I'm going to assume however that this line is going to cause problems:

 

for (int i = 0; i < 8; i++) 
{
    if (inv.getStackInSlot(i).getUnlocalizedName().contains("sword"))
    {
        ...
    }
}

inv.getStackInSlot(i) may return null there, and then you're calling null.getUnlocalizedName(). This may be causing your exception. you should add another null check there.

 

Lemme just add that this is NOT how you check for items.

 

for (ItemStack stack : stacks)
{
    if (stack != null)
    {
        Item item = stack.getItem()
        if (item instanceof ItemSword)
        {
        }
//OR
        if (item == Items.apple)
        {
        }
    }
}

1.7.10 is no longer supported by forge, you are on your own.

Another thing to add is don't expect every modder to use the standards, even though you should extend ItemSword there are definitely modders out there that do not. You should use what Ernio posted above, but note that if you want your mod to be completely compatible with certain mods, you may need to add specific support for the mods that don't use standard practices.

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.