RiftLibrary Blocks - Rift-Modding-Group/RiftLibrary GitHub Wiki

Steps

Creating a block in RiftLibrary requires the following steps:

  1. Creating your Blockbench Model
  2. Creating your Geo Model
  3. Creating your block class
  4. Creating your tile entity classes
  5. Creating and registering your renderer

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.

The Block Class

As far as Minecraft is concerned, blocks on their own are static objects, so their default models cannot be animated, unless you're somehow crazy enough to create each frame of its animation as a different model and put them all in one file in the resources/models/block/ folder (god forbid). Hence, animating models is handled through tile entities.

Anyways, make your Block class implement ITileEntityProvider and override its createNewTileEntity(World worldIn, int meta) method. Additionally, to ensure that your block doesn't get covered with a shadow or be completely black, override isOpaqueCube(IBlockState state) and isFullCube(IBlockState state) so that they return false. Finally, override getRenderType(IBlockState state) to make it return EnumBlockRenderType.ENTITYBLOCK_ANIMATED, to ensure we don't need to create a blockstate for it.

Here's an example class showing the result:

public class ExampleBlock extends Block implements ITileEntityProvider {
    public ExampleBlock() {
	super(Material.ROCK);
    }

    @Override
    public boolean hasTileEntity(IBlockState state) {
	return true;
    }

    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new ExampleTileEntity();
    }

    @Override
    public EnumBlockRenderType getRenderType(IBlockState state) {
	return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
	return false;
    }

    @Override
    public boolean isFullCube(IBlockState state) {
	return false;
    }
}

The Tile Entity class

Here, implement the IAnimatable interface, and override the two methods your IDE may ask you to. These methods are:

  • registerControllers(AnimationData data): This method is where animations for your tile entity are registered and controlled
  • getFactory(): 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 ExampleTileEntity extends TileEntity implements IAnimatable {
    private final AnimationBuilder SPIN_ANIM = new AnimationBuilder().addAnimation("move.spin", true);
    private final AnimationFactory factory = new AnimationFactory(this);

    public ExampleTileEntity() {
        super();
    }

    @Override
    public void registerControllers(AnimationData data) {
        data.addAnimationController(new AnimationController<>(this, "spinning", 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 tile entity, you need to assign a renderer to it. It must extend GeoBlockRenderer<T>, with T being the tile entity you're making the renderer for. Here's an example renderer class:

public class ExampleBlockRenderer extends GeoBlockRenderer<ExampleTileEntity> {
    public ExampleBlockRenderer() {
	super(new ExampleBlockModel());
    }
}

In the FMLPreInitializationEvent event of your mod, register your Tile Entity renderer as so:

ClientRegistry.bindTileEntitySpecialRenderer(ExampleTileEntity.class, new ExampleBlockRenderer());

About ItemBlocks...

Sure you may have made an animated block, but what about if it's still as an item in the inventory? Or as a dropped item? Well, you still have to give a model to its item form in one of two ways:

  1. The vanilla way, preferable for if its block form only animates under certain conditions
  2. The RiftLibrary way (if you want it animated as an item)