LKloosterman Posted August 30, 2016 Share Posted August 30, 2016 Alright, so I host a small server which a couple of friends and I play on pretty much every night, and during one of our sessions, we thought up that it would be cool if we had some sort of currency system as we have sort of a town-type game with a lot of bartering. Being a pretty experienced modder, I decided I'd just make a super simple currency mod, but it turns out, even the simplest of mods gives me trouble. I added three items, those being copper, silver, and gold coins. I decided on making simple shapeless crafting recipes in order to switch between them, here's what I have: //1 Silver Coin -> 5 Copper Coins GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); //5 Copper Coins -> 1 Silver Coin GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); //1 Gold Coin -> 5 Silver Coins GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), ModItems.gold_coin); //5 Silver Coins -> 1 Gold Coin GameRegistry.addShapelessRecipe(new ItemStack(ModItems.gold_coin), new ItemStack(ModItems.silver_coin, 5)); As you can see, my plan was to have 5 Copper Coins be equal to 1 Silver Coin, 5 Silver Coins to 1 Gold Coin, and then be able to reverse this by using 1 Gold Coin to equal 5 Silver Coins, and 1 Silver Coin to equal 1 Copper Coins. This seemed fine to me and I tested it, and actually almost released it but for one bug. When I place 1 Copper Coin in the crafting area, it outputs 1 Silver coin. If I change the line: GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); to: GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 5), new ItemStack(ModItems.copper_coin, 5)); inserting 1 Copper Coin outputs 5 Silver coins, even though I told the recipe to use 5 Copper Coins. Now comes the weird part... if I place 1 Silver Coin it does not output 1 Gold Coin like I thought it would, that only happens if I take out this part: GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); I searched Google for information on how the ShaplessRecipes method works, and even looked at the ItemStack class to see if I was using the ItemStack(ItemIn, amount) method wrong but I couldn't see anything that would explain this... Let me know what I might be doing wrong, I'm here to learn. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 Recipes input do not care about stacksize it assumes it was 1. So you need to add ModItems.silvercoin 5 times in an Object[] (I think). Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 Recipes input do not care about stacksize it assumes it was 1. So you need to add ModItems.silvercoin 5 times in an Object[] (I think). I tried that but what happens is the 5 coins then need to be spread out in the crafting area, instead of being able to be used in a stack of 5. This way, it can be used in the player's inventory. Quote Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 The one part that continues to baffle me is that it works for the silver coins without problem, until I remove GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 Recipes input do not care about stacksize it assumes it was 1. So you need to add ModItems.silvercoin 5 times in an Object[] (I think). I tried that but what happens is the 5 coins then need to be spread out in the crafting area, instead of being able to be used in a stack of 5. This way, it can be used in the player's inventory. Like I said the Crafting System doesn't work that way. If you notice all vanilla recipes are in stacks of 1. If you want it to be done that way, you will need to make your own crafting. And override the vanilla one, meaning you need to override the players inventory or edit it in some way. The one part that continues to baffle me is that it works for the silver coins without problem, until I remove GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); What? What works? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 What? What works? The Silver Coins work as I expected, when I add one it outputs a Copper Coin, same for if I put in 2, 3, and 4 in a stack, and then when I add a fifth to the stack and put it in the crafting table, the stack of 5 Silver Coins outputs one Gold Coin. It's just the Copper Coin that isn't working. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 What? What works? The Silver Coins work as I expected, when I add one it outputs a Copper Coin, same for if I put in 2, 3, and 4 in a stack, and then when I add a fifth to the stack and put it in the crafting table, the stack of 5 Silver Coins outputs one Gold Coin. It's just the Copper Coin that isn't working. So what you are saying is that you put a stack of 5 silver coins into the crafting slots and it outputs 1 gold coin and takes all 5 silver coins? But it doesn't for copper? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 So what you are saying is that you put a stack of 5 silver coins into the crafting slots and it outputs 1 gold coin and takes all 5 silver coins? But it doesn't for copper? Yessir. That's why I'm confused When I take away GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); The Silver Coins do the exact same thing as the Copper Quote Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 I'm thinking it's because the crafting recipe for 1 Silver Coin is made but not for one copper... So I need to make a recipe for 1 Copper Coin that outputs nothing or something so that it will work properly... Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 So what you are saying is that you put a stack of 5 silver coins into the crafting slots and it outputs 1 gold coin and takes all 5 silver coins? But it doesn't for copper? Yessir. That's why I'm confused When I take away GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); The Silver Coins do the exact same thing as the Copper Could you post the whole class for me? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 I just made 1 Copper Coin output 1 Gray Dye and now it works. I guess it'll work for now, it's only a simple mod anyway. Quote Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 Could you post the whole class for me? Sure, Which class? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 Could you post the whole class for me? Sure, Which class? Where you add the recipes and initialize the Items aka your main mod class. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 Where you add the recipes and initialize the Items aka your main mod class. I add the Recipes in my ModRecipes Class: package com.currencymod.init; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModRecipes { public static void registerRecipes() { addCraftingRecipes(); } private static void addCraftingRecipes() { //Shapeless recipes GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), ModItems.gold_coin); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.gold_coin), new ItemStack(ModItems.silver_coin, 5)); } } And I initialize the items in my ModItems class: package com.currencymod.init; import com.currencymod.item.ItemCurrency; import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModItems { //Items public static ItemCurrency copper_coin; public static ItemCurrency silver_coin; public static ItemCurrency gold_coin; static { copper_coin = registerItem(new ItemCurrency("copper_coin")); silver_coin = registerItem(new ItemCurrency("silver_coin")); gold_coin = registerItem(new ItemCurrency("gold_coin")); } private static <T extends Item> T registerItem(T item) { GameRegistry.register(item); return item; } } And here's my Main class, although I don't think it'll be too helpful: package com.currencymod.main; import com.currencymod.proxy.CommonProxy; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid = Main.MOD_ID, name = Main.MOD_NAME, version = Main.MOD_VERSION) public class Main { public static final String MOD_ID = "currencymod"; public static final String MOD_NAME = "Lars's Currency Mod"; public static final String MOD_VERSION = "1.0.0"; @SidedProxy(clientSide = "com.currencymod.proxy.ClientProxy", serverSide = "com.currencymod.proxy.ServerProxy") public static CommonProxy proxy; @Instance(MOD_ID) public static Main instance; @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); } @EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(event); } } Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 Where you add the recipes and initialize the Items aka your main mod class. I add the Recipes in my ModRecipes Class: package com.currencymod.init; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModRecipes { public static void registerRecipes() { addCraftingRecipes(); } private static void addCraftingRecipes() { //Shapeless recipes GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), ModItems.silver_coin); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin, 1), new ItemStack(ModItems.copper_coin, 5)); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), ModItems.gold_coin); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.gold_coin), new ItemStack(ModItems.silver_coin, 5)); } } And I initialize the items in my ModItems class: package com.currencymod.init; import com.currencymod.item.ItemCurrency; import net.minecraft.item.Item; import net.minecraftforge.fml.common.registry.GameRegistry; public class ModItems { //Items public static ItemCurrency copper_coin; public static ItemCurrency silver_coin; public static ItemCurrency gold_coin; static { copper_coin = registerItem(new ItemCurrency("copper_coin")); silver_coin = registerItem(new ItemCurrency("silver_coin")); gold_coin = registerItem(new ItemCurrency("gold_coin")); } private static <T extends Item> T registerItem(T item) { GameRegistry.register(item); return item; } } And here's my Main class, although I don't think it'll be too helpful: package com.currencymod.main; import com.currencymod.proxy.CommonProxy; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @Mod(modid = Main.MOD_ID, name = Main.MOD_NAME, version = Main.MOD_VERSION) public class Main { public static final String MOD_ID = "currencymod"; public static final String MOD_NAME = "Lars's Currency Mod"; public static final String MOD_VERSION = "1.0.0"; @SidedProxy(clientSide = "com.currencymod.proxy.ClientProxy", serverSide = "com.currencymod.proxy.ServerProxy") public static CommonProxy proxy; @Instance(MOD_ID) public static Main instance; @EventHandler public void preInit(FMLPreInitializationEvent event) { proxy.preInit(event); } @EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(event); } } Ah the reason it doesn't work is because you already added a recipe that is bound to the Item silver_coin. And it will not override that. Which is why you need to do it the way I mentioned earlier. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 Ah the reason it doesn't work is because you already added a recipe that is bound to the Item silver_coin. And it will not override that. Which is why you need to do it the way I mentioned earlier. Nope, as mentioned before, the Silver Coin works perfectly, it's the copper coin that's the problem. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 Ah the reason it doesn't work is because you already added a recipe that is bound to the Item silver_coin. And it will not override that. Which is why you need to do it the way I mentioned earlier. Nope, as mentioned before, the Silver Coin works perfectly, it's the copper coin that's the problem. GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), "ModItems.silver_coin"); // An Item and not an ItemStack GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), "ModItems.gold_coin"); // Also an Item and not an ItemStack Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), "ModItems.silver_coin"); // An Item and not an ItemStack GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), "ModItems.gold_coin"); // Also an Item and not an ItemStack Tried changing it, doesn't change anything. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), "ModItems.silver_coin"); // An Item and not an ItemStack GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin , 5), "ModItems.gold_coin"); // Also an Item and not an ItemStack Tried changing it, doesn't change anything. That would have thrown all of the Errors the "" were there to highlight the object... How much Java do you know?/What IDE are you using? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
TheMasterGabriel Posted August 30, 2016 Share Posted August 30, 2016 I just made 1 Copper Coin output 1 Gray Dye and now it works. I guess it'll work for now, it's only a simple mod anyway. When Minecraft initializes all the recipes you add, it sorts the list. I suspect that your recipes work because of a quirk in how Java implements list sorting, but that's entirely unplanned. If you want to build a stable mod that is ensured to work for everybody, do it by creating an IRecipe instance. It's not that difficult. Just copy the ShapelessRecipes class and change the line in the matches method that checks for item and metadata equality to check for stack size as well. You can then just add your recipes like: GameRegistry.addRecipe(new MyCopiedShapelessRecipes(output stack, input stack)); However, if you aren't that familiar with Java programming, please take some time to learn at least the basics before jumping in blind. I promise that you will understand a lot more and we will be able to help you a lot more efficiently if you do. Quote Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 That would have thrown all of the Errors the "" were there to highlight the object... How much Java do you know?/What IDE are you using? Yeah, I know that, obviously I took the quotations out and put GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), new ItemStack(ModItems.silver_coin)); I didn't just copy what you wrote I know a moderate amount of Java, I've taken two HS Computer Science Courses and going to college for Software Development in 3 days, on top of this I've made several Java applications and mods before. I'm using Eclipse. Quote Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 When Minecraft initializes all the recipes you add, it sorts the list. I suspect that your recipes work because of a quirk in how Java implements list sorting, but that's entirely unplanned. If you want to build a stable mod that is ensured to work for everybody, do it by creating an IRecipe instance. It's not that difficult. Just copy the ShapelessRecipes class and change the line in the matches method that checks for item and metadata equality to check for stack size as well. You can then just add your recipes like: GameRegistry.addRecipe(new MyCopiedShapelessRecipes(output stack, input stack)); However, if you aren't that familiar with Java programming, please take some time to learn at least the basics before jumping in blind. I promise that you will understand a lot more and we will be able to help you a lot more efficiently if you do. Thanks, this is the type of answer I can use. And I am well-versed in Java, I just didn't know about the listing quirk. Thanks. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 30, 2016 Share Posted August 30, 2016 That would have thrown all of the Errors the "" were there to highlight the object... How much Java do you know?/What IDE are you using? Yeah, I know that, obviously I took the quotations out and put GameRegistry.addShapelessRecipe(new ItemStack(ModItems.copper_coin, 5), new ItemStack(ModItems.silver_coin)); I didn't just copy what you wrote I know a moderate amount of Java, I've taken two HS Computer Science Courses and going to college for Software Development in 3 days, on top of this I've made several Java applications and mods before. I'm using Eclipse. I'm sorry you wouldn't believe how many people get on here and ask how to do something really "simple" and it turns out that they don't know Java or even any O-O Language. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
LKloosterman Posted August 30, 2016 Author Share Posted August 30, 2016 I'm sorry you wouldn't believe how many people get on here and ask how to do something really "simple" and it turns out that they don't know Java or even any O-O Language. No problem, thanks for trying to help in any case. I guess I can serve as some faith restored to you for people asking questions on here. Quote Link to comment Share on other sites More sharing options...
Draco18s Posted August 30, 2016 Share Posted August 30, 2016 Something something, recipes still don't respect stack size something something. ItemStack oneCopperCoin = new ItemStack(ModItems.copper_coin, 1); GameRegistry.addShapelessRecipe(new ItemStack(ModItems.silver_coin), oneCopperCoin, oneCopperCoin, oneCopperCoin, oneCopperCoin, oneCopperCoin); Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
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.