@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 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); } }
@SubscribeEvent (priority = EventPriority.HIGH) public void handleLivingAttackEvent(LivingAttackEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof EntityPlayer)) { return; } DamageSource source = event.getSource(); if (source instanceof EntityDamageSourceIndirect || source.isUnblockable() || source.isProjectile()) { return; } if (source instanceof EntityDamageSource && ((EntityDamageSource) source).getIsThornsDamage()) { return; } EntityPlayer player = (EntityPlayer) event.getEntityLiving(); ItemStack stack = player.getActiveItemStack(); if (!stack.isEmpty() && stack.getItem() instanceof ItemShieldCore) { ((ItemShieldCore) stack.getItem()).onHit(stack, player, source.getTrueSource()); } }
@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 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); } } } }
@Override public void onPlayerAttacksOther(LivingAttackEvent event, EntityPlayer attacker, @Nonnull ItemStack armorStack, EntityEquipmentSlot slot) { boolean hasPower = ChargableUtility.hasPower(attacker, ArmorModule.powerFistConsumption); ItemStack stack = attacker.getItemStackFromSlot(EntityEquipmentSlot.CHEST); if (hasPower && attacker.getHeldItemMainhand().isEmpty()) { Entity victim = event.getEntity(); World world = victim.world; world.playSound(victim.posX, victim.posY, victim.posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 4F, (1F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F, false); Vec3d normalizedLookVec = attacker.getLookVec().normalize(); victim.motionX += 3.0F * normalizedLookVec.x; victim.motionY += (normalizedLookVec.y > 0.0F ? 2.0F * normalizedLookVec.y : 0.0F) + 1.5F; victim.motionZ += 3.0F * normalizedLookVec.z; victim.motionX += -0.5F * normalizedLookVec.x; victim.motionZ += -0.5F * normalizedLookVec.z; ChargableUtility.drainSteam(stack, ArmorModule.powerFistConsumption, attacker); } } }
private void poisonTipEvent(LivingAttackEvent event) { if(Configs.isEnabled(EnchantmentPoisonTipConfig.class) && event.getSource().getTrueSource() instanceof EntityLivingBase) { EntityLivingBase entity = (EntityLivingBase) event.getSource().getTrueSource(); ItemStack itemStack = entity.getHeldItemMainhand(); int enchantmentListID = EnchantmentHelpers.doesEnchantApply(itemStack, EnchantmentPoisonTipConfig._instance.getEnchantment()); if (enchantmentListID > -1) { int level = EnchantmentHelpers.getEnchantmentLevel(itemStack, enchantmentListID); EnchantmentPoisonTip.poison((EntityLivingBase) event.getEntity(), level); 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); } } }