Search in sources :

Example 51 with DamageSource

use of net.minecraft.util.DamageSource in project BloodMagic by WayofTime.

the class WillHandler method onLivingDrops.

// Add/Drop Demon Will for Player
@SubscribeEvent
public static void onLivingDrops(LivingDropsEvent event) {
    EntityLivingBase attackedEntity = event.getEntityLiving();
    DamageSource source = event.getSource();
    Entity entity = source.getTrueSource();
    if (attackedEntity.isPotionActive(RegistrarBloodMagic.SOUL_SNARE) && (attackedEntity instanceof EntityMob || attackedEntity.getEntityWorld().getDifficulty() == EnumDifficulty.PEACEFUL)) {
        PotionEffect eff = attackedEntity.getActivePotionEffect(RegistrarBloodMagic.SOUL_SNARE);
        int lvl = eff.getAmplifier();
        double amountOfSouls = attackedEntity.getEntityWorld().rand.nextDouble() * (lvl + 1) * (lvl + 1) * 5;
        ItemStack soulStack = ((IDemonWill) RegistrarBloodMagicItems.MONSTER_SOUL).createWill(0, amountOfSouls);
        event.getDrops().add(new EntityItem(attackedEntity.getEntityWorld(), attackedEntity.posX, attackedEntity.posY, attackedEntity.posZ, soulStack));
    }
    if (entity != null && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        ItemStack heldStack = player.getHeldItemMainhand();
        if (heldStack.getItem() instanceof IDemonWillWeapon && !player.getEntityWorld().isRemote) {
            IDemonWillWeapon demonWillWeapon = (IDemonWillWeapon) heldStack.getItem();
            List<ItemStack> droppedSouls = demonWillWeapon.getRandomDemonWillDrop(attackedEntity, player, heldStack, event.getLootingLevel());
            if (!droppedSouls.isEmpty()) {
                ItemStack remainder;
                for (ItemStack willStack : droppedSouls) {
                    remainder = PlayerDemonWillHandler.addDemonWill(player, willStack);
                    if (!remainder.isEmpty()) {
                        EnumDemonWillType pickupType = ((IDemonWill) remainder.getItem()).getType(remainder);
                        if (((IDemonWill) remainder.getItem()).getWill(pickupType, remainder) >= 0.0001) {
                            event.getDrops().add(new EntityItem(attackedEntity.getEntityWorld(), attackedEntity.posX, attackedEntity.posY, attackedEntity.posZ, remainder));
                        }
                    }
                }
                player.inventoryContainer.detectAndSendChanges();
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) PotionEffect(net.minecraft.potion.PotionEffect) EntityMob(net.minecraft.entity.monster.EntityMob) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 52 with DamageSource

use of net.minecraft.util.DamageSource in project minecolonies by Minecolonies.

the class EntityAIBarbarianAttackMelee method attack.

/**
 * AI for an Entity to attack the target
 *
 * @param target The target to attack
 */
private void attack(final EntityLivingBase target) {
    if (target != null) {
        double damageToBeDealt = BarbarianSpawnUtils.ATTACK_DAMAGE;
        if (entity instanceof EntityChiefBarbarian) {
            damageToBeDealt += 1.0;
        }
        if (entity.getDistance(target) <= MIN_DISTANCE_FOR_ATTACK && lastAttack <= 0 && entity.canEntityBeSeen(target)) {
            target.attackEntityFrom(new DamageSource(entity.getName()), (float) damageToBeDealt);
            entity.swingArm(EnumHand.MAIN_HAND);
            entity.playSound(SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, (float) 1.0D, (float) getRandomPitch());
            target.setRevengeTarget(entity);
            lastAttack = CYCLES_TO_WAIT;
        }
        if (lastAttack > 0) {
            lastAttack -= 1;
        }
        entity.faceEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
        entity.getLookHelper().setLookPositionWithEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
        entity.getNavigator().tryMoveToEntityLiving(target, ATTACK_SPEED);
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource)

Example 53 with DamageSource

use of net.minecraft.util.DamageSource in project ImmersiveEngineering by BluSunrize.

the class ThermalFoundationHelper method init.

@Override
public void init() {
    // TE Compat for smelter recipes. Not worth a separate module.
    OreDictionary.registerOre("crystalSlag", new ItemStack(IEContent.itemMaterial, 1, 7));
    ChemthrowerHandler.registerEffect("coal", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 0));
    ChemthrowerHandler.registerFlammable("coal");
    ChemthrowerHandler.registerEffect("crude_oil", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(IEPotions.flammable, 140, 0), new PotionEffect(MobEffects.BLINDNESS, 80, 1)));
    ChemthrowerHandler.registerFlammable("crude_oil");
    ChemthrowerHandler.registerEffect("refined_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 1));
    ChemthrowerHandler.registerFlammable("refined_oil");
    ChemthrowerHandler.registerEffect("resin", new ChemthrowerEffect_Potion(null, 0, IEPotions.sticky, 100, 1));
    ChemthrowerHandler.registerEffect("tree_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 120, 0));
    ChemthrowerHandler.registerFlammable("tree_oil");
    ChemthrowerHandler.registerEffect("redstone", new ChemthrowerEffect_Potion(null, 0, IEPotions.conductive, 100, 1));
    ChemthrowerHandler.registerEffect("glowstone", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.GLOWING, 120, 0), new PotionEffect(MobEffects.SPEED, 120, 0), new PotionEffect(MobEffects.JUMP_BOOST, 120, 0)));
    ChemthrowerHandler.registerEffect("ender", new ChemthrowerEffect_RandomTeleport(null, 0, 1));
    try {
        Class c_DamageHelper = Class.forName("cofh.lib.util.helpers.DamageHelper");
        DamageSource pyrotheum = (DamageSource) c_DamageHelper.getDeclaredField("pyrotheum").get(null);
        Field f_explodeCreepers = Class.forName("cofh.thermalfoundation.fluid.BlockFluidPyrotheum").getDeclaredField("effect");
        f_explodeCreepers.setAccessible(true);
        if ((boolean) f_explodeCreepers.get(null))
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3) {

                @Override
                public void applyToEntity(EntityLivingBase target, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
                    super.applyToEntity(target, shooter, thrower, fluid);
                    if (target instanceof EntityCreeper) {
                        target.getEntityWorld().createExplosion(target, target.posX, target.posY, target.posZ, 6.0F, target.getEntityWorld().getGameRules().getBoolean("mobGriefing"));
                        target.setDead();
                    }
                }
            });
        else
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3));
        DamageSource cryotheum = (DamageSource) c_DamageHelper.getDeclaredField("cryotheum").get(null);
        ChemthrowerHandler.registerEffect("cryotheum", new ChemthrowerEffect_Potion(cryotheum, 2, MobEffects.SLOWNESS, 50, 3));
    } catch (Exception e) {
    }
    ChemthrowerHandler.registerEffect("aerotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.INVISIBILITY, 60, 0), new PotionEffect(MobEffects.WATER_BREATHING, 300, 0)));
    ChemthrowerHandler.registerEffect("petrotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.HASTE, 300, 2), new PotionEffect(MobEffects.NIGHT_VISION, 300, 0), new PotionEffect(MobEffects.RESISTANCE, 300, 1)) {

        @Override
        public void applyToBlock(World world, RayTraceResult mop, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
            IBlockState state = world.getBlockState(mop.getBlockPos());
            if (state.getBlock() == Blocks.STONE || state.getBlock() == Blocks.COBBLESTONE || state.getBlock() == Blocks.STONEBRICK || state.getBlock() == Blocks.MOSSY_COBBLESTONE)
                world.setBlockState(mop.getBlockPos(), Blocks.GRAVEL.getDefaultState());
        }
    });
    ChemthrowerHandler.registerEffect("mana", new ChemthrowerEffect_RandomTeleport(null, 0, .01f));
    final Item itemPhyto = Item.REGISTRY.getObject(new ResourceLocation("thermalfoundation:fertilizer"));
    if (itemPhyto != null)
        BelljarHandler.registerItemFertilizer(new ItemFertilizerHandler() {

            @Override
            public boolean isValid(@Nullable ItemStack fertilizer) {
                return !fertilizer.isEmpty() && fertilizer.getItem() == itemPhyto;
            }

            @Override
            public float getGrowthMultiplier(ItemStack fertilizer, ItemStack seed, ItemStack soil, TileEntity tile) {
                return BelljarHandler.solidFertilizerModifier * (1.5f + (.25f * fertilizer.getMetadata()));
            }
        });
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) DamageSource(net.minecraft.util.DamageSource) ChemthrowerEffect_Damage(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage) PotionEffect(net.minecraft.potion.PotionEffect) Fluid(net.minecraftforge.fluids.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion) ChemthrowerEffect_RandomTeleport(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_RandomTeleport) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) Item(net.minecraft.item.Item) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) ItemFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 54 with DamageSource

use of net.minecraft.util.DamageSource in project ImmersiveEngineering by BluSunrize.

the class ThaumcraftHelper method init.

@Override
public void init() {
    FMLInterModComms.sendMessage("thaumcraft", "harvestStackedCrop", new ItemStack(IEContent.blockCrop, 5));
    Potion potion_ward = Potion.getPotionFromResourceLocation("thaumcraft:warpward");
    if (potion_ward != null)
        ChemthrowerHandler.registerEffect("purifying_fluid", new ChemthrowerEffect_Potion(null, 0, potion_ward, 100, 0));
    try {
        Class c_DamageSourceThaumcraft = Class.forName("thaumcraft.api.damagesource.DamageSourceThaumcraft");
        if (c_DamageSourceThaumcraft != null) {
            DamageSource dmg_dissolve = (DamageSource) c_DamageSourceThaumcraft.getField("dissolve").get(null);
            ChemthrowerHandler.registerEffect("liquid_death", new ChemthrowerEffect_Damage(dmg_dissolve, 4));
        }
    } catch (Exception e) {
    }
    try {
        Class c_TileSmelter = Class.forName("thaumcraft.common.tiles.essentia.TileSmelter");
        if (c_TileSmelter != null)
            ExternalHeaterHandler.registerHeatableAdapter(c_TileSmelter, new AlchemyFurnaceAdapter(c_TileSmelter));
    } catch (Exception e) {
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) ChemthrowerEffect_Damage(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion) Potion(net.minecraft.potion.Potion) ItemStack(net.minecraft.item.ItemStack) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)

Aggregations

DamageSource (net.minecraft.util.DamageSource)54 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)24 Entity (net.minecraft.entity.Entity)23 ItemStack (net.minecraft.item.ItemStack)19 BlockPos (net.minecraft.util.math.BlockPos)10 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EntityMinecart (net.minecraft.entity.item.EntityMinecart)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)8 World (net.minecraft.world.World)8 IBlockState (net.minecraft.block.state.IBlockState)7 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 PotionEffect (net.minecraft.potion.PotionEffect)6 MathHelper (net.minecraft.util.math.MathHelper)6 Collection (java.util.Collection)5 Map (java.util.Map)5