use of com.lying.variousoddities.entity.hostile.EntityGoblin in project VariousOddities by Lyinginbedmon.
the class VOBusServer method onDeathNearGoblinEvent.
@SubscribeEvent
public static void onDeathNearGoblinEvent(LivingDeathEvent event) {
LivingEntity victim = event.getEntityLiving();
DamageSource cause = event.getSource();
World world = victim.getEntityWorld();
// Reduce refractory period of nearby goblins when a. goblin is slain or b. goblin slays any mob (esp. players)
if (victim instanceof EntityGoblin)
reduceRefractory(victim, 1000);
else if (cause instanceof EntityDamageSource && ((EntityDamageSource) cause).getTrueSource() instanceof EntityGoblin)
reduceRefractory(victim, victim instanceof PlayerEntity ? 4000 : 500);
// Occasionally spawn ghastlings when a ghast dies to a reflected fireball
if (victim.getType() == EntityType.GHAST)
if (cause.getImmediateSource() instanceof FireballEntity && cause.getTrueSource() instanceof PlayerEntity) {
Random rand = victim.getRNG();
if (rand.nextInt(15) == 0)
for (int i = 0; i < rand.nextInt(3); i++) {
EntityGhastling ghastling = VOEntities.GHASTLING.create(world);
ghastling.setLocationAndAngles(victim.getPosX(), victim.getPosY(), victim.getPosZ(), rand.nextFloat() * 360F, 0F);
world.addEntity(ghastling);
}
}
// Heal worgs and wargs when they kill something
if (cause instanceof EntityDamageSource && ((EntityDamageSource) cause).getTrueSource() instanceof AbstractGoblinWolf)
((AbstractGoblinWolf) cause.getTrueSource()).heal(2F + victim.getRNG().nextFloat() * 3F);
}
use of com.lying.variousoddities.entity.hostile.EntityGoblin in project VariousOddities by Lyinginbedmon.
the class EntityAIGoblinFlee method getNearestAvoid.
private MobEntity getNearestAvoid() {
MobEntity avoid = null;
double minDist = Double.MAX_VALUE;
for (MobEntity living : theWorld.getEntitiesWithinAABB(MobEntity.class, theGoblin.getBoundingBox().grow(6), new Predicate<MobEntity>() {
public boolean apply(MobEntity input) {
return input != theGoblin && input.getAttackTarget() != null && input.getAttackTarget() instanceof EntityGoblin;
}
})) {
double distance = living.getDistanceSq(theGoblin);
if (getPathAwayFrom(living) != null && distance < minDist) {
minDist = distance;
avoid = living;
}
}
return avoid;
}
use of com.lying.variousoddities.entity.hostile.EntityGoblin in project VariousOddities by Lyinginbedmon.
the class EntityAIGoblinMate method updateTask.
public void updateTask() {
BlockPos nestSite = theGoblin.getNestSite();
switch(currentState) {
case SEARCHING_MATE:
if (targetMate == null || !targetMate.isAlive() || !targetMate.isInLove()) {
for (EntityGoblin goblin : theWorld.getEntitiesWithinAABB(EntityGoblin.class, theGoblin.getBoundingBox().grow(16), searchPredicate)) {
if (goblin != theGoblin) {
if (theNavigator.getPathToEntity(goblin, (int) theGoblin.getAttributeValue(Attributes.FOLLOW_RANGE)) != null) {
targetMate = goblin;
break;
}
}
}
} else {
matingTimer = Reference.Values.TICKS_PER_SECOND * 10;
currentState = State.MATING;
}
break;
case MATING:
if (!targetMate.isInLove())
currentState = State.SEARCHING_MATE;
else if (theGoblin.getDistance(targetMate) < 1D) {
theNavigator.clearPath();
if (--matingTimer <= 0) {
matingTimer = Reference.Values.TICKS_PER_SECOND * 5;
theGoblin.setInLove(false);
targetMate.setInLove(false);
theGoblin.setGrowingAge(72000);
targetMate.setGrowingAge(72000);
theGoblin.setCarryingFrom(targetMate);
currentState = State.SEARCHING_NEST;
}
} else
theNavigator.tryMoveToEntityLiving(targetMate, 1.0D);
break;
case SEARCHING_NEST:
if (nestSite == null || !isValidForNest(nestSite) || distanceToPos(nestSite) > 32D)
theGoblin.setNestSite(getRandomNestSite());
else {
if (distanceToPos(nestSite) > 1.5D)
theNavigator.tryMoveToXYZ(nestSite.getX(), nestSite.getY(), nestSite.getZ(), 1.2D);
else {
theNavigator.clearPath();
if (--matingTimer <= 0) {
EntityGoblin parent = theGoblin.getOtherParent();
for (int i = 0; i < (1 + theGoblin.getRNG().nextInt(2)); i++) {
EntityGoblin child = (EntityGoblin) theGoblin.func_241840_a((ServerWorld) theWorld, parent);
child.copyLocationAndAnglesFrom(theGoblin);
child.setGrowingAge(-4000);
theWorld.addEntity(child);
}
theGoblin.setCarryingFrom(null);
matingTimer = Reference.Values.TICKS_PER_SECOND * 3;
currentState = State.LEAVING_NEST;
}
}
}
break;
case LEAVING_NEST:
if (distanceToPos(nestSite) < 8D && matingTimer-- > 0) {
if (theNavigator.noPath()) {
// Find random position away from nest site and move towards it
Vector3d targetFlee = RandomPositionGenerator.findRandomTargetBlockAwayFrom(theGoblin, 16, 7, new Vector3d(nestSite.getX(), nestSite.getY(), nestSite.getZ()));
if (targetFlee != null)
theNavigator.tryMoveToXYZ(targetFlee.x, targetFlee.y, targetFlee.z, 1.2D);
}
} else
currentState = null;
break;
}
}
use of com.lying.variousoddities.entity.hostile.EntityGoblin in project VariousOddities by Lyinginbedmon.
the class EntityAIWorgFollowGoblin method shouldExecute.
public boolean shouldExecute() {
if (theWorg.isTamed() || theWorg.getAttackTarget() != null && theWorg.getAttackTarget().isAlive() || theWorg.isSitting() || theWorg.getControllingPassenger() != null)
return false;
double minDist = Double.MAX_VALUE;
for (EntityGoblin goblin : theWorld.getEntitiesWithinAABB(EntityGoblin.class, theWorg.getBoundingBox().grow(16D), searchPredicate)) {
double dist = goblin.getDistanceSq(theWorg) / goblin.getGoblinType().authority;
if (dist < minDist && theWorg.getNavigator().getPathToEntity(goblin, (int) dist + 1) != null) {
nearestGoblin = goblin;
minDist = dist;
}
}
if (nearestGoblin == null || !nearestGoblin.isAlive())
return false;
return nearestGoblin.getDistance(theWorg) > (theWorg.isChild() ? 3D : 6D);
}
use of com.lying.variousoddities.entity.hostile.EntityGoblin in project VariousOddities by Lyinginbedmon.
the class EntityAIGoblinWorgHurt method startExecuting.
public void startExecuting() {
theGoblin.getLookController().setLookPositionWithEntity(targetWorg, (float) (theGoblin.getHorizontalFaceSpeed() + 20), (float) theGoblin.getVerticalFaceSpeed());
theGoblin.swingArm(Hand.OFF_HAND);
targetWorg.attackEntityFrom(DamageSource.causeMobDamage(theGoblin), 0F);
for (EntityGoblin child : theWorld.getEntitiesWithinAABB(EntityGoblin.class, targetWorg.getBoundingBox().grow(12, 2, 12), new Predicate<EntityGoblin>() {
public boolean apply(EntityGoblin input) {
return input.isChild() && input.canEntityBeSeen(targetWorg) && input.canEntityBeSeen(theGoblin);
}
})) child.setViolent(true);
}
Aggregations