AzureLib

Updating Guide: 2.x to 3.x

Updating Blocks Entities

A guide for converting AzureLib/Geckolib Blocks Entities to the new 3.x code.

Block Entities Class

Old Block Entity class in AzureLib/GeckolibNew 3.x Block Entity class
public class ExampleBE extends BlockEntity implements GeoBlockEntity {
// Geckolib used GeckoLibUtil
private final AnimatableInstanceCache cache = AzureLibUtil.createInstanceCache(this);
public ExampleBE(BlockPos pos, BlockState blockState) {
super(YourEntityTypes.EXAMPLE_BE, pos, blockState);
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
// Where you registered your Controllers and such
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return cache;
}
}
public class ExampleBE extends BlockEntity {
// This is your class where you will setup the AzCommands/Animations you wish to play
public final ExampleBEDispatcher dispatcher;
public ExampleBE(BlockPos pos, BlockState blockState) {
super(YourEntityTypes.EXAMPLE_BE, pos, blockState);
// Create the instance of the class here to use later.
this.dispatcher = new ExampleBEDispatcher();
}
public static void tick(
Level level,
BlockPos pos,
BlockState state,
ExampleBE blockEntity
) {
if (blockEntity.level != null && level.isClientSide()) {
// This is where you now trigger an animation to play
blockEntity.animationDispatcher.spin(blockEntity);
}
}
}

As you can see here, you no longer need to implement a Geo interface to your class anymore and no longer register your controllers here. All that is needed now is to simply implement a Dispatcher, which we will cover below.

Animations

Old AzureLib/Geckolib Controller/Animation registrationNew 3.x Controller/Animation registration
private static final RawAnimation SPINNING = RawAnimation.begin().thenLoop("spinning");
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
controllers.add(
new AnimationController<>(this, "base_controller", 0,
state -> PlayState.CONTINUE).triggerableAnim(
"spinning",
SPINNING
)
);
}
public class ExampleBEAnimator extends AzBlockAnimator<ExampleBE> {
private static final ResourceLocation ANIMATIONS = ResourceLocation.fromNamespaceAndPath(
YOUR_MOD_ID,
"animations/item/examplebe.animation.json"
);
@Override
public void registerControllers(AzAnimationControllerContainer<ExampleBE> animationControllerContainer) {
animationControllerContainer.add(
AzAnimationController.builder(this, "base_controller")
.build()
);
}
@Override
public @NotNull ResourceLocation getAnimationLocation(ExampleBE animatable) {
return ANIMATIONS;
}
}
public class ExampleBEDispatcher {
private static final AzCommand SPINNING_COMMAND = AzCommand.create(
"base_controller",
"spinning",
AzPlayBehaviors.LOOP
);
public void spin(BlockEntity entity) {
SPINNING_COMMAND.sendForItem(entity, itemStack);
}
}

Rendering

Old AzureLib/Geckolib RendererNew 3.x Renderer
public class ExampleBERenderer extends GeoBlockRenderer<ExampleBE> {
public ExampleBERenderer() {
super(new DefaultedBlockGeoModel<>(ResourceLocation.fromNamespaceAndPath(
YOUR_MOD_ID, "examplebe"
)));
}
}
public class ExampleBERenderer extends AzBlockEntityRenderer<ExampleBE> {
private static final ResourceLocation GEO = ResourceLocation.fromNamespaceAndPath(
YOUR_MOD_ID,
"geo/block/examplebe.geo.json"
);
private static final ResourceLocation TEX = ResourceLocation.fromNamespaceAndPath(
YOUR_MOD_ID,
"textures/block/examplebe.png"
);
public ExampleBERenderer() {
super(
AzBlockEntityRendererConfig.<ExampleBE>builder(GEO, TEX)
.setAnimatorProvider(ExampleBEAnimator::new).build()
);
}
}

This is where you will now register the ResourceLocation model and texture of your armor and you register your ExampleBEAnimator.

Registering

This has not changed for Block Entities, please refer to your mod loader for how to register block entities and the block entities renderer.