Posted July 29, 201213 yr In the next Forge release will it be possible to create an Interface for the following method in ItemStack.class: onFoodEaten. Want to do stuff when a item is eaten but don't want to edit those classes or ItemStack.class.
July 29, 201213 yr Rather then asking for the specific interface, tell us what you are trying to accomplish and we can often help you find a way.
July 29, 201213 yr Author I made a Thirst Mod with another friend. I just want that when you drink from a either a potion, milk bucket or soup to add stats to the thirst bar. I was previously able to do it by editing their respective classes but I figured out that with the following code I was able to add stats from ItemStack.class/onFoodEaten: if(getItem()) == Item.potion) { Utilities.getStats.addStats(10, 2f); } I don't want to edit any classes so thats why I was asking for an interface. Otherwise the only way is to edit ItemStack.class or the drink classes. Thanks
July 29, 201213 yr Author Why didn't I think of that earlier. Java Reflection works perfectly except for the conflict that pops up when the game is loading. The code for anyone else who may need it. try { Class item = Item.class; Field soup = item.getField("bowlSoup"); Item soupObj = (new ItemSoupMod(26, ).setIconCoord(8, 4).setItemName("mushroomStew"); soup.set(Item.bowlSoup, soupObj); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } You've got your thanks OverMind. Thanks a lot.
July 30, 201213 yr Why didn't I think of that earlier. Java Reflection works perfectly except for the conflict that pops up when the game is loading. The code for anyone else who may need it. try { Class item = Item.class; Field soup = item.getField("bowlSoup"); Item soupObj = (new ItemSoupMod(26, ).setIconCoord(8, 4).setItemName("mushroomStew"); soup.set(Item.bowlSoup, soupObj); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } You've got your thanks OverMind. Thanks a lot. as a general rule of thumb for programming like this, is it not acceptable to just use just one catch(Exception e) for the try-catch methods? i thought Exception caught all Errors?
July 30, 201213 yr You will not get that conflict if you null out the id cell of the itemList first. Do note, will not work with other mods that do the same, but unsure if any exist, so probably good for now.
July 30, 201213 yr Author I would I do that. (I'm not too good with arrays) but I will have a good look at it.
July 30, 201213 yr Item.java has an array of like 32000 in size or so, where all items are linked to by ID, just set the cell of the ID you are overwriting to null before you new your item.
July 30, 201213 yr I refresh after posting to check what I wrote for spelling and such again, and you had posted.
July 30, 201213 yr Author Okay done and all finished. Thanks so much! Heres the code for anyone: try { Item.itemsList[282] = null; Item.itemsList[373] = null; Item.itemsList[335] = null; Class item = Item.class; Field soup = item.getField("bowlSoup"); Item soupObj = (new ItemSoupMod(26, ).setIconCoord(8, 4).setItemName("mushroomStew"); soup.set(Item.bowlSoup, soupObj); Class itemPotion = ItemPotion.class; Field potion = itemPotion.getField("potion"); ItemPotion potionObj = (ItemPotion)(new ItemPotionMod(117)).setIconCoord(13, .setItemName("potion"); potion.set(ItemPotion.potion, potionObj); Field bucket = item.getField("bucketMilk"); Item bucketMilk = (new ItemBucketMilkMod(79)).setIconCoord(13, 4).setItemName("milk").setContainerItem(Item.bucketEmpty); bucket.set(Item.bucketMilk, bucketMilk); } catch (Exception e) { e.printStackTrace(); } Nulling it out means that this method will also work with Blocks without the game crashing. Sweet!
July 30, 201213 yr Correct, I do that to replace stock water with my own version. So do not touch water, I already do that.
July 30, 201213 yr Author Yeah okay, I'll be using it for the cauldron cause we have our own clean water cauldron. No more base classes edited!
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.