Search in sources :

Example 1 with DamageFunction

use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeCommon by SpongePowered.

the class DamageEventHandler method createAttackEnchantmentFunction.

public static List<DamageFunction> createAttackEnchantmentFunction(net.minecraft.item.ItemStack heldItem, EnumCreatureAttribute creatureAttribute, float attackStrength) {
    final Multimap<Enchantment, Integer> enchantments = LinkedHashMultimap.create();
    final List<DamageFunction> damageModifierFunctions = new ArrayList<>();
    if (!heldItem.isEmpty()) {
        NBTTagList nbttaglist = heldItem.getEnchantmentTagList();
        if (nbttaglist.hasNoTags()) {
            return ImmutableList.of();
        }
        for (int i = 0; i < nbttaglist.tagCount(); ++i) {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int enchantmentLevel = nbttaglist.getCompoundTagAt(i).getShort("lvl");
            final Enchantment enchantment = Enchantment.getEnchantmentByID(j);
            if (enchantment != null) {
                enchantments.put(enchantment, enchantmentLevel);
            }
        }
        if (enchantments.isEmpty()) {
            return ImmutableList.of();
        }
        ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(heldItem);
        for (Map.Entry<Enchantment, Collection<Integer>> enchantment : enchantments.asMap().entrySet()) {
            final DamageModifier enchantmentModifier = DamageModifier.builder().type(DamageModifierTypes.WEAPON_ENCHANTMENT).cause(Cause.of(EventContext.empty(), snapshot, enchantment)).build();
            DoubleUnaryOperator enchantmentFunction = (damage) -> {
                double totalDamage = 0;
                for (int level : enchantment.getValue()) {
                    totalDamage += (double) enchantment.getKey().calcDamageByCreature(level, creatureAttribute) * attackStrength;
                }
                return totalDamage;
            };
            damageModifierFunctions.add(new DamageFunction(enchantmentModifier, enchantmentFunction));
        }
    }
    return damageModifierFunctions;
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Item(net.minecraft.item.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) NBTTagList(net.minecraft.nbt.NBTTagList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Map(java.util.Map) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) NbtDataUtil(org.spongepowered.common.data.util.NbtDataUtil) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) Predicate(java.util.function.Predicate) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) EntityUtil(org.spongepowered.common.entity.EntityUtil) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) Optional(java.util.Optional) MobEffects(net.minecraft.init.MobEffects) EventContext(org.spongepowered.api.event.cause.EventContext) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Iterables(com.google.common.collect.Iterables) Enchantment(net.minecraft.enchantment.Enchantment) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) DamageModifierTypes(org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes) Multimap(com.google.common.collect.Multimap) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Chunk(net.minecraft.world.chunk.Chunk) Entity(net.minecraft.entity.Entity) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) BlockPos(net.minecraft.util.math.BlockPos) DamageSource(net.minecraft.util.DamageSource) IBlockState(net.minecraft.block.state.IBlockState) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) EntityDamageSource(net.minecraft.util.EntityDamageSource) EnumCreatureAttribute(net.minecraft.entity.EnumCreatureAttribute) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Collection(java.util.Collection) Enchantment(net.minecraft.enchantment.Enchantment) Map(java.util.Map) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 2 with DamageFunction

use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeCommon by SpongePowered.

the class DamageEventHandler method createAbsorptionModifier.

public static Optional<DamageFunction> createAbsorptionModifier(EntityLivingBase entityLivingBase, DamageSource damageSource) {
    final float absorptionAmount = entityLivingBase.getAbsorptionAmount();
    if (absorptionAmount > 0) {
        DoubleUnaryOperator function = damage -> -(Math.max(damage - Math.max(damage - absorptionAmount, 0.0F), 0.0F));
        // TODO: direct cause creation: bad bad bad
        DamageModifier modifier = DamageModifier.builder().cause(Cause.of(EventContext.empty(), entityLivingBase)).type(DamageModifierTypes.ABSORPTION).build();
        return Optional.of(new DamageFunction(modifier, function));
    }
    return Optional.empty();
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Item(net.minecraft.item.Item) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) NBTTagList(net.minecraft.nbt.NBTTagList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Map(java.util.Map) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) ItemArmor(net.minecraft.item.ItemArmor) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) NbtDataUtil(org.spongepowered.common.data.util.NbtDataUtil) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) Predicate(java.util.function.Predicate) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) EntityUtil(org.spongepowered.common.entity.EntityUtil) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) Optional(java.util.Optional) MobEffects(net.minecraft.init.MobEffects) EventContext(org.spongepowered.api.event.cause.EventContext) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Iterables(com.google.common.collect.Iterables) Enchantment(net.minecraft.enchantment.Enchantment) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) DamageModifierTypes(org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes) Multimap(com.google.common.collect.Multimap) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Chunk(net.minecraft.world.chunk.Chunk) Entity(net.minecraft.entity.Entity) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) BlockPos(net.minecraft.util.math.BlockPos) DamageSource(net.minecraft.util.DamageSource) IBlockState(net.minecraft.block.state.IBlockState) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) EntityDamageSource(net.minecraft.util.EntityDamageSource) EnumCreatureAttribute(net.minecraft.entity.EnumCreatureAttribute) EquipmentTypes(org.spongepowered.api.item.inventory.equipment.EquipmentTypes) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 3 with DamageFunction

use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeCommon by SpongePowered.

the class MixinEntityLivingBase method damageEntityHook.

@Override
public boolean damageEntityHook(DamageSource damageSource, float damage) {
    if (!this.isEntityInvulnerable(damageSource)) {
        final boolean human = (Object) this instanceof EntityPlayer;
        // apply forge damage hook
        damage = applyModDamage((EntityLivingBase) (Object) this, damageSource, damage);
        // set after forge hook.
        float originalDamage = damage;
        if (damage <= 0) {
            damage = 0;
        }
        List<DamageFunction> originalFunctions = new ArrayList<>();
        Optional<DamageFunction> hardHatFunction = DamageEventHandler.createHardHatModifier((EntityLivingBase) (Object) this, damageSource);
        Optional<List<DamageFunction>> armorFunction = provideArmorModifiers((EntityLivingBase) (Object) this, damageSource, damage);
        Optional<DamageFunction> resistanceFunction = DamageEventHandler.createResistanceModifier((EntityLivingBase) (Object) this, damageSource);
        Optional<List<DamageFunction>> armorEnchantments = DamageEventHandler.createEnchantmentModifiers((EntityLivingBase) (Object) this, damageSource);
        Optional<DamageFunction> absorptionFunction = DamageEventHandler.createAbsorptionModifier((EntityLivingBase) (Object) this, damageSource);
        Optional<DamageFunction> shieldFunction = DamageEventHandler.createShieldFunction((EntityLivingBase) (Object) this, damageSource, damage);
        if (hardHatFunction.isPresent()) {
            originalFunctions.add(hardHatFunction.get());
        }
        if (shieldFunction.isPresent()) {
            originalFunctions.add(shieldFunction.get());
        }
        if (armorFunction.isPresent()) {
            originalFunctions.addAll(armorFunction.get());
        }
        if (resistanceFunction.isPresent()) {
            originalFunctions.add(resistanceFunction.get());
        }
        if (armorEnchantments.isPresent()) {
            originalFunctions.addAll(armorEnchantments.get());
        }
        if (absorptionFunction.isPresent()) {
            originalFunctions.add(absorptionFunction.get());
        }
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            DamageEventHandler.generateCauseFor(damageSource);
            DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), originalFunctions, this, originalDamage);
            if (damageSource != DamageSourceRegistryModule.IGNORED_DAMAGE_SOURCE) {
                // Basically, don't throw an event if it's our own damage source
                Sponge.getEventManager().post(event);
            }
            if (event.isCancelled()) {
                return false;
            }
            damage = (float) event.getFinalDamage();
            // Helmet
            final ItemStack mainHandItem = this.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
            if ((damageSource instanceof FallingBlockDamageSource) && mainHandItem != null) {
                mainHandItem.damageItem((int) (event.getBaseDamage() * 4.0F + this.rand.nextFloat() * event.getBaseDamage() * 2.0F), (EntityLivingBase) (Object) this);
            }
            // Shield
            if (shieldFunction.isPresent()) {
                // TODO gabizou: Should this be in the API?
                this.damageShield((float) event.getBaseDamage());
                if (!damageSource.isProjectile()) {
                    Entity entity = damageSource.getImmediateSource();
                    if (entity instanceof EntityLivingBase) {
                        this.blockUsingShield((EntityLivingBase) entity);
                    }
                }
            }
            // Armor
            if (!damageSource.isUnblockable()) {
                for (DamageFunction modifier : event.getModifiers()) {
                    applyArmorDamage((EntityLivingBase) (Object) this, damageSource, event, modifier.getModifier());
                }
            }
            double absorptionModifier = absorptionFunction.map(function -> event.getDamage(function.getModifier())).orElse(0d);
            if (absorptionFunction.isPresent()) {
                absorptionModifier = event.getDamage(absorptionFunction.get().getModifier());
            }
            this.setAbsorptionAmount(Math.max(this.getAbsorptionAmount() + (float) absorptionModifier, 0.0F));
            if (damage != 0.0F) {
                if (human) {
                    ((EntityPlayer) (Object) this).addExhaustion(damageSource.getHungerDamage());
                }
                float f2 = this.getHealth();
                this.setHealth(f2 - damage);
                this.getCombatTracker().trackDamage(damageSource, f2, damage);
                if (human) {
                    return true;
                }
                this.setAbsorptionAmount(this.getAbsorptionAmount() - damage);
            }
            return true;
        }
    }
    return false;
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) EnumHand(net.minecraft.util.EnumHand) Random(java.util.Random) SpongeCommonEventFactory(org.spongepowered.common.event.SpongeCommonEventFactory) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Mixin(org.spongepowered.asm.mixin.Mixin) SpongeOptionalValue(org.spongepowered.common.data.value.mutable.SpongeOptionalValue) PhaseData(org.spongepowered.common.event.tracking.PhaseData) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) Living(org.spongepowered.api.entity.living.Living) DamageSourceRegistryModule(org.spongepowered.common.registry.type.event.DamageSourceRegistryModule) At(org.spongepowered.asm.mixin.injection.At) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) AbstractAttributeMap(net.minecraft.entity.ai.attributes.AbstractAttributeMap) MutableBoundedValue(org.spongepowered.api.data.value.mutable.MutableBoundedValue) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) SpongeHealthData(org.spongepowered.common.data.manipulator.mutable.entity.SpongeHealthData) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) EntityUtil(org.spongepowered.common.entity.EntityUtil) HealthData(org.spongepowered.api.data.manipulator.mutable.entity.HealthData) List(java.util.List) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Transform(org.spongepowered.api.entity.Transform) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) IMixinEntityLivingBase(org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase) Potion(net.minecraft.potion.Potion) MobEffects(net.minecraft.init.MobEffects) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) SpongeDamageableData(org.spongepowered.common.data.manipulator.mutable.entity.SpongeDamageableData) Keys(org.spongepowered.api.data.key.Keys) EntityWolf(net.minecraft.entity.passive.EntityWolf) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Vector3d(com.flowpowered.math.vector.Vector3d) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) Overwrite(org.spongepowered.asm.mixin.Overwrite) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) OptionalValue(org.spongepowered.api.data.value.mutable.OptionalValue) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) Text(org.spongepowered.api.text.Text) EntityPhase(org.spongepowered.common.event.tracking.phase.entity.EntityPhase) ProjectileLauncher(org.spongepowered.common.entity.projectile.ProjectileLauncher) EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) CauseStackManager(org.spongepowered.api.event.CauseStackManager) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) WorldServer(net.minecraft.world.WorldServer) Nullable(javax.annotation.Nullable) DamageableData(org.spongepowered.api.data.manipulator.mutable.entity.DamageableData) Entity(net.minecraft.entity.Entity) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) World(net.minecraft.world.World) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) BlockPos(net.minecraft.util.math.BlockPos) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) DamageSource(net.minecraft.util.DamageSource) IBlockState(net.minecraft.block.state.IBlockState) SpongeValueFactory(org.spongepowered.common.data.value.SpongeValueFactory) DamageEventHandler(org.spongepowered.common.event.damage.DamageEventHandler) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) CombatTracker(net.minecraft.util.CombatTracker) EntityLivingBase(net.minecraft.entity.EntityLivingBase) DamageObject(org.spongepowered.common.event.damage.DamageObject) MathHelper(net.minecraft.util.math.MathHelper) EntityCreature(net.minecraft.entity.EntityCreature) Projectile(org.spongepowered.api.entity.projectile.Projectile) SoundEvent(net.minecraft.util.SoundEvent) Entity(net.minecraft.entity.Entity) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) ArrayList(java.util.ArrayList) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) CauseStackManager(org.spongepowered.api.event.CauseStackManager) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) IMixinEntityLivingBase(org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) DamageObject(org.spongepowered.common.event.damage.DamageObject) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 4 with DamageFunction

use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeCommon by SpongePowered.

the class MixinEntityMob method attackEntityAsMob.

/**
 * @author gabizou - April 8th, 2016
 * @author gabizou - April 11th, 2016 - Update for 1.9 additions
 * @author Aaro1011 - November 12, 2016 - Update for 1.11
 *
 * @reason Rewrite this to throw an {@link AttackEntityEvent} and process correctly.
 *
 * float f        | baseDamage
 * int i          | knockbackModifier
 * boolean flag   | attackSucceeded
 *
 * @param targetEntity The entity to attack
 * @return True if the attack was successful
 */
@Overwrite
public boolean attackEntityAsMob(Entity targetEntity) {
    // Sponge Start - Prepare our event values
    // float baseDamage = this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    final double originalBaseDamage = this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
    final List<DamageFunction> originalFunctions = new ArrayList<>();
    // Sponge End
    int knockbackModifier = 0;
    if (targetEntity instanceof EntityLivingBase) {
        // Sponge Start - Gather modifiers
        // 1.0F is for full attack strength since mobs don't have the concept
        originalFunctions.addAll(DamageEventHandler.createAttackEnchantmentFunction(this.getHeldItemMainhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute(), 1.0F));
        // baseDamage += EnchantmentHelper.getModifierForCreature(this.getHeldItem(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
        knockbackModifier += EnchantmentHelper.getKnockbackModifier((EntityMob) (Object) this);
    }
    // Sponge Start - Throw our event and handle appropriately
    final DamageSource damageSource = DamageSource.causeMobDamage((EntityMob) (Object) this);
    Sponge.getCauseStackManager().pushCause(damageSource);
    final AttackEntityEvent event = SpongeEventFactory.createAttackEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), originalFunctions, EntityUtil.fromNative(targetEntity), knockbackModifier, originalBaseDamage);
    SpongeImpl.postEvent(event);
    Sponge.getCauseStackManager().popCause();
    if (event.isCancelled()) {
        return false;
    }
    knockbackModifier = event.getKnockbackModifier();
    // boolean attackSucceeded = targetEntity.attackEntityFrom(DamageSource.causeMobDamage(this), baseDamage);
    boolean attackSucceeded = targetEntity.attackEntityFrom(damageSource, (float) event.getFinalOutputDamage());
    // Sponge End
    if (attackSucceeded) {
        if (knockbackModifier > 0 && targetEntity instanceof EntityLivingBase) {
            ((EntityLivingBase) targetEntity).knockBack((EntityMob) (Object) this, (float) knockbackModifier * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
            this.motionX *= 0.6D;
            this.motionZ *= 0.6D;
        }
        int j = EnchantmentHelper.getFireAspectModifier((EntityMob) (Object) this);
        if (j > 0) {
            targetEntity.setFire(j * 4);
        }
        if (targetEntity instanceof EntityPlayer) {
            EntityPlayer entityplayer = (EntityPlayer) targetEntity;
            ItemStack itemstack = this.getHeldItemMainhand();
            ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : ItemStack.EMPTY;
            if (!itemstack.isEmpty() && !itemstack1.isEmpty() && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == Items.SHIELD) {
                float f1 = 0.25F + (float) EnchantmentHelper.getEfficiencyModifier((EntityMob) (Object) this) * 0.05F;
                if (this.rand.nextFloat() < f1) {
                    entityplayer.getCooldownTracker().setCooldown(Items.SHIELD, 100);
                    this.world.setEntityState(entityplayer, (byte) 30);
                }
            }
        }
        this.applyEnchantments((EntityMob) (Object) this, targetEntity);
    }
    return attackSucceeded;
}
Also used : ItemAxe(net.minecraft.item.ItemAxe) DamageSource(net.minecraft.util.DamageSource) ArrayList(java.util.ArrayList) EntityMob(net.minecraft.entity.monster.EntityMob) AttackEntityEvent(org.spongepowered.api.event.entity.AttackEntityEvent) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with DamageFunction

use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeCommon by SpongePowered.

the class MixinEntityPlayer method attackTargetEntityWithCurrentItem.

/**
 * @author gabizou - April 8th, 2016
 * @author gabizou - April 11th, 2016 - Update for 1.9 - This enitre method was rewritten
 *
 * @reason Rewrites the attackTargetEntityWithCurrentItem to throw an {@link AttackEntityEvent} prior
 * to the ensuing {@link DamageEntityEvent}. This should cover all cases where players are
 * attacking entities and those entities override {@link EntityLivingBase#attackEntityFrom(DamageSource, float)}
 * and effectively bypass our damage event hooks.
 *
 * LVT Rename Table:
 * float f        | damage               |
 * float f1       | enchantmentDamage    |
 * float f2       | attackStrength       |
 * boolean flag   | isStrongAttack       |
 * boolean flag1  | isSprintingAttack    |
 * boolean flag2  | isCriticalAttack     | Whether critical particles will spawn and of course, multiply the output damage
 * boolean flag3  | isSweapingAttack     | Whether the player is sweaping an attack and will deal AoE damage
 * int i          | knockbackModifier    | The knockback modifier, must be set from the event after it has been thrown
 * float f4       | targetOriginalHealth | This is initially set as the entity original health
 * boolean flag4  | litEntityOnFire      | This is an internal flag to where if the attack failed, the entity is no longer set on fire
 * int j          | fireAspectModifier   | Literally just to check that the weapon used has fire aspect enchantments
 * double d0      | distanceWalkedDelta  | This checks that the distance walked delta is more than the normal walking speed to evaluate if you're making a sweaping attack
 * double d1      | targetMotionX        | Current target entity motion x vector
 * double d2      | targetMotionY        | Current target entity motion y vector
 * double d3      | targetMotionZ        | Current target entity motion z vector
 * boolean flag5  | attackSucceeded      | Whether the attack event succeeded
 *
 * @param targetEntity The target entity
 */
@Overwrite
public void attackTargetEntityWithCurrentItem(Entity targetEntity) {
    // Sponge Start - Add SpongeImpl hook to override in forge as necessary
    if (!SpongeImplHooks.checkAttackEntity((EntityPlayer) (Object) this, targetEntity)) {
        return;
    }
    // Sponge End
    if (targetEntity.canBeAttackedWithItem()) {
        if (!targetEntity.hitByEntity((EntityPlayer) (Object) this)) {
            // Sponge Start - Prepare our event values
            // float damage = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
            final double originalBaseDamage = this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
            float damage = (float) originalBaseDamage;
            // Sponge End
            float enchantmentDamage = 0.0F;
            // Spogne Start - Redirect getting enchantments for our damage event handlers
            // if (targetEntity instanceof EntityLivingBase) {
            // enchantmentDamage = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
            // } else {
            // enchantmentDamage = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), EnumCreatureAttribute.UNDEFINED);
            // }
            float attackStrength = this.getCooledAttackStrength(0.5F);
            final List<ModifierFunction<DamageModifier>> originalFunctions = new ArrayList<>();
            final EnumCreatureAttribute creatureAttribute = targetEntity instanceof EntityLivingBase ? ((EntityLivingBase) targetEntity).getCreatureAttribute() : EnumCreatureAttribute.UNDEFINED;
            final List<DamageFunction> enchantmentModifierFunctions = DamageEventHandler.createAttackEnchantmentFunction(this.getHeldItemMainhand(), creatureAttribute, attackStrength);
            // This is kept for the post-damage event handling
            final List<DamageModifier> enchantmentModifiers = enchantmentModifierFunctions.stream().map(ModifierFunction::getModifier).collect(Collectors.toList());
            enchantmentDamage = (float) enchantmentModifierFunctions.stream().map(ModifierFunction::getFunction).mapToDouble(function -> function.applyAsDouble(originalBaseDamage)).sum();
            originalFunctions.addAll(enchantmentModifierFunctions);
            // Sponge End
            originalFunctions.add(DamageEventHandler.provideCooldownAttackStrengthFunction((EntityPlayer) (Object) this, attackStrength));
            damage = damage * (0.2F + attackStrength * attackStrength * 0.8F);
            enchantmentDamage = enchantmentDamage * attackStrength;
            this.resetCooldown();
            if (damage > 0.0F || enchantmentDamage > 0.0F) {
                boolean isStrongAttack = attackStrength > 0.9F;
                boolean isSprintingAttack = false;
                boolean isCriticalAttack = false;
                boolean isSweapingAttack = false;
                int knockbackModifier = 0;
                knockbackModifier = knockbackModifier + EnchantmentHelper.getKnockbackModifier((EntityPlayer) (Object) this);
                if (this.isSprinting() && isStrongAttack) {
                    // Sponge - Only play sound after the event has be thrown and not cancelled.
                    // this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.entity_player_attack_knockback, this.getSoundCategory(), 1.0F, 1.0F);
                    ++knockbackModifier;
                    isSprintingAttack = true;
                }
                isCriticalAttack = isStrongAttack && this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(MobEffects.BLINDNESS) && !this.isRiding() && targetEntity instanceof EntityLivingBase;
                isCriticalAttack = isCriticalAttack && !this.isSprinting();
                if (isCriticalAttack) {
                    // Sponge Start - add critical attack tuple
                    // damage *= 1.5F; // Sponge - This is handled in the event
                    originalFunctions.add(DamageEventHandler.provideCriticalAttackTuple((EntityPlayer) (Object) this));
                // Sponge End
                }
                // damage = damage + enchantmentDamage; // Sponge - We don't need this since our event will re-assign the damage to deal
                double distanceWalkedDelta = (double) (this.distanceWalkedModified - this.prevDistanceWalkedModified);
                final ItemStack heldItem = this.getHeldItem(EnumHand.MAIN_HAND);
                if (isStrongAttack && !isCriticalAttack && !isSprintingAttack && this.onGround && distanceWalkedDelta < (double) this.getAIMoveSpeed()) {
                    ItemStack itemstack = heldItem;
                    if (itemstack.getItem() instanceof ItemSword) {
                        isSweapingAttack = true;
                    }
                }
                // Sponge Start - Create the event and throw it
                final DamageSource damageSource = DamageSource.causePlayerDamage((EntityPlayer) (Object) this);
                final boolean isMainthread = !this.world.isRemote;
                if (isMainthread) {
                    Sponge.getCauseStackManager().pushCause(damageSource);
                }
                final Cause currentCause = isMainthread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), damageSource);
                final AttackEntityEvent event = SpongeEventFactory.createAttackEntityEvent(currentCause, originalFunctions, EntityUtil.fromNative(targetEntity), knockbackModifier, originalBaseDamage);
                SpongeImpl.postEvent(event);
                if (isMainthread) {
                    Sponge.getCauseStackManager().popCause();
                }
                if (event.isCancelled()) {
                    return;
                }
                damage = (float) event.getFinalOutputDamage();
                // sponge - need final for later events
                final double attackDamage = damage;
                knockbackModifier = event.getKnockbackModifier();
                enchantmentDamage = (float) enchantmentModifiers.stream().mapToDouble(event::getOutputDamage).sum();
                // Sponge End
                float targetOriginalHealth = 0.0F;
                boolean litEntityOnFire = false;
                int fireAspectModifier = EnchantmentHelper.getFireAspectModifier((EntityPlayer) (Object) this);
                if (targetEntity instanceof EntityLivingBase) {
                    targetOriginalHealth = ((EntityLivingBase) targetEntity).getHealth();
                    if (fireAspectModifier > 0 && !targetEntity.isBurning()) {
                        litEntityOnFire = true;
                        targetEntity.setFire(1);
                    }
                }
                double targetMotionX = targetEntity.motionX;
                double targetMotionY = targetEntity.motionY;
                double targetMotionZ = targetEntity.motionZ;
                boolean attackSucceeded = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) (Object) this), damage);
                if (attackSucceeded) {
                    if (knockbackModifier > 0) {
                        if (targetEntity instanceof EntityLivingBase) {
                            ((EntityLivingBase) targetEntity).knockBack((EntityPlayer) (Object) this, (float) knockbackModifier * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
                        } else {
                            targetEntity.addVelocity((double) (-MathHelper.sin(this.rotationYaw * 0.017453292F) * (float) knockbackModifier * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * 0.017453292F) * (float) knockbackModifier * 0.5F));
                        }
                        this.motionX *= 0.6D;
                        this.motionZ *= 0.6D;
                        this.setSprinting(false);
                    }
                    if (isSweapingAttack) {
                        for (EntityLivingBase entitylivingbase : this.world.getEntitiesWithinAABB(EntityLivingBase.class, targetEntity.getEntityBoundingBox().grow(1.0D, 0.25D, 1.0D))) {
                            if (entitylivingbase != (EntityPlayer) (Object) this && entitylivingbase != targetEntity && !this.isOnSameTeam(entitylivingbase) && this.getDistanceSq(entitylivingbase) < 9.0D) {
                                // Sponge Start - Do a small event for these entities
                                // entitylivingbase.knockBack(this, 0.4F, (double)MathHelper.sin(this.rotationYaw * 0.017453292F), (double)(-MathHelper.cos(this.rotationYaw * 0.017453292F)));
                                // entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(this), 1.0F);
                                final EntityDamageSource sweepingAttackSource = EntityDamageSource.builder().entity(this).type(DamageTypes.SWEEPING_ATTACK).build();
                                try (final StackFrame frame = isMainthread ? Sponge.getCauseStackManager().pushCauseFrame() : null) {
                                    if (isMainthread) {
                                        Sponge.getCauseStackManager().pushCause(sweepingAttackSource);
                                    }
                                    final ItemStackSnapshot heldSnapshot = ItemStackUtil.snapshotOf(heldItem);
                                    if (isMainthread) {
                                        Sponge.getCauseStackManager().addContext(EventContextKeys.WEAPON, heldSnapshot);
                                    }
                                    final DamageFunction sweapingFunction = DamageFunction.of(DamageModifier.builder().cause(Cause.of(EventContext.empty(), heldSnapshot)).item(heldSnapshot).type(DamageModifierTypes.SWEEPING).build(), (incoming) -> EnchantmentHelper.getSweepingDamageRatio((EntityPlayer) (Object) this) * attackDamage);
                                    final List<DamageFunction> sweapingFunctions = new ArrayList<>();
                                    sweapingFunctions.add(sweapingFunction);
                                    AttackEntityEvent sweepingAttackEvent = SpongeEventFactory.createAttackEntityEvent(currentCause, sweapingFunctions, EntityUtil.fromNative(entitylivingbase), 1, 1.0D);
                                    SpongeImpl.postEvent(sweepingAttackEvent);
                                    if (!sweepingAttackEvent.isCancelled()) {
                                        entitylivingbase.knockBack((EntityPlayer) (Object) this, sweepingAttackEvent.getKnockbackModifier() * 0.4F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
                                        entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) (Object) this), (float) sweepingAttackEvent.getFinalOutputDamage());
                                    }
                                }
                            // Sponge End
                            }
                        }
                        this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0F, 1.0F);
                        this.spawnSweepParticles();
                    }
                    if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
                        ((EntityPlayerMP) targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
                        targetEntity.velocityChanged = false;
                        targetEntity.motionX = targetMotionX;
                        targetEntity.motionY = targetMotionY;
                        targetEntity.motionZ = targetMotionZ;
                    }
                    if (isCriticalAttack) {
                        this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0F, 1.0F);
                        this.onCriticalHit(targetEntity);
                    }
                    if (!isCriticalAttack && !isSweapingAttack) {
                        if (isStrongAttack) {
                            this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0F, 1.0F);
                        } else {
                            this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0F, 1.0F);
                        }
                    }
                    if (enchantmentDamage > 0.0F) {
                        this.onEnchantmentCritical(targetEntity);
                    }
                    this.setLastAttackedEntity(targetEntity);
                    if (targetEntity instanceof EntityLivingBase) {
                        EnchantmentHelper.applyThornEnchantments((EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
                    }
                    EnchantmentHelper.applyArthropodEnchantments((EntityPlayer) (Object) this, targetEntity);
                    ItemStack itemstack1 = this.getHeldItemMainhand();
                    Entity entity = targetEntity;
                    if (targetEntity instanceof MultiPartEntityPart) {
                        IEntityMultiPart ientitymultipart = ((MultiPartEntityPart) targetEntity).parent;
                        if (ientitymultipart instanceof EntityLivingBase) {
                            entity = (EntityLivingBase) ientitymultipart;
                        }
                    }
                    if (!itemstack1.isEmpty() && targetEntity instanceof EntityLivingBase) {
                        itemstack1.hitEntity((EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
                        if (itemstack1.isEmpty()) {
                            this.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
                        }
                    }
                    if (targetEntity instanceof EntityLivingBase) {
                        float f5 = targetOriginalHealth - ((EntityLivingBase) targetEntity).getHealth();
                        this.addStat(StatList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
                        if (fireAspectModifier > 0) {
                            targetEntity.setFire(fireAspectModifier * 4);
                        }
                        if (this.world instanceof WorldServer && f5 > 2.0F) {
                            int k = (int) ((double) f5 * 0.5D);
                            ((WorldServer) this.world).spawnParticle(EnumParticleTypes.DAMAGE_INDICATOR, targetEntity.posX, targetEntity.posY + (double) (targetEntity.height * 0.5F), targetEntity.posZ, k, 0.1D, 0.0D, 0.1D, 0.2D, new int[0]);
                        }
                    }
                    this.addExhaustion(0.3F);
                } else {
                    this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F);
                    if (litEntityOnFire) {
                        targetEntity.extinguish();
                    }
                }
            }
        }
    }
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) Item(net.minecraft.item.Item) Inject(org.spongepowered.asm.mixin.injection.Inject) GameProfile(com.mojang.authlib.GameProfile) EnumHand(net.minecraft.util.EnumHand) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SpongeCommonEventFactory(org.spongepowered.common.event.SpongeCommonEventFactory) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Mixin(org.spongepowered.asm.mixin.Mixin) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) LockCode(net.minecraft.world.LockCode) SoundCategory(net.minecraft.util.SoundCategory) DamageSourceRegistryModule(org.spongepowered.common.registry.type.event.DamageSourceRegistryModule) At(org.spongepowered.asm.mixin.injection.At) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) InventoryEnderChest(net.minecraft.inventory.InventoryEnderChest) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) AttackEntityEvent(org.spongepowered.api.event.entity.AttackEntityEvent) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) Team(net.minecraft.scoreboard.Team) Sponge(org.spongepowered.api.Sponge) StatBase(net.minecraft.stats.StatBase) DamageTypes(org.spongepowered.api.event.cause.entity.damage.DamageTypes) SpongeHealthData(org.spongepowered.common.data.manipulator.mutable.entity.SpongeHealthData) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) PacketPhase(org.spongepowered.common.event.tracking.phase.packet.PacketPhase) EntityUtil(org.spongepowered.common.entity.EntityUtil) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Shadow(org.spongepowered.asm.mixin.Shadow) LegacyTexts(org.spongepowered.common.text.serializer.LegacyTexts) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) MobEffects(net.minecraft.init.MobEffects) Container(net.minecraft.inventory.Container) Scoreboard(net.minecraft.scoreboard.Scoreboard) EventContext(org.spongepowered.api.event.cause.EventContext) PlayerCapabilities(net.minecraft.entity.player.PlayerCapabilities) ModifierFunction(org.spongepowered.api.event.cause.entity.ModifierFunction) SpongeImpl(org.spongepowered.common.SpongeImpl) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) IEntityMultiPart(net.minecraft.entity.IEntityMultiPart) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) ITargetedLocation(org.spongepowered.common.interfaces.ITargetedLocation) SpongeTexts(org.spongepowered.common.text.SpongeTexts) Vector3d(com.flowpowered.math.vector.Vector3d) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) CooldownTracker(net.minecraft.util.CooldownTracker) DamageModifierTypes(org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes) Overwrite(org.spongepowered.asm.mixin.Overwrite) ExperienceHolderUtils(org.spongepowered.common.data.processor.common.ExperienceHolderUtils) ITextComponent(net.minecraft.util.text.ITextComponent) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) WorldServer(net.minecraft.world.WorldServer) ItemSword(net.minecraft.item.ItemSword) Nullable(javax.annotation.Nullable) Entity(net.minecraft.entity.Entity) MixinEntityLivingBase(org.spongepowered.common.mixin.core.entity.MixinEntityLivingBase) SoundEvents(net.minecraft.init.SoundEvents) StatList(net.minecraft.stats.StatList) Items(net.minecraft.init.Items) World(net.minecraft.world.World) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(org.spongepowered.api.item.inventory.Slot) DamageSource(net.minecraft.util.DamageSource) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) TextComponentString(net.minecraft.util.text.TextComponentString) DamageEventHandler(org.spongepowered.common.event.damage.DamageEventHandler) FoodStats(net.minecraft.util.FoodStats) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) EntityLivingBase(net.minecraft.entity.EntityLivingBase) MathHelper(net.minecraft.util.math.MathHelper) VecHelper(org.spongepowered.common.util.VecHelper) EnumCreatureAttribute(net.minecraft.entity.EnumCreatureAttribute) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) SoundEvent(net.minecraft.util.SoundEvent) Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) WorldServer(net.minecraft.world.WorldServer) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) AttackEntityEvent(org.spongepowered.api.event.entity.AttackEntityEvent) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) SPacketEntityVelocity(net.minecraft.network.play.server.SPacketEntityVelocity) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) Cause(org.spongepowered.api.event.cause.Cause) ItemSword(net.minecraft.item.ItemSword) EnumCreatureAttribute(net.minecraft.entity.EnumCreatureAttribute) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) DamageSource(net.minecraft.util.DamageSource) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) MixinEntityLivingBase(org.spongepowered.common.mixin.core.entity.MixinEntityLivingBase) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ModifierFunction(org.spongepowered.api.event.cause.entity.ModifierFunction) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IEntityMultiPart(net.minecraft.entity.IEntityMultiPart) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

DamageFunction (org.spongepowered.api.event.cause.entity.damage.DamageFunction)25 DamageModifier (org.spongepowered.api.event.cause.entity.damage.DamageModifier)20 List (java.util.List)14 Cause (org.spongepowered.api.event.cause.Cause)13 EventContext (org.spongepowered.api.event.cause.EventContext)13 DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)12 Lists (com.google.common.collect.Lists)11 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)10 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 DamageSource (net.minecraft.util.DamageSource)10 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)10 Optional (java.util.Optional)9 Entity (net.minecraft.entity.Entity)9 Sponge (org.spongepowered.api.Sponge)9 DamageModifierTypes (org.spongepowered.api.event.cause.entity.damage.DamageModifierTypes)9 IBlockState (net.minecraft.block.state.IBlockState)8 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)8 MobEffects (net.minecraft.init.MobEffects)8