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();
}
}
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);
}
}
}
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);
}
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++;
}
}
}
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();
}
}
Aggregations