Jump to content

[Fabric 1.19.2] Can't get single play GeckoLib animations to work properly


Jipthechip

Recommended Posts

I'm trying to use Geckolib to have a block animation play when the block is right clicked, however it isn't working properly. When I right click the block the animation will play once, and then any subsequent times I right click, nothing happens.

Here's my Block class:

public class MagicChurnerBlock extends BlockWithEntity {

    protected MagicChurnerBlock(Settings settings) {
        super(settings);
    }

    @Nullable
    @Override
    public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
        return new MagicChurner(pos, state);
    }

    @Nullable
    @Override
    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
        return checkType(type, DiabolismEntities.MAGIC_CHURNER_BLOCKENTITY, MagicChurner::ticker);
    }

    @Override
    public BlockRenderType getRenderType(BlockState state) {
        return BlockRenderType.ENTITYBLOCK_ANIMATED;
    }

    @Override
    public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
        MagicChurner magicChurner = (MagicChurner) world.getBlockEntity(pos);
        if(magicChurner != null && world.isClient){
            magicChurner.turn();
        }
        return ActionResult.SUCCESS;
    }
}

And my Block Entity Class:

public class MagicChurner extends AbstractFluidContainer implements IAnimatable {

    private AnimationFactory factory = new InstancedAnimationFactory(this);
    private boolean hasBeenTurned =false;

    public MagicChurner(BlockPos pos, BlockState state) {
        super(DiabolismEntities.MAGIC_CHURNER_BLOCKENTITY, pos, state, 1000);
    }

    @Override
    public void registerControllers(AnimationData animationData) {
        animationData.addAnimationController(new AnimationController<MagicChurner>(this, "controller", 0, this::predicate));

    }

    private <E extends IAnimatable>PlayState predicate(AnimationEvent<E> event){
        if(hasBeenTurned) {
            event.getController().setAnimation(new AnimationBuilder().addAnimation("magic_churner_turn", (ILoopType) ILoopType.EDefaultLoopTypes.PLAY_ONCE));
            hasBeenTurned = false;
        }
       return PlayState.CONTINUE;
    }

    @Override
    public AnimationFactory getFactory() {
        return this.factory;
    }

    public static void ticker(World world, BlockPos pos, BlockState state, MagicChurner be) {
        be.tick(world, pos, state);
    }

    private void tick(World world, BlockPos pos, BlockState state) {
    }

    public void turn(){
        this.hasBeenTurned = true;
    }
Edited by Jipthechip
Link to comment
Share on other sites

  • Jipthechip changed the title to [Fabric 1.19.2] Can't get single play GeckoLib animations to work properly

That code is not for Forge 1.19.2

And questions about geckolib should be asked to them.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.