Jump to content

McNutty

Forge Modder
  • Posts

    17
  • Joined

  • Last visited

Everything posted by McNutty

  1. I looked at all appearances of PlayerDestroyItemEvent, and nothing was relevant to my problem. According to a forum post and issue on Github, I'm not the only one struggling with this. I'll just use addItemStackToInventory instead. The only reason I'm doing this in the first place is to protect users from making a stupid mistake.
  2. Now I feel dumb. A week of searching Google, and I still couldn't find it. Followup question, It seems that the event fires immediately before the ItemStack is deleted. What this means for me is that I can't replace the destroyed item with another because the replacement is deleted immediately after. Is there a way around this beyond adding the new item to another inventory slot? I want the player to be left holding the replacement item after the break occurs.
  3. Is there a recommended/possible way to execute a function every time an item with durability breaks? I haven't been able to find an event that does this specifically, and it seems like checking item durability every tick would have a prohibitive runtime cost. To be clear, the Item itself won't be from my mod, so I can't override functions to accomplish this.
  4. When I load my mod, Forge is unable to match my mcmod.info to it. The file is in my project folder at the same level as the resources and java folders. I've searched around online, and the only answers I've found are to make sure that the json formatting is correct and that modid in mcmod.info matches that of the main class. I ran my mcmod.info through several json verifiers, and directly copied and pasted the modid. What else could the issue be? Swapper.java package com.mcnutty145.swapper; import net.minecraft.item.Item; import net.minecraft.util.RegistryNamespaced; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = Swapper.MODID, version = Swapper.VERSION) public class Swapper { public static final String MODID = "swapper"; public static final String VERSION = "0.0.1"; public static final RegistryNamespaced itemRegistry = GameData.getItemRegistry(); public static final Item item = new ItemArmorSwapper(); @EventHandler public void init(FMLInitializationEvent event) { GameRegistry.registerItem(item,"Swapper"); MinecraftForge.EVENT_BUS.register(new EventHandlerCommon()); } @EventHandler public void postInit(FMLInitializationEvent event){ } } mcmod.info [{ "modid": "swapper", "name": "Swapper", "description": "Making item management a little less of a hassle", "version": "${version}", "credits": "Code by McNutty145\nIcons by RandomAzn", "logoFile": "", "mcversion": "${mcversion}", "url": "", "updateUrl": "", "authors": ["McNutty145"], "parent": "", "screenshots": [], "dependencies": [] }]
  5. I am working on a convenience mod with an item that is supposed to take in other items and then switch between them like a swiss army knife. Picture the Enchiridion book binder, but for tools. The item works in most cases, but I have run into an issue whenever the contained item has an instanceof check. The easiest example is the fishing pole, which removes the hook if the current item is no longer an ItemFishingRod. Is there any way around this?
  6. Never mind, found a solution. I moved "getActiveItem(itemStack).onItemRightClick(itemStack, world, player);" outside of "if(!world.isRemote)". I didn't do enough testing to figure out why this works, just that it does.
  7. Never mind, found a solution. I moved "getActiveItem(itemStack).onItemRightClick(itemStack, world, player);" outside of "if(!world.isRemote)". I didn't do enough testing to figure out why this works, just that it does.
  8. Figured it out. Override getItemIndex, return IIcon that you want. That is the method that controls the inventory icon.
  9. I had a similar problem in my mod. In the constructor for my item, I included setTextureName("modname:texturename"). However, the icon in the inventory won't change to reflect the in-hand texture. modname is the name of the package containing your mod classes. For vanilla textures, use "minecraft" texturename is the name of your texture's image file without .png
  10. I think you are right, but I think that onUseItem is called after onItemRightClick is. I used a modified ItemSword class with print statements. Blocking is supposed to call onItemRightClick, onUseItem, and itemMaxUseDuration, but only calls itemMaxUseDuration of the contained Item. Right clicking with a hoe selected tills dirt with the proper animation, but that is because right clicking a block calls onItemUse.
  11. I am trying to make an item that contains tools and copies the texture and attributes of a selected contained tool. Everything works perfectly so far, except when a sword is selected, right clicking doesn't block. Here is the relevant method in my class: getActiveItem returns the Item of the active contained ItemStack. Using print statements, I have determined that "getActiveItem(itemStack).onItemRightClick(getActiveStack(itemStack), world, player);" is called but the active items onItemRightClick is not. Does anyone know why this is?
  12. I fixed everything you've mentioned, but I'm still having my original issue: when the sword is selected, the item doesn't block. I've done some debugging, and the onItemRightClick method of the contained sword is never called, even though the onItemRightClick of my item is called. Does anyone know why that is? onItemRightClick method is here: getActiveItem returns the Item of the currently active ItemStack, in this case the ItemSword item.
  13. You should try (!) to start a Dedicated Server with your mod. I don't have access to a server. Would the solution be to put if(!world.isRemote) inside the keyboard check?
  14. Overriding onItemUse worked for the hoe, thanks. I removed the exception handling; you are totally right that it was a bad idea. I don't know what you mean about the server checking the keyboard. It seems to work fine when I tested it in-game. Now I just need to figure out how to make it able to block when the sword is selected.
  15. Thanks for the thing about NBT. I noticed that would be a problem, but I didn't know how to fix it and was going to work on it later. I overrode getItemUseAction, but it still doesn't work. In the Item class, it says that getItemUseAction specifies the animation to use while right-clicking. My code doesn't execute the right-click function at all: the sword doesn't reduce damage and the hoe doesn't till dirt blocks. Edit: Ok, I just fixed and tested the NBT thing. Apart from that, I'm still at square one as far as accessing each item's right-click action. Here is my updated code:
  16. I'm trying to make an item that contains other items and has the attributes of a selected item within itself, sort of like a swiss army knife. I currently have an item that switches between a diamond hoe, shovel, pick, axe, and sword on shift right-click. The texture, damage value, and block mining attributes all switch to appropriate values when the item switches modes. The problem is that when the sword or hoe are selected, right-clicking does not do anything. I have already used print statements to prove that the onItemRightClick method for the appropriate item is called. Is there a way to do what I'm describing?
×
×
  • Create New...

Important Information

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