Search in sources :

Example 1 with HealthData

use of org.spongepowered.api.data.manipulator.mutable.entity.HealthData in project Skree by Skelril.

the class WildernessWorldWrapper method onEntitySpawn.

@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
    List<Entity> entities = event.getEntities();
    Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
    for (Entity entity : entities) {
        Location<World> loc = entity.getLocation();
        Optional<Integer> optLevel = getLevel(loc);
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        if (entity instanceof Egg && optBlockCause.isPresent()) {
            PrimedTNT explosive = (PrimedTNT) entity.getLocation().getExtent().createEntity(EntityTypes.PRIMED_TNT, entity.getLocation().getPosition());
            explosive.setVelocity(entity.getVelocity());
            explosive.offer(Keys.FUSE_DURATION, 20 * 4);
            // TODO used to have a 1/4 chance of creating fire
            entity.getLocation().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.DISPENSE).build()).build());
            event.setCancelled(true);
            return;
        }
        if (level > 1) {
            // TODO move damage modification
            if (entity instanceof Monster) {
                HealthData healthData = ((Monster) entity).getHealthData();
                double curMax = healthData.maxHealth().get();
                if (curMax <= 80) {
                    // TODO do this a better way, but for now it prevents super mobs
                    double newMax = curMax * getHealthMod(level);
                    healthData.set(Keys.MAX_HEALTH, newMax);
                    healthData.set(Keys.HEALTH, newMax);
                    entity.offer(healthData);
                }
                // Wandering Bosses
                Collection<String> wanderers = wanderingMobManager.getSupportedWanderersOfType(entity.getType());
                for (String wanderer : wanderers) {
                    if (wanderingMobManager.chanceBind(wanderer, level, entity)) {
                        break;
                    }
                }
            }
        }
        Optional<Value<Integer>> optExplosiveRadius = Optional.empty();
        if (optExplosiveRadius.isPresent()) {
            Value<Integer> explosiveRadius = optExplosiveRadius.get();
            int min = explosiveRadius.get();
            entity.offer(Keys.EXPLOSION_RADIUS, Optional.of(MathExt.bound((min + level) / 2, min, entity instanceof Fireball ? 4 : 9)));
        }
    }
}
Also used : PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) HealthData(org.spongepowered.api.data.manipulator.mutable.entity.HealthData) Egg(org.spongepowered.api.entity.projectile.Egg) World(org.spongepowered.api.world.World) Fireball(org.spongepowered.api.entity.projectile.explosive.fireball.Fireball) Monster(org.spongepowered.api.entity.living.monster.Monster) Value(org.spongepowered.api.data.value.mutable.Value) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) Listener(org.spongepowered.api.event.Listener)

Aggregations

HealthData (org.spongepowered.api.data.manipulator.mutable.entity.HealthData)1 Value (org.spongepowered.api.data.value.mutable.Value)1 PrimedTNT (org.spongepowered.api.entity.explosive.PrimedTNT)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Egg (org.spongepowered.api.entity.projectile.Egg)1 Fireball (org.spongepowered.api.entity.projectile.explosive.fireball.Fireball)1 Listener (org.spongepowered.api.event.Listener)1 BlockSpawnCause (org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause)1 World (org.spongepowered.api.world.World)1