List of usage examples for net.minecraftforge.event.entity.living LivingFallEvent getEntityLiving
public LivingEntity getEntityLiving()
From source file:com.blogspot.jabelarminecraft.magicbeans.EventHandler.java
License:Open Source License
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true) public static void onEvent(LivingFallEvent event) { if (!event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer thePlayer = (EntityPlayer) event.getEntityLiving(); boolean isWearingBootsOfSafeFalling = thePlayer.getItemStackFromSlot(EntityEquipmentSlot.FEET) != null && thePlayer.getItemStackFromSlot(EntityEquipmentSlot.FEET) .getItem() == MagicBeans.bootsOfSafeFalling; // boolean isWearingLeggingsOfSafeFalling = thePlayer.getCurrentArmor(1) != null && thePlayer.getCurrentArmor(1).getItem() == MagicBeans.leggingsOfSafeFalling; // boolean isWearingChestPlateOfSafeFalling = thePlayer.getCurrentArmor(2) != null && thePlayer.getCurrentArmor(2).getItem() == MagicBeans.chestplateOfSafeFalling; // boolean isWearingHelmetOfSafeFalling = thePlayer.getCurrentArmor(3) != null && thePlayer.getCurrentArmor(3).getItem() == MagicBeans.helmetOfSafeFalling; if (isWearingBootsOfSafeFalling) // || isWearingLeggingsOfSafeFalling || isWearingChestPlateOfSafeFalling || isWearingHelmetOfSafeFalling) {/*from ww w .j av a2 s. com*/ // DEBUG System.out.println("LivingFallEvent handled due to having safe falling armor equipped"); event.setDistance(0.0F); } } }
From source file:com.lothrazar.cyclicmagic.potion.effect.PotionBounce.java
License:Open Source License
@SubscribeEvent public void onFall(LivingFallEvent event) { EntityLivingBase entity = event.getEntityLiving(); if (entity == null || entity instanceof EntityPlayer == false || entity.isSneaking() || entity.isPotionActive(this) == false) { return;/*from w ww . j a v a 2 s . co m*/ } EntityPlayer player = (EntityPlayer) entity; if (event.getDistance() >= MIN_HEIGHT_START_BOUNCE) { event.setDamageMultiplier(0); if (entity.getEntityWorld().isRemote == false) { event.setCanceled(true); //nada serverside } else { UtilSound.playSound(player, player.getPosition(), SoundEvents.BLOCK_SLIME_FALL, SoundCategory.PLAYERS, UtilSound.VOLUME / event.getDistance()); UtilParticle.spawnParticle(player.world, EnumParticleTypes.SLIME, player.getPosition()); event.setDistance(0);// fall distance if (player.isElytraFlying() == false) { player.motionY *= -PERCENT_HEIGHT_BOUNCED; player.isAirBorne = true; player.onGround = false; //postpone until one tick later. otherwise there is vanilla code internally that says "ok you finished falldamage so motionY=0;" player.posY += 0.01; player.getEntityData().setInteger(NBT_TICK, player.ticksExisted + 1); player.getEntityData().setInteger(NBT_MOTIONY, (int) (player.motionY * 100f)); } } } else if (!entity.getEntityWorld().isRemote && entity.isSneaking()) { event.setDamageMultiplier(DAMAGE_REDUCTION); } }