Search in sources :

Example 1 with EntityGoblin

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);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin) EntityGhastling(com.lying.variousoddities.entity.passive.EntityGhastling) DamageSource(net.minecraft.util.DamageSource) VODamageSource(com.lying.variousoddities.init.VODamageSource) EntityDamageSource(net.minecraft.util.EntityDamageSource) Random(java.util.Random) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) EntityDamageSource(net.minecraft.util.EntityDamageSource) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireballEntity(net.minecraft.entity.projectile.FireballEntity) AbstractGoblinWolf(com.lying.variousoddities.entity.AbstractGoblinWolf) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with EntityGoblin

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;
}
Also used : EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin) MobEntity(net.minecraft.entity.MobEntity)

Example 3 with EntityGoblin

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;
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with EntityGoblin

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);
}
Also used : EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin)

Example 5 with EntityGoblin

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);
}
Also used : EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin)

Aggregations

EntityGoblin (com.lying.variousoddities.entity.hostile.EntityGoblin)5 ServerWorld (net.minecraft.world.server.ServerWorld)2 AbstractGoblinWolf (com.lying.variousoddities.entity.AbstractGoblinWolf)1 EntityGhastling (com.lying.variousoddities.entity.passive.EntityGhastling)1 VODamageSource (com.lying.variousoddities.init.VODamageSource)1 Random (java.util.Random)1 LivingEntity (net.minecraft.entity.LivingEntity)1 MobEntity (net.minecraft.entity.MobEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 FireballEntity (net.minecraft.entity.projectile.FireballEntity)1 DamageSource (net.minecraft.util.DamageSource)1 EntityDamageSource (net.minecraft.util.EntityDamageSource)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1