Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BounceShroomBlockEntity extends BlockEntity implements IAnimatable {
- private AnimationFactory factory = new AnimationFactory(this);
- public BounceShroomBlockEntity(BlockPos pPos, BlockState pBlockState) {
- super(EQBlockEntities.BOUNCE_SHROOM.get(), pPos, pBlockState);
- }
- private boolean bounce;
- private int animTime;
- @Override
- public void registerControllers(AnimationData data) {
- data.addAnimationController(new AnimationController<BounceShroomBlockEntity>(this, "controller",0,this::predicate));
- }
- public static void tick(Level level, BlockPos pos, BlockState state, BounceShroomBlockEntity blockEntity) {
- if(blockEntity.getBounce()){
- if(++blockEntity.animTime > 2) {
- blockEntity.setBounce(false);
- blockEntity.animTime = 0;
- }
- }
- }
- private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event){
- if(getBounce() && event.getController().getAnimationState().equals(AnimationState.Stopped)){
- event.getController().setAnimation(new AnimationBuilder().playOnce("animation.bounceshroom.bounce"));
- event.getController().markNeedsReload();
- }
- return PlayState.CONTINUE;
- }
- @Override
- public AnimationFactory getFactory() {
- return factory;
- }
- public boolean getBounce(){
- return this.bounce;
- }
- public void setBounce(boolean bounce) {
- this.bounce = bounce;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement