RiftLibrary Items - Rift-Modding-Group/RiftLibrary GitHub Wiki
Steps
Creating an item in RiftLibrary requires the following steps:
- Creating your Blockbench Model
- Creating your Geo Model
- Creating your item class
- Creating and registering your renderer
- Creating your item model
Steps #1 and #2 will not be covered on this page, instead visit their respective links for info. This page will focus on steps #3, #4, and #5. It also assumes that you have already made an item registry class. In case you somehow don't know or forgot, here's a quick example from the example mod. For the purposes of this tutorial, assume that ItemRegistry
is where the variable associated with the item is in, and EXAMPLE_ITEM
is a static final Item
variable that is an instance of ExampleItem
.
The Item Class
The first step is to implement the IAnimatable
interface on your item class, and override the two methods your IDE may ask you to. These methods are:
registerControllers(AnimationData data)
: This method is where animations for your entity are registered and controlledgetFactory()
: This method returns an instance of AnimationFactory
The final step is to define a new instance of AnimationFactory
as a global variable, and in its constructor put this
. Make getFactory()
return this global variable.
Here's an example class showing the result:
public class ExampleItem extends Item implements IAnimatable {
private final AnimationBuilder SPIN_ANIM = new AnimationBuilder().addAnimation("move.spin", true);
private final AnimationFactory factory = new AnimationFactory(this);
public ExampleItem() {
super();
}
@Override
public void registerControllers(AnimationData data) {
data.addAnimationController(new AnimationController<>(this, "flying", 0, this::spinAnimController));
}
private PlayState spinAnimController(AnimationEvent event) {
event.getController().setAnimation(SPIN_ANIM);
return PlayState.CONTINUE;
}
@Override
public AnimationFactory getFactory() {
return this.factory;
}
}
The Renderer
Like any other item, you need to assign a renderer to it. It must extend GeoItemRenderer<T>
, with T being the item you're making the renderer for. Here's an example renderer class:
public class ExampleItemRenderer extends GeoItemRenderer<ExampleItem> {
public ExampleItemRenderer() {
super(new ExampleItemModel());
}
}
In the ModelRegistryEvent
event of your mod, register your item renderer as so:
ItemRegistry.EXAMPLE_ITEM.setTileEntityItemStackRenderer(new ExampleItemRenderer());
The Item Model
Like any other non-RiftLibrary item, you still need to create an item model .json
in the resources/models/item
folder. Don't fret, this is only for defining the position and scale of your item when in your hand, inventory, or when on the ground. Otherwise, you'll get the ever-dreaded purple and black checkerboard texture.
Here's the item model for the Bomb example:
{
"parent": "builtin/entity",
"credit": "Made with Blockbench",
"display": {
"thirdperson_righthand": {
"rotation": [
75,
45,
0
],
"translation": [
0,
2.5,
0
],
"scale": [
0.375,
0.375,
0.375
]
},
"thirdperson_lefthand": {
"rotation": [
75,
45,
0
],
"translation": [
0,
2.5,
0
],
"scale": [
0.375,
0.375,
0.375
]
},
"firstperson_righthand": {
"rotation": [
0,
115,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"firstperson_lefthand": {
"rotation": [
0,
225,
0
],
"scale": [
0.4,
0.4,
0.4
]
},
"ground": {
"translation": [
0,
3,
0
],
"scale": [
0.25,
0.25,
0.25
]
},
"gui": {
"rotation": [
30,
137,
0
],
"translation": [
0,
-3.75,
0
],
"scale": [
0.625,
0.625,
0.625
]
},
"fixed": {
"translation": [
0,
-1.5,
0
],
"scale": [
0.5,
0.5,
0.5
]
}
}
}
Finally, in the ModelRegistryEvent
event of your mod, register your item model as so:
ModelLoader.setCustomModelResourceLocation(
ItemRegistry.EXAMPLE_ITEM,
0,
new ModelResourceLocation(YourMod.MODID+":exampleitem", "inventory")
);