Search in sources :

Example 26 with DamageSource

use of net.minecraft.util.DamageSource in project Bewitchment by Um-Mitternacht.

the class ItemThornyGarment method onEntityDamage.

@SubscribeEvent
public void onEntityDamage(LivingHurtEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer && BaublesApi.isBaubleEquipped((EntityPlayer) event.getEntityLiving(), this) > 0) {
        DamageSource source = event.getSource();
        Entity attacker = source.getTrueSource();
        if (attacker instanceof EntityLivingBase && !source.getDamageType().equals("thorns")) {
            // Don't reflect other forms of thorn dmg, otherwise you get an infinite loop
            attacker.attackEntityFrom(DamageSource.causeThornsDamage(event.getEntityLiving()), event.getAmount() * amountReflected);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 27 with DamageSource

use of net.minecraft.util.DamageSource in project Tale-of-Kingdoms by Ivasik78.

the class EntitySantaClaus method onDeath.

@Override
public void onDeath(DamageSource damageSource) {
    if (!worldObj.isRemote) {
        if (damageSource.getSourceOfDamage() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) damageSource.getEntity();
            player.addChatMessage(new ChatComponentTranslation("npc.santa.badKid.dialog"));
            player.dropItem(Items.coal, worldObj.rand.nextInt(32));
            PlayerProvider.get(player).badKid = true;
            IntStream.range(1, rand.nextInt(5)).mapToObj(i -> new EntitySnowman(worldObj)).forEach(golem -> {
                golem.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
                golem.setAttackTarget(player);
                worldObj.spawnEntityInWorld(golem);
            });
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Entity(net.minecraft.entity.Entity) Blocks(net.minecraft.init.Blocks) MathHelper(net.minecraft.util.MathHelper) PlayerProvider(kingdoms.server.PlayerProvider) Items(net.minecraft.init.Items) Item(net.minecraft.item.Item) World(net.minecraft.world.World) Date(java.util.Date) EntityNPC(kingdoms.api.entities.EntityNPC) DamageSource(net.minecraft.util.DamageSource) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Calendar(java.util.Calendar) Material(net.minecraft.block.material.Material) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySnowman(net.minecraft.entity.monster.EntitySnowman) TileEntity(net.minecraft.tileentity.TileEntity) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntitySnowman(net.minecraft.entity.monster.EntitySnowman) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 28 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntityFirechargeChunk method onImpact.

@Override
protected void onImpact(MovingObjectPosition movObjPos) {
    if (!this.worldObj.isRemote) {
        if (movObjPos.entityHit != null) {
            float attackDmg = 1.0F + this.rand.nextFloat();
            boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && ((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
            DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
            if (this.getThrower() == null) {
                dmgSrc = DamageSource.causeThrownDamage(this, this);
            }
            if ((movObjPos.entityHit == this.target || isEnemy) && movObjPos.entityHit.attackEntityFrom(dmgSrc, attackDmg)) {
                if (this.getThrower() instanceof EntityClayMan) {
                    ((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
                }
                if (movObjPos.entityHit instanceof EntityClayMan) {
                    movObjPos.entityHit.setFire(3);
                    movObjPos.entityHit.playSound("random.fizz", 1.0F, 1.0F);
                }
            } else {
                return;
            }
        }
        if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
            // TODO: substitude! change it when
            ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.obsidian);
            // TODO: proper texture arrives
            this.setDead();
        }
        this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
    }
}
Also used : EntityClayMan(de.sanandrew.mods.claysoldiers.entity.EntityClayMan) DamageSource(net.minecraft.util.DamageSource)

Example 29 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntitySnowChunk method onImpact.

@Override
protected void onImpact(MovingObjectPosition movObjPos) {
    if (movObjPos.entityHit != null) {
        boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && ((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
        DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
        if (this.getThrower() == null) {
            dmgSrc = DamageSource.causeThrownDamage(this, this);
        }
        if ((movObjPos.entityHit == this.target || isEnemy) && movObjPos.entityHit.attackEntityFrom(dmgSrc, 0.0F)) {
            if (this.getThrower() instanceof EntityClayMan) {
                ((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
            }
            if (movObjPos.entityHit instanceof EntityClayMan) {
                if (((EntityClayMan) movObjPos.entityHit).addEffect(SoldierEffects.getEffect(SoldierEffects.EFF_SLOWMOTION)) != null) {
                    movObjPos.entityHit.playSound("step.snow", 1.0F, 1.0F);
                }
            }
        } else {
            return;
        }
    }
    if (!this.worldObj.isRemote) {
        if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
            ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.snow);
            this.setDead();
        }
        this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
    }
}
Also used : EntityClayMan(de.sanandrew.mods.claysoldiers.entity.EntityClayMan) DamageSource(net.minecraft.util.DamageSource)

Example 30 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntityClaySoldier method attackEntityAsMob.

@Override
public boolean attackEntityAsMob(Entity entityIn) {
    if (!(entityIn instanceof EntityLivingBase)) {
        return false;
    }
    EntityLivingBase trevor = ((EntityLivingBase) entityIn);
    MutableFloat attackDmg = new MutableFloat(this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue());
    DamageSource dmgSrc = DamageSource.causeMobDamage(this);
    this.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK, upg -> upg.getUpgrade().onAttack(this, upg, trevor, dmgSrc, attackDmg));
    boolean attackSuccess = trevor.attackEntityFrom(dmgSrc, attackDmg.floatValue());
    if (attackSuccess) {
        if (this.i58O55 != null && this.i58O55)
            this.world.getEntitiesWithinAABB(EntityClaySoldier.class, this.getEntityBoundingBox().grow(1.0D), entity -> entity != null && entity != trevor && entity.getSoldierTeam() != this.getSoldierTeam()).forEach(entity -> entity.attackEntityFrom(dmgSrc, attackDmg.floatValue()));
        int fireAspectMod = EnchantmentHelper.getFireAspectModifier(this);
        if (fireAspectMod > 0) {
            trevor.setFire(fireAspectMod * 4);
        }
        this.applyEnchantments(this, trevor);
        float additDifficulty = this.world.getDifficultyForLocation(new BlockPos(this)).getAdditionalDifficulty();
        if (!ItemStackUtils.isValid(this.getHeldItemMainhand())) {
            if (this.isBurning() && this.rand.nextFloat() < additDifficulty * 0.3F) {
                trevor.setFire(2 * (int) additDifficulty);
            }
        }
        this.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK_SUCCESS, upg -> upg.getUpgrade().onAttackSuccess(this, upg, trevor));
    }
    return attackSuccess;
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Arrays(java.util.Arrays) MutableInt(org.apache.commons.lang3.mutable.MutableInt) DataSerializerUUID(de.sanandrew.mods.claysoldiers.network.datasync.DataSerializerUUID) NBTConstants(de.sanandrew.mods.claysoldiers.api.NBTConstants) Item(net.minecraft.item.Item) PacketManager(de.sanandrew.mods.claysoldiers.network.PacketManager) Constants(net.minecraftforge.common.util.Constants) MiscUtils(de.sanandrew.mods.sanlib.lib.util.MiscUtils) NBTTagList(net.minecraft.nbt.NBTTagList) ISoldier(de.sanandrew.mods.claysoldiers.api.soldier.ISoldier) Side(net.minecraftforge.fml.relauncher.Side) EntityAIFollowTarget(de.sanandrew.mods.claysoldiers.entity.ai.EntityAIFollowTarget) Map(java.util.Map) UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry) ITeam(de.sanandrew.mods.claysoldiers.api.soldier.ITeam) DataWatcherBooleans(de.sanandrew.mods.claysoldiers.network.datasync.DataWatcherBooleans) NonNullList(net.minecraft.util.NonNullList) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketSyncUpgrades(de.sanandrew.mods.claysoldiers.network.packet.PacketSyncUpgrades) EnumMap(java.util.EnumMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DataParameter(net.minecraft.network.datasync.DataParameter) UUID(java.util.UUID) CsmMobAttributes(de.sanandrew.mods.claysoldiers.api.CsmMobAttributes) PathNavigateGround(net.minecraft.pathfinding.PathNavigateGround) Collectors(java.util.stream.Collectors) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Objects(java.util.Objects) List(java.util.List) EffectRegistry(de.sanandrew.mods.claysoldiers.registry.effect.EffectRegistry) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ISoldierUpgrade(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgrade) Queue(java.util.Queue) EnumParticle(de.sanandrew.mods.claysoldiers.util.EnumParticle) ItemStackUtils(de.sanandrew.mods.sanlib.lib.util.ItemStackUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) EntityAILookIdle(net.minecraft.entity.ai.EntityAILookIdle) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) ISoldierEffect(de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffect) PathHelper(de.sanandrew.mods.claysoldiers.entity.ai.PathHelper) EnumUpgFunctions(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.EnumUpgFunctions) UpgradeRegistry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeRegistry) EntityAISearchTarget(de.sanandrew.mods.claysoldiers.entity.ai.EntityAISearchTarget) SoldierTargetEnemyEvent(de.sanandrew.mods.claysoldiers.api.event.SoldierTargetEnemyEvent) ItemStack(net.minecraft.item.ItemStack) ByteBuf(io.netty.buffer.ByteBuf) SoldierDeathEvent(de.sanandrew.mods.claysoldiers.api.event.SoldierDeathEvent) UuidUtils(de.sanandrew.mods.sanlib.lib.util.UuidUtils) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Entity(net.minecraft.entity.Entity) Event(net.minecraftforge.fml.common.eventhandler.Event) SoundEvents(net.minecraft.init.SoundEvents) TeamRegistry(de.sanandrew.mods.claysoldiers.registry.team.TeamRegistry) CsmConfiguration(de.sanandrew.mods.claysoldiers.util.CsmConfiguration) World(net.minecraft.world.World) EntityAIFollowEnemy(de.sanandrew.mods.claysoldiers.entity.ai.EntityAIFollowEnemy) EntityAIWander(net.minecraft.entity.ai.EntityAIWander) EntityAIMoveTowardsRestriction(net.minecraft.entity.ai.EntityAIMoveTowardsRestriction) BlockPos(net.minecraft.util.math.BlockPos) ISoldierEffectInst(de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst) DamageSource(net.minecraft.util.DamageSource) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) EntityAIFollowInventory(de.sanandrew.mods.claysoldiers.entity.ai.EntityAIFollowInventory) Consumer(java.util.function.Consumer) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) ISoldierUpgradeInst(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst) DataSerializers(net.minecraft.network.datasync.DataSerializers) ItemRegistry(de.sanandrew.mods.claysoldiers.registry.ItemRegistry) EnumUpgradeType(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.EnumUpgradeType) EntityAISearchInventory(de.sanandrew.mods.claysoldiers.entity.ai.EntityAISearchInventory) PacketSyncEffects(de.sanandrew.mods.claysoldiers.network.packet.PacketSyncEffects) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IDisruptable(de.sanandrew.mods.claysoldiers.api.IDisruptable) ClaySoldiersMod(de.sanandrew.mods.claysoldiers.util.ClaySoldiersMod) EntityCreature(net.minecraft.entity.EntityCreature) MoverType(net.minecraft.entity.MoverType) EntityAIBase(net.minecraft.entity.ai.EntityAIBase) SoundEvent(net.minecraft.util.SoundEvent) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) DamageSource(net.minecraft.util.DamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

DamageSource (net.minecraft.util.DamageSource)61 EntityLivingBase (net.minecraft.entity.EntityLivingBase)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)29 Entity (net.minecraft.entity.Entity)28 ItemStack (net.minecraft.item.ItemStack)15 BlockPos (net.minecraft.util.math.BlockPos)11 World (net.minecraft.world.World)10 IBlockState (net.minecraft.block.state.IBlockState)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Item (net.minecraft.item.Item)8 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)7 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 MobEffects (net.minecraft.init.MobEffects)6 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)6 EntityDamageSourceIndirect (net.minecraft.util.EntityDamageSourceIndirect)6 MathHelper (net.minecraft.util.math.MathHelper)6 Collection (java.util.Collection)5