-
Notifications
You must be signed in to change notification settings - Fork 1
Integrating Your Mod with ENIM: The ENIM Framework
Note: Up-to-date documentation for APIs (such as the animation system) can be found in doc comments in the code which may be run through a documentation generator.
ENIM provides a framework for adding customizable entity models. However, by default no entities have custom models. Vanilla entities come bundled with ENIM itself, but mod-added entities need to be added separately. This page describes the ENIM entity render framework and the steps necessary to add custom models to the entities in your mod.
(package kvverti.enim.entity.state)
Under ENIM, entity renders contain a map relating the state of an entity to a model, similar to the BlockState system for blocks in vanilla. RenderState
s are exactly like IBlockState
s, except that they implement a different interface and do not contain the #getBlock()
method. To obtain a RenderState
, call getStateManager().getDefaultState()
in the render class and set the state properties appropriately.
Each of the base render classes provides a StateManager
through its getStateManager()
method. The StateManager
keeps track of the render's entitystates and associates each RenderState
with an EntityState
.
The StateManager
class methods are listed here. The getDefaultState()
and setDefaultState(RenderState)
methods will be of the most use to clients.
-
StateManager(IProperty<?>...)
: Constructs aStateManager
which uses the given properties for the render states. -
RenderState getDefaultState()
: Returns aRenderState
in the default configuration for this render. -
void setDefaultState(RenderState)
: Sets the defaultRenderState
to the configuration of the givenRenderState
. -
EntityState getState(RenderState)
: Returns theEntityState
associated with the givenRenderState
. Most clients should usegetCurrentEntityState()
in the render class instead of this method. -
ENIMModel getModel(RenderState)
: Returns the java model for the given state. The java model is used only for rendering and does not contain accessible information about the custom model. To get the custom model, usegetCurrentEntityState().model()
in the render class.
When creating an IProprty<T>
based on an enum, the enum must implement IStringSerializable
. This interface, EnumStringSerializable
, extends that interface and provides a default implementation of the getName()
method which returns the lowercase representation of the enum constant name.
(package kvverti.enim.entity)
The underpinnings of ENIM renders rest on this interface: ReloadableRender
. The interface allows for ENIM to reload renders and their models when the resources are reloaded. While you can implement this interface directly, ENIM provides a set of base classes to extend that implement the reloading functions of the interface.
- ENIMRender<T>: The base class for entity renders.
- LivingRender<T>: The base class for living entity renders.
- ENIMTileEntityRender<T>: The base class for tile entity renders.
The abstract class ENIMRender<T>
is the base class for all reloadable entity renders. All the functionality related to reloading the render and basic functionality to rendering is provided. To create a basic entity render, one need only to extend this class and implement the method getStateFromEntity(T)
, which returns a RenderState
based on the properties of the passed entity.
The abstract class LivingRender<T>
is a subclass of ENIMRender<T>
for use with living entities (those which extend EntityLivingBase
). The LivingRender<T>
class contains additional functionality related to the rendering of living entities, such as rendering potion effects, damage, and death colorings.
The abstract class ENIMTileEntityRender<T>
is the base class for all reloadable tile entity renders. This class is similar to the ENIMRender<T> class, but is for tile entities. To create a basic tile entity render, one need only extend this class and implement the method getStateFromTile(T)
, which returns a RenderState
based on the properties of the passed tile entity.
In addition to the base classes above, ENIM provides other classes for the most common implementations of renders.
-
BasicRender<T>
: Provides a basic implementation ofENIMRender<T>
for entities that do not have multiple states. -
BasicLivingRender<T>
: Provides a basic implementation ofLivingRender<T>
for entities that do not have multiple states. -
SignLikeRender<T>
: Provides a render implementation for sign-like tile entities, such as the sign and banner.
All the base render classes share certain methods that clients may use or override in determining the rendering for the entity. They are as follows:
-
StateManager getStateManager()
: Returns theStateManager
for this render. -
EntityState getCurrentEntityState()
: Returns theEntityState
that is rendered in this render tick. -
boolean shouldRender(T)
: Clients may override this method to control the circumstances under which the entity is rendered. -
void preRender(T, EntityInfo)
: Clients may override this method to perform any necessary logic before the entity is rendered. Important: subclasses must callsuper.preRender(entity, info)
before performing any custom logic. -
void postRender(T, EntityInfo)
: Clients may override this method to perform any necessary logic after the entity is rendered. Important: subclasses must callsuper.postRender(entity, info)
after performing any custom logic.
(package kvverti.enim.model)
This section describes the in-memory representation of custom entity models. See the ENIM Json Model Format for details on the resource pack side. The model system provides access to the models loaded from resource packs in a manner which mirrors the structure of custom models in resource packs. All properties are read-only and immutable; these classes cannot be used to change custom models. The main classes in the model system are given below:
- EntityState: Contains information from the entitystate file for the entity.
- EntityModel: Represents the entity model as loaded from the resources.
- ModelProperties: The model properties, such as nameplate height and held item positions.
-
ModelElement: An element in the
elements
tag of the model. -
Animation: An animation in the
animations
tag of a model.
The EntityState
class represents an entry in the states
tag of the entitystate file. It provides access to attributes defined in the entitystate file through its accessor properties.
-
model()
: The entity model, as an instance ofEntityModel
. -
texture()
: TheResourceLocation
used as the entity texture. Note that ENIM uses dynamically loaded textures so this location will not correspond to the location of the texture image in the resource path. -
size()
: The dimensions of the texture, as anint[]
of length2
. The dimensions may not always correspond to the dimensions of the texture image, for example in high-resolution resource packs. -
y()
: The rotation of the model around the vertical axis, as afloat
. -
scale()
: The scale of the model, as afloat
.
The EntityModel
class represents a complete model from the models directory in the resources. This model fully resolves the imports and overrides specified in the model file. Thus, the elements and animations returned through its accessor properties represent all of the elements and animations of the model, including imports.
-
properties()
: The entity properties, as an instance ofModelProperties
. -
elements()
: AnImmutableSet
of the model elements, as instances ofModelElement
. -
getElement(String)
: A convenience to get the model element with the given name. -
animations()
: AnImmutableMap
associating the different types of animations with their animations. The keys are of typeAnimation.Type
and values of typeAnimation
. The map only contains keys which are present in the model file, that is, are imported or explicitly defined animations.
This class contains the various model properties defined in the entity model file. Properties will be added or deprecated in this class when the model system adds or removes properties.
-
nameplate()
: The height at which the custom name of the entity is rendered, as afloat
. -
leftHand()
: The origin for items held in the left hand, as an OriginPoint. -
rightHand()
: The origin for items held in the right hand, as an OriginPoint.
OriginPoints associate a point in the render coordinate space with the name of a model element. The point will undergo the same transformations as its parent element.
-
parent
: The name of the parent element present in this model. -
coords
: The point of origin as aVec3f
.
The ModelElement class is a structure that contains the information for a single element of a model. Properties will be added or deprecated in this class when the model system adds or removes properties.
-
name()
: The element name, as aString
. -
parent()
: The name of the parent element of this element, as aString
. Returnsnull
if there is no parent. -
from()
: The lowest vertex of this element, as aVec3f
. -
to()
: The highest vertex, as aVec3f
. -
uv()
: The texture coordinates of the element, as anint[]
of length two. -
origin()
: The origin of transformation of the element, as aVec3f
. -
rotation()
: The rotation of the element in degrees, as aVec3f
. -
scale()
: The scale of the element, as afloat
. -
isTranslucent()
: Whether the element should be rendered as translucent. -
isHead()
: Whether this element represents a head.