Jump to content

[1.8] Custom Recipe Issue


I_Iz_Shahid

Recommended Posts

Welcome back for yet another question that seems to have me stumped :D

 

Anyways, I managed to make a custom furnace with a different set of recipes that use 2 items instead of one to produce one result, but I have one issue. I can't set the recipes, here is my recipes file:

 

 

package I_Iz_Shahids_Mods.net.RapierPlus.Recipes;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import I_Iz_Shahids_Mods.net.RapierPlus.Main;

import com.google.common.collect.Maps;

public class MoulderRecipes
{
    private static final MoulderRecipes mouldingBase = new MoulderRecipes();
    /** The list of moulding results. **/
    private final Map mouldingList = Maps.newHashMap();
    private final Map experienceList = Maps.newHashMap();

    public static MoulderRecipes instance()
    {
        return mouldingBase;
    }

    private MoulderRecipes()
    {
        addMouldingRecipe(
              new ItemStack(Main.bladeMould),
              new ItemStack(Items.iron_ingot),
              new ItemStack(Main.ironBlade), 0.7F);
        addMouldingRecipe(
                new ItemStack(Main.pommelMould),
                new ItemStack(Items.iron_ingot),
                new ItemStack(Main.ironPommel), 0.7F);
    }

    public void addMouldingRecipe(ItemStack Mould, ItemStack Material,
          ItemStack Result, float parExperience)
    {
    	mouldingList.put(Mould, Material, Result);
        //experienceList.put(Result, Float.valueOf(parExperience));
    }

    /**
     * Returns the moulding result of an item.
     */
    public ItemStack getMouldingResult(ItemStack parItemStack)
    {
        Iterator iterator = mouldingList.entrySet().iterator();
        Entry entry;

        do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry)iterator.next();
        }
        while (!areItemStacksEqual(parItemStack, (ItemStack)entry
              .getKey()));

        return (ItemStack)entry.getValue();
    }

    private boolean areItemStacksEqual(ItemStack parItemStack1, 
          ItemStack parItemStack2)
    {
        return parItemStack2.getItem() == parItemStack1.getItem() 
              && (parItemStack2.getMetadata() == 32767 
              || parItemStack2.getMetadata() == parItemStack1
              .getMetadata());
    }

    public Map getMouldingList()
    {
        return mouldingList;
    }

    public float getMouldingExperience(ItemStack parItemStack)
    {
        Iterator iterator = experienceList.entrySet().iterator();
        Entry entry;

        do
        {
            if (!iterator.hasNext())
            {
                return 0.0F;
            }

            entry = (Entry)iterator.next();
        }
        while (!areItemStacksEqual(parItemStack, 
              (ItemStack)entry.getKey()));

        return ((Float)entry.getValue()).floatValue();
    }
}

 

 

now the problem is exactly at this line:

 

mouldingList.put(Mould, Material, Result);

 

This yields an error that the put function can only take 2 objects as input, but I can't find a replacement function. How do I do this?

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

you cant use a map that way. read a doc how maps work and u will see that they store one key for one value. not two keys for one value

This is wrong.

map.put("Hello", 1);
map.put("Goodbye", 1);

Works perfectly fine.

map.get("Hello"); //1
map.get("Goodbye"); //2

However he doesn't know how to use the syntax properly.

Maker of the Craft++ mod.

Link to comment
Share on other sites

I am completely lost here  :(

 

What I get so far is that

1. I need to set the key to use both itemstacks

2. I should use a different class to do that, but I don't know how that class should be structured, does anyone have a tutorial I can check out?

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

Using this I get this crash code:

 

 

 

[08:05:57] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking block entity
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:781) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
Caused by: java.lang.ClassCastException: I_Iz_Shahids_Mods.net.RapierPlus.Recipes.RecipeKey cannot be cast to net.minecraft.item.ItemStack
at I_Iz_Shahids_Mods.net.RapierPlus.Recipes.MoulderRecipes.getMouldingResult(MoulderRecipes.java:63) ~[MoulderRecipes.class:?]
at I_Iz_Shahids_Mods.net.RapierPlus.Blocks.Entity.TileEntityMoulder.canMould(TileEntityMoulder.java:801) ~[TileEntityMoulder.class:?]
at I_Iz_Shahids_Mods.net.RapierPlus.Blocks.Entity.TileEntityMoulder.update(TileEntityMoulder.java:751) ~[TileEntityMoulder.class:?]
at net.minecraft.world.World.updateEntities(World.java:1879) ~[World.class:?]
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:587) ~[WorldServer.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:775) ~[MinecraftServer.class:?]
... 4 more

 

 

 

apparently the crash is at this segment of the recipe code:

 

 

 

public ItemStack getMouldingResult(ItemStack parItemStack)
    {
        Iterator iterator = mouldingList.entrySet().iterator();
        Entry entry;

        do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry)iterator.next();
        }
        while (!areItemStacksEqual(parItemStack, (ItemStack)entry
              .getKey()));

        return (ItemStack)entry.getValue();
    }

    private boolean areItemStacksEqual(ItemStack parItemStack1, 
          ItemStack parItemStack2)
    {
        return parItemStack2.getItem() == parItemStack1.getItem() 
              && (parItemStack2.getMetadata() == 32767 
              || parItemStack2.getMetadata() == parItemStack1
              .getMetadata());
    }

 

 

 

I think its cause it cant compare the entry and parItemStack2 which shouldn't happen

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

What I get from here is that instead of:

 

do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry)iterator.next();
        }
        while (!areItemStacksEqual(parItemStack, (ItemStack)entry
              .getKey()));

        return (ItemStack)entry.getValue();

 

 

do this:

 

 

do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry)iterator.next();
        }
        while (!areItemStacksEqual((ItemStack) parItemStack, (ItemStack)entry
              .getKey()));

        return (ItemStack)entry.getValue();

 

 

but when I do this, then I get this error code:

 

 

 

 

[08:39:48] [server thread/ERROR]: Encountered an unexpected exception

net.minecraft.util.ReportedException: Ticking block entity

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:781) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]

at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]

Caused by: java.lang.ClassCastException: I_Iz_Shahids_Mods.net.RapierPlus.Recipes.RecipeKey cannot be cast to net.minecraft.item.ItemStack

at I_Iz_Shahids_Mods.net.RapierPlus.Recipes.MoulderRecipes.getMouldingResult(MoulderRecipes.java:62) ~[MoulderRecipes.class:?]

at I_Iz_Shahids_Mods.net.RapierPlus.Blocks.Entity.TileEntityMoulder.canMould(TileEntityMoulder.java:801) ~[TileEntityMoulder.class:?]

at I_Iz_Shahids_Mods.net.RapierPlus.Blocks.Entity.TileEntityMoulder.update(TileEntityMoulder.java:751) ~[TileEntityMoulder.class:?]

at net.minecraft.world.World.updateEntities(World.java:1879) ~[World.class:?]

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:587) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:775) ~[MinecraftServer.class:?]

... 4 more

 

 

if(pain == 0)

{

   gain = 0;

}

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.