Jump to content

Entevily

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by Entevily

  1. diesieben07, I do appreciate your response. I understand that an Iterator was recommended. The only issue is I do not have experience with an iterator. I still have it in my comments in my code to look into using an iterator at a later point. I had not been able to get an iterator to remove the recipe so I decided not to use it until I understand it. I was, however, able to remove the recipes using the for-each loop. But thanks for your response.
  2. Thanks everyone for your awesome responses. All of you have great points. I ended up using the solution provided by RankShank. The only other thing I did was reverse the list before going through the remove phase so that I don't remove an index and then change the order of the rest and possibly accidently remove something else, like Draco18s had mentioned. Here is my final code: public static void removeRecipe(Item itemToRemove) { List<IRecipe> remove = new ArrayList(); for(IRecipe recipe : (List<IRecipe>)CraftingManager.getInstance().getRecipeList()) if(recipe.getRecipeOutput() != null && recipe.getRecipeOutput().getItem() == itemToRemove) remove.add(recipe); remove = Lists.reverse(remove); for(IRecipe r : remove) CraftingManager.getInstance().getRecipeList().remove(r); }
  3. [pre]I'm using Forge for Minecraft 1.8. So I'm trying to access the Crafting Manager and remove recipes for certain vanilla items. Below is the code I've got so far. [/pre] public static void removeRecipes() { CraftingManager cm = CraftingManager.getInstance(); List recipes = Lists.newArrayList(); recipes = cm.getRecipeList(); for(int i = 0; i < recipes.size(); i ++){ if(recipes.get(i) instanceof ShapedRecipes){ if(((ShapedRecipes)recipes.get(i)).getRecipeOutput().getItem().equals(Items.stone_axe)){ System.out.println("SoTrue"); cm.getRecipeList().remove(i); } } } } [pre] Problem is, that this prints the line "SoTrue" but it does not remove the item at that index. I removed the 'cm.getRecipeList().remove(i)' and replaced it with 'cm.getRecipeList().clear()' and all recipes go out the window. So what might I be doing wrong, when I'm just trying to remove, like in this example, the Stone Axe Recipe. I'm calling this method in the Init phase of my common proxy. Any assistance with this will be greatly appreciated. Thanks. [/pre]
  4. Thanks diesieben07. I found all sorts of references that said event.block when I was doing my research. Here's two examples: http://www.minecraftforge.net/wiki/Event_Reference http://www.minecraftforge.net/forum/index.php?topic=19820.0 But I appreciate your assistance in getting me a quick and accurate response. Thanks The_Wabbit for the example usage. I appreciate it guys. Have a good day.
  5. So, I created an event handler to check when a leaf is harvested and I want to drop some sticks. I found some help online and it got me to where I am now, but I am having trouble determining if the event.block is equal to Blocks.leaves. The issue is that event.block gives me an error : "block cannot be resolved or is not a field". I found no help online through searching and I'm not sure why this is happening. I tried attaching an image of how the error looks, but it wont let me. So here is my Event Handler, and my CommonProxy where I initialize the event bus. MyEventHandler.java import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class MyEventHandler { @SubscribeEvent public static void onDrops(BlockEvent.HarvestDropsEvent event){ if( event.block == Blocks.leaves && event.harvester.getHeldItem() != null && event.harvester.getHeldItem().getItem() == RealismItems.flintKnife){ event.drops.add(new ItemStack(Items.stick, 2)); } } } CommonProxy.java import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class CommonProxy { public void preInit(FMLPreInitializationEvent e) { RealismItems.createItems(); RealismBlocks.createBlocks(); } public void init(FMLInitializationEvent e) { RealismCrafting.initCrafting(); MinecraftForge.EVENT_BUS.register(new MyEventHandler()); } public void postInit(FMLPostInitializationEvent e) { } } Any assistance with this would be greatly appreciated.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.