use of net.minecraft.entity.EntityLivingBase in project Skree by Skelril.
the class ShnugglesPrimeInstance method runAttack.
public void runAttack(ShnugglesPrimeAttack attackCase) {
Optional<Giant> optBoss = getBoss();
if (!optBoss.isPresent()) {
return;
}
Giant boss = optBoss.get();
double bossHealth = getHealth(boss);
double maxBossHealth = getMaxHealth(boss);
double delay = 15000;
if (lastAttackTime != 0 && System.currentTimeMillis() - lastAttackTime <= delay) {
return;
}
Collection<Player> contained = getPlayers(PARTICIPANT);
if (contained.isEmpty()) {
return;
}
// AI-ish system
if ((attackCase == ShnugglesPrimeAttack.EVERLASTING || attackCase == ShnugglesPrimeAttack.MINION_LEECH) && bossHealth > maxBossHealth * .9) {
attackCase = Probability.getChance(2) ? ShnugglesPrimeAttack.DARK_POTIONS : ShnugglesPrimeAttack.CORRUPTION;
}
for (Player player : contained) {
if (player.get(Keys.HEALTH).get() < 4) {
attackCase = ShnugglesPrimeAttack.CORRUPTION;
break;
}
}
Collection<Zombie> zombies = getContained(Zombie.class);
if (zombies.size() > 200) {
attackCase = ShnugglesPrimeAttack.BASK_IN_MY_GLORY;
}
if (bossHealth < maxBossHealth * .4 && Probability.getChance(5)) {
if (zombies.size() < 100 && bossHealth > 200) {
attackCase = ShnugglesPrimeAttack.EVERLASTING;
} else {
attackCase = ShnugglesPrimeAttack.MINION_LEECH;
}
}
if ((attackCase == ShnugglesPrimeAttack.BLINDNESS || attackCase == ShnugglesPrimeAttack.FIRE) && bossHealth < maxBossHealth * .15) {
runRandomAttack();
return;
}
switch(attackCase) {
case WRATH:
sendAttackBroadcast("Taste my wrath!", AttackSeverity.NORMAL);
for (Player player : contained) {
player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 3 - 1.5, random.nextDouble() * 1 + .5, random.nextDouble() * 3 - 1.5));
player.offer(Keys.FIRE_TICKS, 20 * 3);
}
break;
case CORRUPTION:
sendAttackBroadcast("Embrace my corruption!", AttackSeverity.NORMAL);
PotionEffect witherEffect = PotionEffect.of(PotionEffectTypes.WITHER, 1, 20 * 3);
for (Player player : contained) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(witherEffect);
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
break;
case BLINDNESS:
sendAttackBroadcast("Are you BLIND? Mwhahahaha!", AttackSeverity.NORMAL);
PotionEffect blindnessEffect = PotionEffect.of(PotionEffectTypes.BLINDNESS, 0, 20 * 4);
for (Player player : contained) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(blindnessEffect);
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
break;
case TANGO_TIME:
sendAttackBroadcast("Tango time!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.TANGO_TIME);
Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
if (!isBossSpawned())
return;
for (Player player : getPlayers(PARTICIPANT)) {
// TODO Convert to Sponge
if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
player.sendMessage(Text.of(TextColors.YELLOW, "Come closer..."));
player.setLocation(boss.getLocation());
EntityDamageSource source = EntityDamageSource.builder().entity(boss).type(DamageTypes.ATTACK).build();
player.damage(100, source, Cause.source(boss).build());
player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 1.7 - 1.5, random.nextDouble() * 2, random.nextDouble() * 1.7 - 1.5));
} else {
player.sendMessage(Text.of(TextColors.YELLOW, "Fine... No tango this time..."));
}
}
sendAttackBroadcast("Now wasn't that fun?", AttackSeverity.INFO);
activeAttacks.remove(ShnugglesPrimeAttack.TANGO_TIME);
}).submit(SkreePlugin.inst());
break;
case EVERLASTING:
if (!damageHeals) {
activeAttacks.add(ShnugglesPrimeAttack.EVERLASTING);
sendAttackBroadcast("I am everlasting!", AttackSeverity.NORMAL);
damageHeals = true;
Task.builder().delay(12, TimeUnit.SECONDS).execute(() -> {
if (damageHeals) {
damageHeals = false;
if (!isBossSpawned())
return;
sendAttackBroadcast("Thank you for your assistance.", AttackSeverity.INFO);
}
activeAttacks.remove(ShnugglesPrimeAttack.EVERLASTING);
}).submit(SkreePlugin.inst());
break;
}
runRandomAttack();
return;
case FIRE:
sendAttackBroadcast("Fire is your friend...", AttackSeverity.NORMAL);
for (Player player : contained) {
player.offer(Keys.FIRE_TICKS, 20 * 5);
}
break;
case BASK_IN_MY_GLORY:
if (!damageHeals) {
sendAttackBroadcast("Bask in my glory!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
if (!isBossSpawned())
return;
boolean baskInGlory = false;
for (Player player : getContained(Player.class)) {
// TODO Convert to Sponge
if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You!"));
baskInGlory = true;
}
}
//Attack
if (baskInGlory) {
damageHeals = true;
spawnPts.stream().filter(pt -> Probability.getChance(12)).forEach(pt -> {
Explosion explosion = Explosion.builder().shouldDamageEntities(true).location(pt).radius(10).build();
getRegion().getExtent().triggerExplosion(explosion, Cause.source(SkreePlugin.container()).owner(boss).build());
});
//Schedule Reset
Task.builder().delay(500, TimeUnit.MILLISECONDS).execute(() -> {
damageHeals = false;
}).submit(SkreePlugin.inst());
return;
}
// Notify if avoided
sendAttackBroadcast("Gah... Afraid are you friends?", AttackSeverity.INFO);
activeAttacks.remove(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
}).submit(SkreePlugin.inst());
break;
}
runRandomAttack();
break;
case DARK_POTIONS:
sendAttackBroadcast("Unleash the inner darkness!", AttackSeverity.NORMAL);
PotionEffect instantDamageEffect = PotionEffect.of(PotionEffectTypes.INSTANT_DAMAGE, 0, 1);
for (Living entity : getContained(Zombie.class)) {
if (!Probability.getChance(5)) {
continue;
}
entity.offer(Keys.HEALTH, 0D);
Location targetLoc = entity.getLocation();
Entity potion = getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, targetLoc.getPosition());
potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(instantDamageEffect));
getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
return;
case MINION_LEECH:
sendAttackBroadcast("My minions our time is now!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.MINION_LEECH);
IntegratedRunnable minionEater = new IntegratedRunnable() {
@Override
public boolean run(int times) {
if (!isBossSpawned())
return true;
for (Living entity : getContained(Living.class)) {
// TODO convert to Sponge
if (entity instanceof Giant || !Probability.getChance(5) || !((EntityGiantZombie) boss).canEntityBeSeen((EntityLivingBase) entity)) {
continue;
}
double realDamage = entity.get(Keys.HEALTH).get();
// TODO convert to Sponge
if (entity instanceof Zombie && ((EntityZombie) entity).isChild()) {
entity.offer(Keys.HEALTH, 0D);
} else {
DamageSource source = DamageSource.builder().type(DamageTypes.ATTACK).build();
entity.damage(realDamage, source, Cause.source(boss).build());
}
toHeal += Math.min(1, realDamage / 3);
}
if (new TimeFilter(-1, 2).matchesFilter(times + 1)) {
getPlayerMessageChannel(SPECTATOR).send(Text.of(TextColors.DARK_AQUA, "The boss has drawn in: " + (int) toHeal + " health."));
}
return true;
}
@Override
public void end() {
if (!isBossSpawned())
return;
heal(boss, toHeal);
toHeal = 0;
sendAttackBroadcast("Thank you my minions!", AttackSeverity.INFO);
printBossHealth();
activeAttacks.remove(ShnugglesPrimeAttack.MINION_LEECH);
}
};
TimedRunnable<IntegratedRunnable> minonEatingTask = new TimedRunnable<>(minionEater, 20);
Task minionEatingTaskExecutor = Task.builder().interval(500, TimeUnit.MILLISECONDS).execute(minonEatingTask).submit(SkreePlugin.inst());
minonEatingTask.setTask(minionEatingTaskExecutor);
break;
}
lastAttackTime = System.currentTimeMillis();
lastAttack = attackCase;
}
use of net.minecraft.entity.EntityLivingBase in project Skree by Skelril.
the class LoadedBow method applyPropertyOverrides.
private void applyPropertyOverrides() {
this.addPropertyOverride(new ResourceLocation("skree", "pull"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack item, @Nullable World world, @Nullable EntityLivingBase living) {
if (living == null) {
return 0.0F;
} else {
ItemStack itemstack = living.getActiveItemStack();
return itemstack != null ? (item.getMaxItemUseDuration() - living.getItemInUseCount()) / 20.0F : 0.0F;
}
}
});
this.addPropertyOverride(new ResourceLocation("skree", "pulling"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack item, @Nullable World world, @Nullable EntityLivingBase living) {
return living != null && living.isHandActive() && living.getActiveItemStack() == item ? 1.0F : 0.0F;
}
});
}
use of net.minecraft.entity.EntityLivingBase in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityCollisionInjector method alterEntityMovement.
// Returns false if game should use default collision
public static boolean alterEntityMovement(Entity entity, double dx, double dy, double dz) {
if (entity instanceof PhysicsWrapperEntity) {
return true;
}
Vector velVec = new Vector(dx, dy, dz);
double origDx = dx;
double origDy = dy;
double origDz = dz;
boolean isLiving = entity instanceof EntityLivingBase;
boolean isMoving = false;
if (isLiving) {
EntityLivingBase living = (EntityLivingBase) entity;
isMoving = Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01;
}
Vec3d velocity = new Vec3d(dx, dy, dz);
ArrayList<EntityPolygonCollider> fastCollisions = new ArrayList<EntityPolygonCollider>();
EntityPolygon playerBeforeMove = new EntityPolygon(entity.getEntityBoundingBox(), entity);
ArrayList<Polygon> colPolys = getCollidingPolygonsAndDoBlockCols(entity, velocity);
PhysicsWrapperEntity worldBelow = null;
EntityDraggable draggable = EntityDraggable.getDraggableFromEntity(entity);
for (Polygon poly : colPolys) {
if (poly instanceof ShipPolygon) {
ShipPolygon shipPoly = (ShipPolygon) poly;
EntityPolygonCollider fast = new EntityPolygonCollider(playerBeforeMove, shipPoly, shipPoly.normals, velVec);
if (!fast.seperated) {
fastCollisions.add(fast);
worldBelow = shipPoly.shipFrom.wrapper;
}
}
}
//TODO: Make this more comprehensive
draggable.worldBelowFeet = worldBelow;
if (fastCollisions.isEmpty()) {
return false;
}
int contX = 0;
int contY = 0;
int contZ = 0;
Vector total = new Vector();
for (EntityPolygonCollider col : fastCollisions) {
Vector response = col.collisions[col.minDistanceIndex].getResponse();
// TODO: Add more potential yResponses
double stepSquared = entity.stepHeight * entity.stepHeight;
boolean isStep = isLiving && entity.onGround;
if (response.Y > 0 && BigBastardMath.canStandOnNormal(col.potentialSeperatingAxes[col.minDistanceIndex])) {
response = new Vector(0, -col.collisions[col.minDistanceIndex].penetrationDistance / col.potentialSeperatingAxes[col.minDistanceIndex].Y, 0);
}
if (isStep) {
EntityLivingBase living = (EntityLivingBase) entity;
if (Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01) {
for (int i = 3; i < 6; i++) {
Vector tempResponse = col.collisions[i].getResponse();
if (tempResponse.Y > 0 && BigBastardMath.canStandOnNormal(col.collisions[i].axis) && tempResponse.lengthSq() < stepSquared) {
response = tempResponse;
}
}
}
}
// total.add(response);
if (Math.abs(response.X) > .01) {
total.X += response.X;
contX++;
}
if (Math.abs(response.Y) > .01) {
total.Y += response.Y;
contY++;
}
if (Math.abs(response.Z) > .01) {
total.Z += response.Z;
contZ++;
}
}
if (contX != 0) {
total.X /= contX;
}
if (contY != 0) {
total.Y /= contY;
}
if (contZ != 0) {
total.Z /= contZ;
}
dx += total.X;
dy += total.Y;
dz += total.Z;
boolean alreadyOnGround = entity.onGround && (dy == origDy) && origDy < 0;
Vector original = new Vector(origDx, origDy, origDz);
Vector newMov = new Vector(dx - origDx, dy - origDy, dz - origDz);
entity.isCollidedHorizontally = original.dot(newMov) < 0;
entity.isCollidedVertically = isDifSignificant(dy, origDy);
entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround;
entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
if (entity instanceof EntityLivingBase) {
EntityLivingBase base = (EntityLivingBase) entity;
base.motionY = dy;
if (base.isOnLadder()) {
float f9 = 0.15F;
base.motionX = MathHelper.clamp_double(base.motionX, -0.15000000596046448D, 0.15000000596046448D);
base.motionZ = MathHelper.clamp_double(base.motionZ, -0.15000000596046448D, 0.15000000596046448D);
base.fallDistance = 0.0F;
if (base.motionY < -0.15D) {
base.motionY = -0.15D;
}
boolean flag = base.isSneaking() && base instanceof EntityPlayer;
if (flag && base.motionY < 0.0D) {
base.motionY = 0.0D;
}
}
entity.moveEntity(dx, base.motionY, dz);
} else {
entity.moveEntity(dx, dy, dz);
}
entity.isCollidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
entity.isCollidedVertically = isDifSignificant(dy, origDy);
entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
if (dx != origDx) {
entity.motionX = dx;
}
if (dy != origDy) {
if (!(entity.motionY > 0 && dy > 0)) {
entity.motionY = 0;
}
}
if (dz != origDz) {
entity.motionZ = dz;
}
return true;
}
use of net.minecraft.entity.EntityLivingBase in project Witchworks by Um-Mitternacht.
the class ItemTaglock method getVictim.
public Optional<EntityLivingBase> getVictim(ItemStack stack, World world) {
UUID uuid = NBTHelper.getUniqueID(stack, TAGLOCK_ENTITY);
for (Entity entity : world.loadedEntityList) {
if (entity instanceof EntityLivingBase && entity.getUniqueID().equals(uuid)) {
return Optional.of((EntityLivingBase) entity);
}
}
EntityPlayer victim = world.getPlayerEntityByUUID(uuid);
return Optional.ofNullable(victim);
}
use of net.minecraft.entity.EntityLivingBase in project Realistic-Terrain-Generation by Team-RTG.
the class DisruptionSpawn method disrupt.
@Override
public void disrupt(World world, BlockPos pos, List<EntityPlayer> players) {
if (!world.isRemote) {
EntityLivingBase entityliving = null;
try {
entityliving = entity.getConstructor(World.class).newInstance(world);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
if (entityliving != null) {
entityliving.setLocationAndAngles(pos.getX(), pos.getY() + 1, pos.getZ(), entityliving.rotationYaw, entityliving.rotationPitch);
((EntityLiving) entityliving).onInitialSpawn(world.getDifficultyForLocation(pos.up()), (IEntityLivingData) null);
world.spawnEntity(entityliving);
}
}
}
Aggregations