Search in sources :

Example 21 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project NetherEx by LogicTechCorp.

the class EventHandler method onLivingAttacked.

@SubscribeEvent
public static void onLivingAttacked(LivingAttackEvent event) {
    EntityLivingBase entity = (EntityLivingBase) event.getEntity();
    World world = entity.getEntityWorld();
    BlockPos pos = entity.getPosition();
    DamageSource source = event.getSource();
    if (source.isFireDamage()) {
        if (!entity.isImmuneToFire() && entity.isRiding() && entity.getRidingEntity() instanceof EntityObsidianBoat) {
            event.setCanceled(true);
        }
    }
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (source.isFireDamage()) {
            if (ArmorUtil.isWearingFullArmorSet(player, NetherExMaterials.ARMOR_HIDE_SALAMANDER)) {
                event.setCanceled(true);
            }
        }
        if (player.dimension == -1) {
            if (source == DamageSource.LAVA && player.isPotionActive(MobEffects.FIRE_RESISTANCE)) {
                player.addStat(NetherExAchievements.STAYIN_FROSTY);
            }
        }
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) EntityObsidianBoat(nex.entity.item.EntityObsidianBoat) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 22 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project NetherEx by LogicTechCorp.

the class ExplosionSpore method doExplosionA.

@Override
public void doExplosionA() {
    if (!world.isRemote) {
        Set<BlockPos> set = Sets.newHashSet();
        for (int j = 0; j < 16; ++j) {
            for (int k = 0; k < 16; ++k) {
                for (int l = 0; l < 16; ++l) {
                    if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                        double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
                        double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
                        double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
                        double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                        d0 = d0 / d3;
                        d1 = d1 / d3;
                        d2 = d2 / d3;
                        float f = explosionSize * (0.7F + world.rand.nextFloat() * 0.6F);
                        double d4 = explosionX;
                        double d6 = explosionY;
                        double d8 = explosionZ;
                        for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                            BlockPos blockpos = new BlockPos(d4, d6, d8);
                            IBlockState iblockstate = world.getBlockState(blockpos);
                            if (iblockstate.getMaterial() != Material.AIR) {
                                float f2 = exploder != null ? exploder.getExplosionResistance(this, world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, (Entity) null, this);
                                f -= (f2 + 0.3F) * 0.3F;
                            }
                            if (f > 0.0F && (exploder == null || exploder.verifyExplosion(this, world, blockpos, iblockstate, f))) {
                                set.add(blockpos);
                            }
                            d4 += d0 * 0.30000001192092896D;
                            d6 += d1 * 0.30000001192092896D;
                            d8 += d2 * 0.30000001192092896D;
                        }
                    }
                }
            }
        }
        affectedBlockPositions.addAll(set);
        float f3 = explosionSize * 2.0F;
        int k1 = MathHelper.floor(explosionX - (double) f3 - 1.0D);
        int l1 = MathHelper.floor(explosionX + (double) f3 + 1.0D);
        int i2 = MathHelper.floor(explosionY - (double) f3 - 1.0D);
        int i1 = MathHelper.floor(explosionY + (double) f3 + 1.0D);
        int j2 = MathHelper.floor(explosionZ - (double) f3 - 1.0D);
        int j1 = MathHelper.floor(explosionZ + (double) f3 + 1.0D);
        List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
        ForgeEventFactory.onExplosionDetonate(world, this, list, f3);
        Vec3d vec3d = new Vec3d(explosionX, explosionY, explosionZ);
        for (Entity entity : list) {
            if (!entity.isImmuneToExplosions()) {
                double d12 = entity.getDistance(explosionX, explosionY, explosionZ) / (double) f3;
                if (d12 <= 1.0D) {
                    double d5 = entity.posX - explosionX;
                    double d7 = entity.posY + (double) entity.getEyeHeight() - explosionY;
                    double d9 = entity.posZ - explosionZ;
                    double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
                    if (d13 != 0.0D) {
                        d5 = d5 / d13;
                        d7 = d7 / d13;
                        d9 = d9 / d13;
                        double d14 = (double) world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
                        double d10 = (1.0D - d12) * d14;
                        if (!(entity instanceof EntitySporeCreeper) && !(entity instanceof EntitySpore)) {
                            entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
                        }
                        if (entity instanceof EntityLivingBase) {
                            ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(NetherExEffects.SPORE, 2400, 0));
                        }
                        double d11 = d10;
                        if (entity instanceof EntityLivingBase) {
                            d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
                        }
                        entity.motionX += d5 * d11;
                        entity.motionY += d7 * d11;
                        entity.motionZ += d9 * d11;
                        if (entity instanceof EntityPlayer) {
                            EntityPlayer entityplayer = (EntityPlayer) entity;
                            if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
                                playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntitySpore(nex.entity.monster.EntitySpore) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) EntitySporeCreeper(nex.entity.monster.EntitySporeCreeper) Vec3d(net.minecraft.util.math.Vec3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 23 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project SecurityCraft by Geforce132.

the class TileEntityClaymore method updateEntity.

@Override
public void updateEntity() {
    if (getWorld().isRemote)
        return;
    else {
        if (getWorld().getBlock(xCoord, yCoord, zCoord) == SCContent.claymoreDefused)
            return;
        if (cooldown > 0) {
            cooldown--;
            return;
        }
        if (cooldown == 0) {
            BlockUtils.destroyBlock(getWorld(), xCoord, yCoord, zCoord, false);
            getWorld().createExplosion((Entity) null, entityX, entityY + 0.5F, entityZ, 3.5F, true);
            return;
        }
        int meta = getWorld().getBlockMetadata(xCoord, yCoord, zCoord);
        AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1);
        if (meta == 3)
            axisalignedbb = axisalignedbb.addCoord(0, 0, -SecurityCraft.config.claymoreRange);
        else if (meta == 1)
            axisalignedbb = axisalignedbb.addCoord(0, 0, SecurityCraft.config.claymoreRange);
        else if (meta == 2)
            axisalignedbb = axisalignedbb.addCoord(SecurityCraft.config.claymoreRange, 0, 0);
        else if (meta == 4)
            axisalignedbb = axisalignedbb.addCoord(-SecurityCraft.config.claymoreRange, 0, 0);
        List<?> list = getWorld().getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityLivingBase entityliving;
        while (iterator.hasNext()) {
            entityliving = (EntityLivingBase) iterator.next();
            if (PlayerUtils.isPlayerMountedOnCamera(entityliving))
                continue;
            entityX = entityliving.posX;
            entityY = entityliving.posY;
            entityZ = entityliving.posZ;
            cooldown = 20;
            getWorld().playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "random.click", 0.3F, 0.6F);
            break;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 24 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project SecurityCraft by Geforce132.

the class BlockLaser method onEntityCollidedWithBlock.

/**
 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
 */
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
    if (!par1World.isRemote && par5Entity instanceof EntityLivingBase && !HelpfulMethods.doesMobHavePotionEffect((EntityLivingBase) par5Entity, Potion.invisibility)) {
        for (int i = 1; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2 + i, par3, par4);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2 + i, par3, par4)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2 + i, par3, par4, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2 + i, par3, par4, mod_SecurityCraft.LaserBlock, 2, 3); //TODO
                par1World.setBlockMetadataWithNotify(par2 + i, par3, par4, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2 + i, par3, par4, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2 + i, par3, par4, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2 + i, par3, par4, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2 + i, par3, par4) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2 + i, par3, par4)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
        for (int i = 0; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2 - i, par3, par4);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2 - i, par3, par4)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2 - i, par3, par4, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2 - i, par3, par4, mod_SecurityCraft.LaserBlock, 2, 3);
                par1World.setBlockMetadataWithNotify(par2 - i, par3, par4, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2 - i, par3, par4, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2 - i, par3, par4, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2 - i, par3, par4, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2 - i, par3, par4) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2 - i, par3, par4)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
        for (int i = 0; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2, par3, par4 + i);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4 + i)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2, par3, par4 + i, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2, par3, par4 + i, mod_SecurityCraft.LaserBlock, 2, 3);
                par1World.setBlockMetadataWithNotify(par2, par3, par4 + i, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + i, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2, par3, par4 + i, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + i, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2, par3, par4 + i) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4 + i)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
        for (int i = 0; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2, par3, par4 - i);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4 - i)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2, par3, par4 - i, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2, par3, par4 - i, mod_SecurityCraft.LaserBlock, 2, 3);
                par1World.setBlockMetadataWithNotify(par2, par3, par4 - i, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2, par3, par4 - i, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2, par3, par4 - i, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2, par3, par4 - i, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2, par3, par4 - i) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2, par3, par4 - i)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
        for (int i = 0; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2, par3 + i, par4);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2, par3 + i, par4)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2, par3 + i, par4, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2, par3 + i, par4, mod_SecurityCraft.LaserBlock, 2, 3);
                par1World.setBlockMetadataWithNotify(par2, par3 + i, par4, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2, par3 + i, par4, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2, par3 + i, par4, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2, par3 + i, par4, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2, par3 + i, par4) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2, par3 + i, par4)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
        for (int i = 0; i <= mod_SecurityCraft.configHandler.laserBlockRange; i++) {
            Block id = par1World.getBlock(par2, par3 - i, par4);
            if (id == mod_SecurityCraft.LaserBlock) {
                if (((CustomizableSCTE) par1World.getTileEntity(par2, par3 - i, par4)).hasModule(EnumCustomModules.WHITELIST) && HelpfulMethods.getPlayersFromModule(par1World, par2, par3 - i, par4, EnumCustomModules.WHITELIST).contains(((EntityLivingBase) par5Entity).getCommandSenderName())) {
                    return;
                }
                // par1World.setBlock(par2, par3 - i, par4, mod_SecurityCraft.LaserBlock, 2, 3);
                par1World.setBlockMetadataWithNotify(par2, par3 - i, par4, 2, 3);
                par1World.notifyBlocksOfNeighborChange(par2, par3 - i, par4, mod_SecurityCraft.LaserBlock);
                par1World.scheduleBlockUpdate(par2, par3 - i, par4, mod_SecurityCraft.LaserBlock, 50);
                par1World.notifyBlocksOfNeighborChange(par2, par3 - i, par4, mod_SecurityCraft.LaserBlock);
                if (par1World.getTileEntity(par2, par3 - i, par4) instanceof CustomizableSCTE && ((CustomizableSCTE) par1World.getTileEntity(par2, par3 - i, par4)).hasModule(EnumCustomModules.HARMING)) {
                    float f = ((EntityLivingBase) par5Entity).getHealth();
                    ((EntityLivingBase) par5Entity).attackEntityFrom(DamageSource.generic, 10F);
                // ((EntityLivingBase) par5Entity).setHealth(f - 0.5F);
                }
            } else {
                continue;
            }
        }
    }
}
Also used : CustomizableSCTE(org.freeforums.geforce.securitycraft.tileentity.CustomizableSCTE) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block)

Example 25 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project SecurityCraft by Geforce132.

the class BlockBouncingBetty method onEntityCollidedWithBlock.

/**
 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
 */
public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
    if (par5Entity instanceof EntityLivingBase) {
        par1World.setBlockToAir(par2, par3, par4);
        EntityTnTCompact entitytntprimed = new EntityTnTCompact(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F), (EntityLivingBase) par5Entity);
        entitytntprimed.fuse = 15;
        entitytntprimed.motionY = 0.50D;
        par1World.spawnEntityInWorld(entitytntprimed);
        par1World.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
    } else {
        return;
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityTnTCompact(org.freeforums.geforce.securitycraft.entity.EntityTnTCompact)

Aggregations

EntityLivingBase (net.minecraft.entity.EntityLivingBase)594 EntityPlayer (net.minecraft.entity.player.EntityPlayer)201 Entity (net.minecraft.entity.Entity)177 PotionEffect (net.minecraft.potion.PotionEffect)106 ItemStack (net.minecraft.item.ItemStack)88 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)86 BlockPos (net.minecraft.util.math.BlockPos)77 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)77 Vec3d (net.minecraft.util.math.Vec3d)65 World (net.minecraft.world.World)57 IBlockState (net.minecraft.block.state.IBlockState)45 List (java.util.List)38 ArrayList (java.util.ArrayList)37 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)37 TileEntity (net.minecraft.tileentity.TileEntity)37 EntityItem (net.minecraft.entity.item.EntityItem)32 DamageSource (net.minecraft.util.DamageSource)25 Block (net.minecraft.block.Block)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)23 WorldServer (net.minecraft.world.WorldServer)23