Scouter456

Untitled

Aug 2nd, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. public class BounceShroomBlockEntity extends BlockEntity implements IAnimatable {
  2.     private AnimationFactory factory = new AnimationFactory(this);
  3.     public BounceShroomBlockEntity(BlockPos pPos, BlockState pBlockState) {
  4.         super(EQBlockEntities.BOUNCE_SHROOM.get(), pPos, pBlockState);
  5.     }
  6.  
  7.  
  8.  
  9.     private boolean bounce;
  10.     private int animTime;
  11.     @Override
  12.     public void registerControllers(AnimationData data) {
  13.         data.addAnimationController(new AnimationController<BounceShroomBlockEntity>(this, "controller",0,this::predicate));
  14.     }
  15.  
  16.     public static void tick(Level level, BlockPos pos, BlockState state, BounceShroomBlockEntity blockEntity) {
  17.         if(blockEntity.getBounce()){
  18.             if(++blockEntity.animTime > 2) {
  19.                 blockEntity.setBounce(false);
  20.                 blockEntity.animTime = 0;
  21.             }
  22.         }
  23.     }
  24.     private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event){
  25.         if(getBounce() && event.getController().getAnimationState().equals(AnimationState.Stopped)){
  26.             event.getController().setAnimation(new AnimationBuilder().playOnce("animation.bounceshroom.bounce"));
  27.             event.getController().markNeedsReload();
  28.         }
  29.         return PlayState.CONTINUE;
  30.     }
  31.  
  32.  
  33.     @Override
  34.     public AnimationFactory getFactory() {
  35.         return factory;
  36.     }
  37.  
  38.     public boolean getBounce(){
  39.         return this.bounce;
  40.     }
  41.  
  42.     public void setBounce(boolean bounce) {
  43.         this.bounce = bounce;
  44.     }
  45. }
Add Comment
Please, Sign In to add comment