Advertisement
Guest User

CustomBlockBounce

a guest
Apr 15th, 2017
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class CustomBlockBounce extends Block {
  2.  
  3.   //Constructor stuff
  4.   public CustomBlockBounce (Material materialIn, String name //You can delete this and replace it with your block name) {
  5.     super(materialIn);
  6.     setUnlocalizedName(name);
  7.     setRegistryName(name);
  8.     MinecraftForge.EventBus.register(this);
  9.   }
  10.  
  11.   @SubscribeEvent
  12.   public void onPlayerStepOn(LivingEvent.LivingJumpEvent event) {
  13.     if(event.getEntity() == null) {
  14.       return;
  15.     }
  16.  
  17.     // check if we jumped from a block that bounce
  18.     BlockPos pos = new BlockPos(event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ);
  19.     if(event.getEntity().getEntityWorld().isAirBlock(pos)) {
  20.       pos = pos.down();
  21.     }
  22.  
  23.     IBlockState state = event.getEntity().getEntityWorld().getBlockState(pos);
  24.     Block block = state.getBlock();
  25.  
  26.     if(block == ModBlocks.customBlockBounce) {
  27.       bounce(event.getEntity(), 1.0f);
  28.     }
  29.   }
  30.  
  31.   private void bounce(Entity entity, float amount) {
  32.     entity.motionY += amount;
  33.   }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement