Search in sources :

Example 1 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project NetherEx by LogicTechCorp.

the class EntityGhastQueenFireball method onImpact.

@Override
protected void onImpact(RayTraceResult result) {
    if (!world.isRemote) {
        if (result.entityHit != null) {
            result.entityHit.attackEntityFrom(new EntityDamageSourceIndirect("ghastQueenFireball", this, shootingEntity).setFireDamage().setProjectile(), 24.0F);
            applyEnchantments(shootingEntity, result.entityHit);
        }
        boolean flag = world.getGameRules().getBoolean("mobGriefing");
        world.newExplosion(null, posX, posY, posZ, (float) explosionPower, flag, flag);
        setDead();
    }
}
Also used : EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect)

Example 2 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project SpongeCommon by SpongePowered.

the class DamageEventHandler method generateCauseFor.

public static void generateCauseFor(DamageSource damageSource) {
    if (damageSource instanceof EntityDamageSourceIndirect) {
        net.minecraft.entity.Entity source = damageSource.getTrueSource();
        if (!(source instanceof EntityPlayer) && source != null) {
            final IMixinEntity mixinEntity = EntityUtil.toMixin(source);
            mixinEntity.getNotifierUser().ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
            mixinEntity.getCreatorUser().ifPresent(owner -> Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner));
        }
    } else if (damageSource instanceof EntityDamageSource) {
        net.minecraft.entity.Entity source = damageSource.getTrueSource();
        if (!(source instanceof EntityPlayer) && source != null) {
            final IMixinEntity mixinEntity = EntityUtil.toMixin(source);
            // TODO only have a UUID, want a user
            mixinEntity.getNotifierUser().ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
            mixinEntity.getCreatorUser().ifPresent(creator -> Sponge.getCauseStackManager().addContext(EventContextKeys.CREATOR, creator));
        }
    } else if (damageSource instanceof BlockDamageSource) {
        Location<org.spongepowered.api.world.World> location = ((BlockDamageSource) damageSource).getLocation();
        BlockPos blockPos = ((IMixinLocation) (Object) location).getBlockPos();
        final IMixinChunk mixinChunk = (IMixinChunk) ((net.minecraft.world.World) location.getExtent()).getChunkFromBlockCoords(blockPos);
        mixinChunk.getBlockNotifier(blockPos).ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
        mixinChunk.getBlockOwner(blockPos).ifPresent(owner -> Sponge.getCauseStackManager().addContext(EventContextKeys.CREATOR, owner));
    }
    Sponge.getCauseStackManager().pushCause(damageSource);
}
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) Entity(net.minecraft.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) World(org.spongepowered.api.world.World) EntityDamageSource(net.minecraft.util.EntityDamageSource) BlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.BlockDamageSource) FallingBlockDamageSource(org.spongepowered.api.event.cause.entity.damage.source.FallingBlockDamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project takumicraft by TNTModders.

the class EntityTakumiArrow method onHit.

@Override
protected void onHit(RayTraceResult raytraceResultIn) {
    if (raytraceResultIn.typeOfHit == Type.ENTITY) {
        if (raytraceResultIn.entityHit == this.shootingEntity) {
            return;
        }
        raytraceResultIn.entityHit.attackEntityFrom(new EntityDamageSourceIndirect("explosion.player", this.shootingEntity, this), 15.0f);
    }
    TakumiUtils.takumiCreateExplosion(world, this, this.posX, this.posY, this.posZ, power, false, false);
    pierce--;
    if (pierce <= 0) {
        this.setDead();
    }
}
Also used : EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect)

Example 4 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project BetterRain by OreCruncher.

the class DamageEffectHandler method onLivingHurt.

@SubscribeEvent(priority = EventPriority.LOW)
public void onLivingHurt(final LivingHurtEvent event) {
    if (event == null || event.entity == null || event.entity.worldObj == null || event.entity.worldObj.isRemote)
        return;
    // Living heal should handle heals - I think..
    if (event.ammount <= 0 || event.entityLiving == null)
        return;
    // A bit hokey - may work.
    boolean isCrit = false;
    if (event.source instanceof EntityDamageSourceIndirect) {
        final EntityDamageSourceIndirect dmgSource = (EntityDamageSourceIndirect) event.source;
        if (dmgSource.getSourceOfDamage() instanceof EntityArrow) {
            final EntityArrow arrow = (EntityArrow) dmgSource.getSourceOfDamage();
            isCrit = arrow.getIsCritical();
        }
    } else if (event.source instanceof EntityDamageSource) {
        final EntityDamageSource dmgSource = (EntityDamageSource) event.source;
        if (dmgSource.getSourceOfDamage() instanceof EntityPlayer) {
            final EntityPlayer player = (EntityPlayer) dmgSource.getSourceOfDamage();
            isCrit = isCritical(player, event.entityLiving);
        }
    }
    final HealthData data = new HealthData(event.entityLiving, isCrit, (int) event.ammount);
    Network.sendHealthUpdate(data, event.entity.worldObj.provider.getDimensionId());
}
Also used : EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityDamageSource(net.minecraft.util.EntityDamageSource) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with EntityDamageSourceIndirect

use of net.minecraft.util.EntityDamageSourceIndirect in project NetherEx by LogicTechCorp.

the class EntityGhastlingFireball method onImpact.

@Override
protected void onImpact(RayTraceResult result) {
    if (!world.isRemote) {
        if (result.entityHit != null && !(result.entityHit instanceof EntityGhastQueen)) {
            result.entityHit.attackEntityFrom(new EntityDamageSourceIndirect("ghastlingFireball", this, shootingEntity).setFireDamage().setProjectile(), 6.0F);
            applyEnchantments(shootingEntity, result.entityHit);
        }
        boolean flag = world.getGameRules().getBoolean("mobGriefing");
        world.newExplosion(null, posX, posY, posZ, (float) explosionPower, flag, flag);
        setDead();
    }
}
Also used : EntityDamageSourceIndirect(net.minecraft.util.EntityDamageSourceIndirect) EntityGhastQueen(nex.entity.boss.EntityGhastQueen)

Aggregations

EntityDamageSourceIndirect (net.minecraft.util.EntityDamageSourceIndirect)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 Entity (net.minecraft.entity.Entity)3 EntityDamageSource (net.minecraft.util.EntityDamageSource)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityArrow (net.minecraft.entity.projectile.EntityArrow)2 DamageSource (net.minecraft.util.DamageSource)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 BlockPos (net.minecraft.util.math.BlockPos)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1