Thursday 26 December 2013

Forge - Items

An overview of the Forge code related to Items.  Note – EntityItems (i.e. Items which have been thrown onto the ground) are not covered here, see Entities instead.

Registries

  • GameRegistry.registerItem is used to register your item.  In some cases, you may have a single Item which represents different things depending on the damage value – for example ItemCloth (wool), which uses the damage value to represent the colour of the wool.  In this case use GameRegistry .registerCustomItemStack to register the ItemStack instead of the Item.
    In general, for an ItemBlock (Item which corresponds to a Block, eg ItemLeaves and BlockLeaves) you shouldn’t register it separately, instead you should supply it to GameRegistry.registerBlock when you register the corresponding Block.
    GameRegistry.findItem can be used to find the Item corresponding to a given name.
  • MinecraftForgeClient.registerItemRenderer (in conjunction with an IItemRenderer class). MinecraftForgeClient binds the IItemRenderer to the item ID.
    There is a special registry for rendering armour. The vanilla code is restricted to a predetermined list of armour types (“prefixes”) - "leather", "chainmail", "iron", "diamond", "gold". You can add your own (eg “lycra”) using
    RenderingRegistry.addNewArmourRendererPrefix
    When an entity wearing your armour is rendered, it will then use a texture of the form lycra_boots.png, lycra_leggings.png, etc. (This can also be achieved using Item.getArmorTexture, which is probably a better way to be honest).
  • MinecraftForge. addGrassSeed (and . addGrassPlant  for the corresponding Block) are used to add new types of grass.
  • MinecraftForge has a several methods used to add new tools and control their effectiveness against different blocks, in particular setToolClass and setBlockHarvestLevel.
  • LanguageRegistry.addNameForObject – allows you to add a displayed name for your Items and ItemStacks.  Apparently it’s better to use a Language Pack instead of this registry.  I haven’t tried those yet so I don’t know.
  • GameRegistry.addRecipe (shaped, shapeless) lets you add custom recipes for crafting items.
  • GameRegistry.addSmelting, GameRegistry.registerFuelHandler (with IFuelHandler) – for controlling how furnaces make use of your Items- allows you to add custom smelting recipes (eg smelting iron ore to ingots) or add custom fuels (in addition to coal, wood, etc).

When registering crafting recipes or smelting recipes, use OreDictionary.WILDCARD_VALUE for ItemStacks where any damage value will match (eg for a recipe using wool (ItemCloth) where any colour can be used).

Utility functions

  • EnumHelper (and EnumHelperClient for use on client-side only)– can be used to add extra elements to the various vanilla enums, for example vanilla EnumToolMaterial which has WOOD, STONE, IRON, EMERALD (diamond), and GOLD, to which you could add for example OVERCOOKED_SPAGHETTI.

New methods and classes

  • Item has many methods added to let mods change behaviour more easily – when dropped, used (eaten), used on entities or blocks, rendering, armor, potions, enchantment, They are defined after the comment in the Item code
    /*===========Forge Start ========*/.
  • ISpecialArmor – ItemArmor classes call the functions in this interface when calculating damage reduction – if you define your Item to implement ISpecialArmor, the appropriate methods on your item will be called when damage reduction is being calculated.
  • IPlantable interface for plants
  • Ores: OreDictionary, ShapedOreRecipes, ShapelessOreRecipes - As far as I can tell, this lets you make recipes using ores provided by other mods, in particular BuildCraft.  Some vanilla examples of ore are iron, stone, wood.

Events

  • GameRegistry.registerPickupHandler – when player picks up an item, superceded by EntityItemPickupEvent.
  • ItemTossEvent  - when the item is about to enter the world (discarded by player)
  • FillBucketEvent – when a bucket is filled (click on water, lava etc) or emptied.
  • ItemTooltipEvent – when your cursor is hovering over an item, to let you customise the ToolTip text that appears.
  • PlayerDestroyItemEvent – whenever an item is destroyed / used up.
  • UseHoeEvent – player uses a hoe tool
  • OreRegisterEvent
  • GameRegistry.registerCraftingHandler (ICraftingHandler) for when an item is crafted or smelted.
  • PotionBrewedEvent


~Overview of Forge (and what it can do for you)
    Forge concepts
           Some general notes
           How Forge starts up your code (@Mod, @SidedProxy, etc)  
           Registering your classes
           Extra methods for vanilla base classes
           Events
     Forge summary - grouped by task
           Blocks
           Items
           TileEntities
           Entities
           World generation, loading, saving
           Miscellaneous - player input, rendering, GUI, chat, sounds

No comments:

Post a Comment