@SubscribeEvent public static void onPlayerAttacked(LivingAttackEvent event) { if(event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntityLiving(); if(getOdinRing(player) != null && damageNegations.contains(event.getSource().damageType)) event.setCanceled(true); } }
event.setCanceled(true);
@Override public void onPlayerAttacked(LivingAttackEvent event, EntityPlayer victim, @Nonnull ItemStack armorStack, EntityEquipmentSlot slot) { if (event.getSource() == DamageSource.DROWN && ChargableUtility.hasPower(victim, ArmorModule.rebreatherConsumption)) { ChargableUtility.drainSteam(victim.getItemStackFromSlot(EntityEquipmentSlot.CHEST), ArmorModule.rebreatherConsumption, victim); event.setCanceled(true); } } }
@SubscribeEvent public void onDamage(LivingAttackEvent event) { if (event.getSource() == DamageSource.starve && event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer player = ((EntityPlayer)event.getEntityLiving()); if (player.isPlayerSleeping()) { event.setCanceled(true); } } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public static void onPlayerDamageEvent(LivingAttackEvent event) { if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND) && event.isCancelable() && event.getSource().isProjectile()) event.setCanceled(true); }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { if (event.getEntity() instanceof EntityPlayer) { for (Capability listener : listeners) { boolean cancel = ((IPlayerEventListener) event.getEntity().getCapability(listener, null)).onEntityAttacked(event.getSource(), event.getAmount()); if (cancel) { event.setCanceled(true); } } } }
@SubscribeEvent(priority = EventPriority.HIGH) public void onLivingAttack(LivingAttackEvent event) { if (event.getEntity() instanceof EntityPlayer) { if (!FactionPlayerHandler.get((EntityPlayer) event.getEntity()).onEntityAttacked(event.getSource(), event.getAmount())) { event.setCanceled(true); } } }
@SubscribeEvent public void onEntityMounted(LivingAttackEvent event) { if (event.getEntityLiving() instanceof EntityPlayer) { /* if (event.entityLiving.ridingEntity != null && event.entityLiving.ridingEntity instanceof EntityArmchairMount) if(event.entityLiving.ridingEntity.worldObj.isAirBlock((int) (event.entityLiving.ridingEntity.posX - 0.5D), (int)(event.entityLiving.ridingEntity.posY + 1D), (int)(event.entityLiving.ridingEntity.posZ - 0.5D))) if(event.entityLiving.ridingEntity.worldObj.isAirBlock((int) (event.entityLiving.ridingEntity.posX - 0.5D), (int)(event.entityLiving.ridingEntity.posY + 2D), (int)(event.entityLiving.ridingEntity.posZ - 0.5D))) if (event.source == DamageSource.inWall) event.setCanceled(true); */ if (event.getEntityLiving().getRidingEntity() != null && event.getEntityLiving().getRidingEntity() instanceof EntityLivingBase) if (event.getSource() == DamageSource.IN_WALL) event.setCanceled(true); } } }
private void unusingEvent(LivingAttackEvent event) { if(Configs.isEnabled(EnchantmentUnusingConfig.class) && event.getSource().getTrueSource() instanceof EntityLivingBase) { EntityLivingBase entity = (EntityLivingBase) event.getSource().getTrueSource(); ItemStack itemStack = entity.getHeldItemMainhand(); if (EnchantmentHelpers.doesEnchantApply(itemStack, EnchantmentUnusingConfig._instance.getEnchantment()) > -1) { if (EnchantmentUnusing.unuseTool(itemStack)) { event.setCanceled(true); //player.stopUsingItem(); return; } } } }
@SubscribeEvent public void onEntityHitByArrow(LivingAttackEvent event){ if(event.getSource().isProjectile() && event.getSource().getSourceOfDamage() instanceof AbstractMBArrow){ boolean isCanceled = ((AbstractMBArrow) event.getSource().getSourceOfDamage()).onHitEntity(event.getEntity(), event.getSource(), event.getAmount()); event.setCanceled(isCanceled); } } }
@SubscribeEvent public void onEntityAttacked(LivingAttackEvent event) { //Probably not a very "clean" solution, but the only one I found if (!skipAttackDamageOnce && "player".equals(event.getSource().getDamageType()) && event.getSource().getTrueSource() instanceof EntityPlayer) { ItemStack stack = ((EntityPlayer) event.getSource().getTrueSource()).getHeldItemMainhand(); if (!stack.isEmpty() && stack.getItem() instanceof IFactionSlayerItem) { IFactionSlayerItem item = (IFactionSlayerItem) stack.getItem(); IFaction faction = VampirismAPI.factionRegistry().getFaction(event.getEntity()); if (faction != null && faction.equals(item.getSlayedFaction())) { float amt = event.getAmount() * item.getDamageMultiplierForFaction(stack); skipAttackDamageOnce = true; boolean result = net.minecraftforge.common.ForgeHooks.onLivingAttack(event.getEntityLiving(), event.getSource(), amt); skipAttackDamageOnce = false; event.setCanceled(!result); } } } }
@SubscribeEvent public void onEntityDamage(LivingAttackEvent event) { if (!ModConfig.general.cowJarEnabled) { return; } if (event.getSource() == DamageSource.ANVIL && isCow(event.getEntityLiving())) { BlockPos pos = event.getEntity().getPosition().down(); IBlockState blockBelow = event.getEntity().getEntityWorld().getBlockState(pos); if (blockBelow.getBlock() == ModBlocks.milkJar) { event.getEntity().getEntityWorld().setBlockState(pos, ModBlocks.cowJar.getDefaultState()); } NetworkHandler.instance.sendToAllAround(new MessageSyncedEffect(pos, MessageSyncedEffect.Type.COW_IN_A_JAR), new NetworkRegistry.TargetPoint(event.getEntity().world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 32)); event.getEntity().setDead(); event.setCanceled(true); } }