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