Search in sources :

Example 1 with IMob

use of net.minecraft.entity.monster.IMob in project Engine by VoltzEngine-Project.

the class CommandVEButcher method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    long time = System.nanoTime();
    //TODO add ability to set location and range
    int dim = 0;
    if (args != null && args.length > 0) {
        if (args[0].startsWith("dim")) {
            try {
                dim = Integer.parseInt(args[0].replace("dim", ""));
            } catch (NumberFormatException e) {
                sender.addChatMessage(new ChatComponentText("Dim id needs to be an int"));
                return true;
            }
        } else {
            sender.addChatMessage(new ChatComponentText("Right now only /ve butcher dim[#] is supported, ex /ve butcher dim0"));
            return true;
        }
    }
    WorldServer world = DimensionManager.getWorld(dim);
    if (world != null) {
        int entitiesKilled = 0;
        int chunksSearched = 0;
        ChunkProviderServer provider = world.theChunkProviderServer;
        for (Object object : provider.loadedChunks) {
            if (object instanceof Chunk) {
                chunksSearched++;
                for (Object l : ((Chunk) object).entityLists) {
                    if (l instanceof Collection) {
                        for (Object e : (Collection) l) {
                            if (e instanceof Entity && e instanceof IMob) {
                                if (((Entity) e).isEntityAlive()) {
                                    ((Entity) e).setDead();
                                    entitiesKilled++;
                                }
                            }
                        }
                    }
                }
            }
        }
        time = System.nanoTime() - time;
        sender.addChatMessage(new ChatComponentText("Removed " + entitiesKilled + "mobs over " + chunksSearched + " chunks in " + StringHelpers.formatNanoTime(time)));
    } else {
        sender.addChatMessage(new ChatComponentText("World doesn't exist, this means it unloaded or the wrong id was provided."));
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) IMob(net.minecraft.entity.monster.IMob) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Collection(java.util.Collection) WorldServer(net.minecraft.world.WorldServer) Chunk(net.minecraft.world.chunk.Chunk) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 2 with IMob

use of net.minecraft.entity.monster.IMob in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntitySpawnEvent.

@SubscribeEvent
public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) {
    World world = event.getWorld();
    int id = world.provider.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
    if (PowerConfiguration.preventSpawnUnpowered) {
        if (dimensionInformation != null) {
            // RFTools dimension.
            DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
            int energy = storage.getEnergyLevel(id);
            if (energy <= 0) {
                event.setResult(Event.Result.DENY);
                Logging.logDebug("Dimension power low: Prevented a spawn of " + event.getEntity().getClass().getName());
            }
        }
    }
    if (dimensionInformation != null) {
        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;
                if (dimensionInformation.hasEffectType(EffectType.EFFECT_BRUTALMOBS)) {
                    newMax = entityAttribute.getBaseValue() * GeneralConfiguration.brutalMobsFactor;
                } else {
                    newMax = entityAttribute.getBaseValue() * 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 != null && 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) {
        if (dimensionInformation != null && 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) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IAttributeInstance(net.minecraft.entity.ai.attributes.IAttributeInstance) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IMob

use of net.minecraft.entity.monster.IMob in project RFToolsDimensions by McJty.

the class ForgeEventHandlers method onEntityJoinWorldEvent.

@SubscribeEvent
public void onEntityJoinWorldEvent(EntityJoinWorldEvent event) {
    World world = event.getWorld();
    if (world.isRemote) {
        return;
    }
    int id = world.provider.getDimension();
    RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(world);
    DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
    if (dimensionInformation != null && dimensionInformation.isNoanimals()) {
        if (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) World(net.minecraft.world.World) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IMob

use of net.minecraft.entity.monster.IMob in project ConvenientAdditions by Necr0.

the class EntityMobCatcher method onImpact.

@Override
protected void onImpact(RayTraceResult result) {
    if (this.world.isRemote || mobCatcherItem.isEmpty() || !(mobCatcherItem.getItem() instanceof ItemMobCatcher))
        return;
    if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
        Entity target = result.entityHit;
        if (target instanceof EntityCreature && !target.isDead) {
            List<String> blacklist = new ArrayList<>();
            blacklist.addAll(BLACKLIST_INTERNAL);
            blacklist.addAll(Arrays.asList(ModConfigTools.mobCatcher_blacklist));
            if (!blacklist.contains(EntityRegistry.getEntry(target.getClass()).getRegistryName().toString())) {
                boolean hostile = target instanceof IMob;
                ItemMobCatcher item = (ItemMobCatcher) mobCatcherItem.getItem();
                List<String> bosslist = new ArrayList<>();
                bosslist.addAll(BOSSLIST_INTERNAL);
                bosslist.addAll(Arrays.asList(ModConfigTools.mobCatcher_bosses));
                if ((item.type.captureHostile || !hostile) && (item.type.captureBoss || !bosslist.contains(EntityRegistry.getEntry(target.getClass()).getRegistryName().toString()))) {
                    EntityCreature t = (EntityCreature) target;
                    float resistance = hostile ? 1.25f : 1;
                    float weakness = (t.getMaxHealth() / t.getHealth());
                    float captureStrength = item.type.captureStrength + .5f;
                    if (captureStrength <= 0 || this.world.rand.nextFloat() < (1 - (weakness / (1.5 * captureStrength) * resistance))) {
                        if (!mobCatcherItem.hasTagCompound())
                            mobCatcherItem.setTagCompound(new NBTTagCompound());
                        NBTTagCompound nbt = mobCatcherItem.getTagCompound();
                        nbt.setTag("CONTAINED_ENTITY", t.serializeNBT());
                        nbt.setString("CONTAINED_ENTITY_ID", EntityRegistry.getEntry(target.getClass()).getRegistryName().toString());
                        mobCatcherItem.setItemDamage(1);
                        world.playSound(null, result.hitVec.xCoord, result.hitVec.yCoord, result.hitVec.zCoord, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, .5f, 2f);
                        t.setDead();
                        dropItem(result.hitVec);
                    } else {
                        breakCatcher(result.hitVec);
                    }
                } else {
                    breakCatcher(result.hitVec);
                }
            }
        }
    } else if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
        dropItem(result.hitVec);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IMob(net.minecraft.entity.monster.IMob) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemMobCatcher(convenientadditions.item.tools.mobCatcher.ItemMobCatcher) EntityCreature(net.minecraft.entity.EntityCreature)

Example 5 with IMob

use of net.minecraft.entity.monster.IMob in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method getTargetWithoutSlowEffect.

@SuppressWarnings("ConstantConditions")
public static Entity getTargetWithoutSlowEffect(TurretBase base, World worldObj, BlockPos pos, int turretRange, TurretHead turret) {
    Entity target = null;
    if (!worldObj.isRemote && base != null && base.getOwner() != null) {
        AxisAlignedBB axis = new AxisAlignedBB(pos.getX() - turretRange - 1, pos.getY() - turretRange - 1, pos.getZ() - turretRange - 1, pos.getX() + turretRange + 1, pos.getY() + turretRange + 1, pos.getZ() + turretRange + 1);
        List<EntityLivingBase> targets = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis);
        for (EntityLivingBase target1 : targets) {
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAnimal && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksNeutrals() && ConfigHandler.globalCanTargetNeutrals) {
                if (target1 instanceof EntityAmbientCreature && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksMobs() && ConfigHandler.globalCanTargetMobs) {
                if (target1 instanceof IMob && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    target = target1;
                }
            }
            if (base.isAttacksPlayers() && ConfigHandler.globalCanTargetPlayers) {
                if (target1 instanceof EntityPlayerMP && !target1.isDead && !target1.isPotionActive(Potion.getPotionById(2))) {
                    EntityPlayerMP entity = (EntityPlayerMP) target1;
                    if (!entity.getUniqueID().toString().equals(base.getOwner()) && !isPlayerTrusted(entity, base) && !entity.capabilities.isCreativeMode) {
                        target = target1;
                    }
                }
            }
            if (target != null && turret != null) {
                EntityLivingBase targetELB = (EntityLivingBase) target;
                if (base.isMultiTargeting() && isTargetAlreadyTargeted(base, target)) {
                    continue;
                }
                if (canTurretSeeTarget(turret, targetELB) && targetELB.getHealth() > 0.0F) {
                    return target;
                }
            }
        }
    }
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IMob(net.minecraft.entity.monster.IMob) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityAmbientCreature(net.minecraft.entity.passive.EntityAmbientCreature)

Aggregations

IMob (net.minecraft.entity.monster.IMob)6 Entity (net.minecraft.entity.Entity)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)2 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)2 EntityAmbientCreature (net.minecraft.entity.passive.EntityAmbientCreature)2 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)2 IAnimals (net.minecraft.entity.passive.IAnimals)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 TileEntity (net.minecraft.tileentity.TileEntity)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ItemMobCatcher (convenientadditions.item.tools.mobCatcher.ItemMobCatcher)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 DimensionStorage (mcjty.rftoolsdim.dimensions.DimensionStorage)1 EntityCreature (net.minecraft.entity.EntityCreature)1 IAttributeInstance (net.minecraft.entity.ai.attributes.IAttributeInstance)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1