Search in sources :

Example 1 with IAnimals

use of net.minecraft.entity.passive.IAnimals in project RFTools by McJty.

the class TickShieldBlockTileEntity method handleDamage.

private void handleDamage() {
    damageTimer--;
    if (damageTimer > 0) {
        return;
    }
    damageTimer = 10;
    if (beamBox == null) {
        int xCoord = getPos().getX();
        int yCoord = getPos().getY();
        int zCoord = getPos().getZ();
        beamBox = new AxisAlignedBB(xCoord - .4, yCoord - .4, zCoord - .4, xCoord + 1.4, yCoord + 2.0, zCoord + 1.4);
    }
    if (shieldBlock != null) {
        ShieldTEBase shieldTileEntity = (ShieldTEBase) getWorld().getTileEntity(shieldBlock);
        if (shieldTileEntity != null) {
            List<Entity> l = getWorld().getEntitiesWithinAABB(Entity.class, beamBox);
            for (Entity entity : l) {
                if ((damageBits & AbstractShieldBlock.META_HOSTILE) != 0 && entity instanceof IMob) {
                    if (checkEntityDamage(shieldTileEntity, HostileFilter.HOSTILE)) {
                        shieldTileEntity.applyDamageToEntity(entity);
                    }
                } else if ((damageBits & AbstractShieldBlock.META_PASSIVE) != 0 && entity instanceof IAnimals) {
                    if (checkEntityDamage(shieldTileEntity, AnimalFilter.ANIMAL)) {
                        shieldTileEntity.applyDamageToEntity(entity);
                    }
                } else if ((damageBits & AbstractShieldBlock.META_PLAYERS) != 0 && entity instanceof EntityPlayer) {
                    if (checkPlayerDamage(shieldTileEntity, (EntityPlayer) entity)) {
                        shieldTileEntity.applyDamageToEntity(entity);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 2 with IAnimals

use of net.minecraft.entity.passive.IAnimals in project RFTools by McJty.

the class SensorTileEntity method checkEntitiesPassive.

private boolean checkEntitiesPassive(BlockPos pos1, EnumFacing dir) {
    List<Entity> entities = getWorld().getEntitiesWithinAABB(EntityCreature.class, getCachedBox(pos1, dir));
    int cnt = 0;
    for (Entity entity : entities) {
        if (entity instanceof IAnimals && !(entity instanceof IMob)) {
            cnt++;
            if (cnt >= number) {
                return true;
            }
        }
    }
    return false;
}
Also used : LogicTileEntity(mcjty.rftools.blocks.logic.generic.LogicTileEntity) Entity(net.minecraft.entity.Entity) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob)

Example 3 with IAnimals

use of net.minecraft.entity.passive.IAnimals in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntityJoinWorldEvent.

@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent event) {
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    WorldProvider provider = world.provider;
    if (!(provider instanceof GenericWorldProvider))
        return;
    DimensionInformation dimensionInformation = ((GenericWorldProvider) provider).getDimensionInformation();
    if (dimensionInformation.isNoanimals() && event.getEntity() instanceof IAnimals && !(event.getEntity() instanceof IMob)) {
        event.setCanceled(true);
        Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
    }
}
Also used : IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IAnimals

use of net.minecraft.entity.passive.IAnimals in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.getWorld();
    WorldProvider provider = world.provider;
    if (!(provider instanceof GenericWorldProvider))
        return;
    DimensionInformation dimensionInformation = ((GenericWorldProvider) provider).getDimensionInformation();
    if (PowerConfiguration.preventSpawnUnpowered) {
        DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
        if (storage.getEnergyLevel(provider.getDimension()) <= 0) {
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Dimension power low: Prevented a spawn of " + event.getEntity().getClass().getName());
        }
    }
    if (dimensionInformation.hasEffectType(EffectType.EFFECT_STRONGMOBS) || dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
        if (event.getEntity() instanceof EntityLivingBase) {
            EntityLivingBase entityLivingBase = (EntityLivingBase) event.getEntity();
            IAttributeInstance entityAttribute = entityLivingBase.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH);
            double newMax = entityAttribute.getBaseValue() * (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS) ? GeneralConfiguration.brutalMobsFactor : GeneralConfiguration.strongMobsFactor);
            entityAttribute.setBaseValue(newMax);
            entityLivingBase.setHealth((float) newMax);
        }
    }
    if (event.getEntity() instanceof IMob) {
        /* BlockPos coordinate = new BlockPos((int) event.getEntity().posX, (int) event.getEntity().posY, (int) event.getEntity().posZ);
            if (PeacefulAreaManager.isPeaceful(new GlobalCoordinate(coordinate, id))) {
                event.setResult(Event.Result.DENY);
                Logging.logDebug("Peaceful manager: Prevented a spawn of " + event.entity.getClass().getName());
            } else */
        if (dimensionInformation.isPeaceful()) {
            // RFTools dimension.
            event.setResult(Event.Result.DENY);
            Logging.logDebug("Peaceful dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
        }
    } else if (event.getEntity() instanceof IAnimals && dimensionInformation.isNoanimals()) {
        // RFTools dimension.
        event.setResult(Event.Result.DENY);
        Logging.logDebug("Noanimals dimension: Prevented a spawn of " + event.getEntity().getClass().getName());
    }
// @todo
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) IAnimals(net.minecraft.entity.passive.IAnimals) IMob(net.minecraft.entity.monster.IMob) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) GenericWorldProvider(mcjty.rftoolsdim.dimensions.world.GenericWorldProvider) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IMob (net.minecraft.entity.monster.IMob)4 IAnimals (net.minecraft.entity.passive.IAnimals)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 GenericWorldProvider (mcjty.rftoolsdim.dimensions.world.GenericWorldProvider)2 Entity (net.minecraft.entity.Entity)2 World (net.minecraft.world.World)2 WorldProvider (net.minecraft.world.WorldProvider)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 LogicTileEntity (mcjty.rftools.blocks.logic.generic.LogicTileEntity)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1