Search in sources :

Example 31 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project BetterWithAddons by DaedalusGame.

the class AnimalCrossbreedHandler method crossBreedAnimal.

@SubscribeEvent
public void crossBreedAnimal(LivingEvent.LivingUpdateEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    World world = entity.world;
    BlockPos pos = entity.getPosition();
    try {
        if (!world.isRemote && entity instanceof EntityAnimal) {
            EntityAnimal animal = (EntityAnimal) entity;
            if (!animal.isInLove())
                return;
            if (world.getLight(pos) >= 8 || (int) inLove.get(animal) > 20)
                return;
            // Instead of expanding entity bounding box, expand block bounding box because it makes more sense this way probably
            AxisAlignedBB aabb = new AxisAlignedBB(pos).expand(8, 8, 8);
            List<EntityAnimal> others = world.getEntitiesWithinAABB(EntityAnimal.class, aabb);
            EntityAnimal found = null;
            for (EntityAnimal other : others) {
                if (other == animal || !other.isInLove())
                    continue;
                if (isSameSpecies(animal, other))
                    return;
                if (animal.getPositionVector().squareDistanceTo(other.getPositionVector()) > 3.5 * 3.5)
                    continue;
                if (!isNotSitting(other) || world.getLight(other.getPosition()) >= 8)
                    continue;
                found = other;
                break;
            }
            if (found == null)
                return;
            Vec3d spawnPos = new Vec3d((found.posX + animal.posX) / 2, (found.posY + animal.posY) / 2, (found.posZ + animal.posZ) / 2);
            BlockPos spawnBlockPos = new BlockPos(spawnPos);
            // TODO: Habitat check
            final EntityAnimal finalFound = found;
            ArrayList<AnimalMutation> mutations = mutationSet.stream().map(x -> x.copy().updateWeight(world, spawnPos, finalFound, animal)).collect(Collectors.toCollection(ArrayList::new));
            AnimalMutation mutation = WeightedRandom.getRandomItem(world.rand, mutations);
            if (mutation != null)
                mutation.spawner.spawn(world, spawnPos, found, animal);
            animal.resetInLove();
            animal.setGrowingAge(6000);
            found.resetInLove();
            found.setGrowingAge(6000);
            animal.playLivingSound();
            found.playLivingSound();
            animal.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 6000));
            found.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 6000));
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) net.minecraft.entity.passive(net.minecraft.entity.passive) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntitySlime(net.minecraft.entity.monster.EntitySlime) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) EntityAgeable(net.minecraft.entity.EntityAgeable) ArrayList(java.util.ArrayList) PotionEffect(net.minecraft.potion.PotionEffect) EntitySilverfish(net.minecraft.entity.monster.EntitySilverfish) Vec3d(net.minecraft.util.math.Vec3d) BiomeDictionary(net.minecraftforge.common.BiomeDictionary) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) LivingEvent(net.minecraftforge.event.entity.living.LivingEvent) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) EntityCaveSpider(net.minecraft.entity.monster.EntityCaveSpider) MobEffects(net.minecraft.init.MobEffects) Biome(net.minecraft.world.biome.Biome) WeightedRandom(net.minecraft.util.WeightedRandom) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 32 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project BetterWithAddons by DaedalusGame.

the class AssortedHandler method livingTick.

@SubscribeEvent
public void livingTick(LivingEvent.LivingUpdateEvent updateEvent) {
    final EntityLivingBase entity = updateEvent.getEntityLiving();
    World world = entity.getEntityWorld();
    UUID uuid = entity.getUniqueID();
    BlockPos pos = entity.getPosition();
    if (!world.isRemote) {
        if (entity.isPotionActive(ModPotions.boss)) {
            if (!BossList.containsKey(uuid)) {
                BossInfoServer displayData = (BossInfoServer) new BossInfoServer(entity.getDisplayName(), Color.PURPLE, Overlay.PROGRESS).setDarkenSky(false);
                BossList.put(uuid, displayData);
                List<EntityPlayerMP> entities = world.getEntitiesWithinAABB(EntityPlayerMP.class, new AxisAlignedBB(pos).expand(24, 24, 24));
                if (entities != null)
                    for (EntityPlayerMP ply : entities) {
                        displayData.addPlayer(ply);
                    }
            } else {
                BossInfoServer bossInfo = BossList.get(uuid);
                bossInfo.setPercent(entity.getHealth() / entity.getMaxHealth());
            }
        } else if (world.getMinecraftServer().getTickCounter() % BossCleanupThreshold == 0 && BossList.containsKey(uuid)) {
            BossInfoServer bossInfo = BossList.get(uuid);
            for (EntityPlayerMP ply : bossInfo.getPlayers()) {
                bossInfo.removePlayer(ply);
            }
            BossList.remove(uuid);
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) World(net.minecraft.world.World) UUID(java.util.UUID) BossInfoServer(net.minecraft.world.BossInfoServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 33 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project BetterWithAddons by DaedalusGame.

the class TerratorialHandler method spawnLiving.

@SubscribeEvent
public void spawnLiving(LivingSpawnEvent.CheckSpawn spawnEvent) {
    World world = spawnEvent.getWorld();
    EntityLivingBase entity = spawnEvent.getEntityLiving();
    Chunk chunk = world.getChunkFromBlockCoords(new BlockPos(spawnEvent.getX(), spawnEvent.getY(), spawnEvent.getZ()));
    if (!chunk.isLoaded())
        return;
    if (entity instanceof EntityZombie || entity instanceof EntitySkeleton || entity instanceof EntityCreeper)
        spawnEvent.setResult(Event.Result.DENY);
}
Also used : EntityCreeper(net.minecraft.entity.monster.EntityCreeper) EntityZombie(net.minecraft.entity.monster.EntityZombie) EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 34 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project malmo by Microsoft.

the class ObservationFromNearbyEntitiesImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    this.tickCount++;
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    // Get all the currently loaded entities:
    List<?> entities = Minecraft.getMinecraft().world.getLoadedEntityList();
    // Get the list of RangeDefinitions that need firing:
    List<RangeDefinition> rangesToFire = new ArrayList<RangeDefinition>();
    int index = 0;
    for (RangeDefinition rd : this.oneparams.getRange()) {
        if (this.tickCount - this.lastFiringTimes[index] >= rd.getUpdateFrequency()) {
            rangesToFire.add(rd);
            this.lastFiringTimes[index] = this.tickCount;
        }
        index++;
    }
    // Create a list of empty lists to populate:
    List<List<Entity>> entitiesInRange = new ArrayList<List<Entity>>();
    for (int i = 0; i < rangesToFire.size(); i++) entitiesInRange.add(new ArrayList<Entity>());
    // Populate all our lists according to which entities are in range:
    for (Object obj : entities) {
        if (obj instanceof Entity) {
            Entity e = (Entity) obj;
            index = 0;
            for (RangeDefinition rd : rangesToFire) {
                if (Math.abs(e.posX - player.posX) < rd.getXrange().doubleValue() && Math.abs(e.posY - player.posY) < rd.getYrange().doubleValue() && Math.abs(e.posZ - player.posZ) < rd.getZrange().doubleValue()) {
                    // Belongs in this list:
                    entitiesInRange.get(index).add(e);
                }
                index++;
            }
        }
    }
    // Now build up a JSON array for each populated list:
    index = 0;
    for (List<Entity> entsInRangeList : entitiesInRange) {
        if (!entitiesInRange.isEmpty()) {
            JsonArray arr = new JsonArray();
            for (Entity e : entsInRangeList) {
                JsonObject jsent = new JsonObject();
                jsent.addProperty("yaw", e.rotationYaw);
                jsent.addProperty("x", e.posX);
                jsent.addProperty("y", e.posY);
                jsent.addProperty("z", e.posZ);
                jsent.addProperty("pitch", e.rotationPitch);
                jsent.addProperty("id", e.getCachedUniqueIdString());
                jsent.addProperty("motionX", e.motionX);
                jsent.addProperty("motionY", e.motionY);
                jsent.addProperty("motionZ", e.motionZ);
                String name = MinecraftTypeHelper.getUnlocalisedEntityName(e);
                if (e instanceof EntityItem) {
                    ItemStack is = ((EntityItem) e).getEntityItem();
                    DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
                    if (di != null) {
                        name = di.getType();
                        if (di.getColour() != null)
                            jsent.addProperty("colour", di.getColour().value());
                        if (di.getVariant() != null)
                            jsent.addProperty("variation", di.getVariant().getValue());
                    }
                    jsent.addProperty("quantity", is.getCount());
                } else if (e instanceof EntityLivingBase) {
                    EntityLivingBase el = (EntityLivingBase) e;
                    jsent.addProperty("life", el.getHealth());
                }
                jsent.addProperty("name", name);
                arr.add(jsent);
            }
            json.add(this.oneparams.getRange().get(index).getName(), arr);
            index++;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) RangeDefinition(com.microsoft.Malmo.Schemas.RangeDefinition) EntityItem(net.minecraft.entity.item.EntityItem)

Example 35 with EntityLivingBase

use of net.minecraft.entity.EntityLivingBase in project MorePlanets by SteveKunG.

the class EntityInfectedSnowball method onImpact.

@Override
protected void onImpact(RayTraceResult moving) {
    if (moving.entityHit != null) {
        int i = 0;
        if (moving.entityHit instanceof EntityBlaze) {
            i = 3;
        }
        if (moving.entityHit instanceof EntityLivingBase) {
            ((EntityLivingBase) moving.entityHit).addPotionEffect(new PotionEffect(MPPotions.INFECTED_SPORE, 100, 0));
        }
        moving.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), i);
    }
    for (int j = 0; j < 8; ++j) {
        MorePlanetsCore.PROXY.spawnParticle(EnumParticleTypesMP.CUSTOM_BREAKING, this.posX, this.posY, this.posZ, new Object[] { NibiruItems.INFECTED_SNOWBALL });
    }
    if (!this.world.isRemote) {
        this.setDead();
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityBlaze(net.minecraft.entity.monster.EntityBlaze)

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