Thursday, 26 December 2013

Forge - Entities

Forge has a lot of code related to entities.  Broadly speaking it can be grouped roughly into
  • inanimate entities (minecarts, dropped items)
  • animals and mobs
  • the player


  • RenderingRegistry.registerEntityRenderingHandler (in conjunction with a Render class).   The renderer is bound directly to the object’s class definition, unlike Blocks no shared ID is required.
  • EntityRegistry.registerModEntity to add your entity to the game
  • EntityRegistry.addSpawn to control how your entity spawns randomly into the world, for example if you create a new Entity called Deer and you want them to spawn randomly in the woods/forest but not in the desert. 
  • DungeonHooks.addDungeonMob can be used to add your mob to mob spawners found in dungeons.
  • VillagerRegistry: contains a number of methods to add trading recipes and control the spawning of different villager types.

New methods and classes

  • Models: These contain a few classes related to rendering, I’m not actually sure if they’re ever used since it seems people nearly always use Techne to make new Entity rendering models and that appears to use vanilla Models only.
  • IEntityAdditionalSpawnData is used to add extra info to the mod’s spawn packet – the server provides the information, and the client can read it when the entity is spawned.
  • IExtendedEntityProperties - for storing extra permanent information in an Entity, i.e. information that will be saved to disk and reloaded.


  • EntityMinecart.registerCollisionHandler(IMinecartCollisionHandler) – superceded
  • GameRegistry.registerPlayerTracker - for tracking players – login, logout, respawn, dimension change.
  • WorldEvent.PotentialSpawns – control which entities are spawned in which location.
  • TickRegistry.registerTickHandler for PLAYER event – whenever an EntityPlayer’s onUpdate is called.
There is a whole stack of other events related to entities that I’m not going to list in detail  - look in the events package if you want to browse through them.  They can be broadly split into several types:
  • Rendering events
  • Change of state – eg spawning and despawning, death, picking up, discarding, throwing, use by player
  • Interactions with the player, other entities, items, especially attack, damage, targeting
  • Player actions – eg flying, falling, sleeping, left or right clicking
Personally I find it sometimes takes me a few tries to find the right event.  There is often some overlap between the different events but subtle differences too.  Usually boils down to guesswork from looking at the vanilla code, plus a bit of trial and error.

~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
     Forge summary - grouped by task
           World generation, loading, saving
           Miscellaneous - player input, rendering, GUI, chat, sounds

No comments:

Post a Comment