I_Iz_Shahid Posted July 20, 2015 Posted July 20, 2015 Welcome back for yet another question that seems to have me stumped 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? Quote if(pain == 0) { gain = 0; }
Failender Posted July 20, 2015 Posted July 20, 2015 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 Quote
Anon10W1z Posted July 20, 2015 Posted July 20, 2015 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. Quote Maker of the Craft++ mod.
Failender Posted July 20, 2015 Posted July 20, 2015 sorry I expressed myself wrong. what i meant is that u can only pass one key and not two to get a value Quote
I_Iz_Shahid Posted July 20, 2015 Author Posted July 20, 2015 Ok, so I reviewed Maps and understand what you guys mean. But how will I go about adding the recipe now? will this work? mouldingList.put(Material, Result); mouldingList(Material, Result); Quote if(pain == 0) { gain = 0; }
Failender Posted July 20, 2015 Posted July 20, 2015 you could create a helper class that holds 2 input items and use that as map key Quote
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 I was thinking of doing that, but how would I return 2 itemstacks in the helper class? Quote if(pain == 0) { gain = 0; }
Failender Posted July 21, 2015 Posted July 21, 2015 1. why should you do that? 2. add two getter methods Quote
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 Could you please explain how getter methods would help, because I will still have to use a single itemstack for the key, am I right? (I want sample code ) Quote if(pain == 0) { gain = 0; }
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 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? Quote if(pain == 0) { gain = 0; }
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 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 Quote if(pain == 0) { gain = 0; }
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 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 Quote if(pain == 0) { gain = 0; }
I_Iz_Shahid Posted July 21, 2015 Author Posted July 21, 2015 All I need to know now is how do I split the recipekey back into its original itemstacks. Quote if(pain == 0) { gain = 0; }
Recommended Posts
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.