use of org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause 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)));
}
}
}
use of org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause in project Skree by Skelril.
the class WildernessWorldWrapper method onItemDrop.
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> loc = optLocation.get();
if (!markedOrePoints.remove(loc)) {
return;
}
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
List<ItemStackSnapshot> itemStacks = new ArrayList<>();
event.getEntities().forEach((entity -> {
if (entity instanceof Item) {
ItemStackSnapshot snapshot = ((Item) entity).item().get();
itemStacks.add(getPoolItemDrop(snapshot));
}
}));
addPool(loc, () -> itemStacks);
}
use of org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause in project Skree by Skelril.
the class BuildWorldWrapper 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) {
if (!isApplicable(entity)) {
continue;
}
if (entity instanceof Lightning) {
((Lightning) entity).setEffect(true);
continue;
}
if (entity instanceof Egg && optBlockCause.isPresent()) {
new ItemDropper(entity.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.EGG)), SpawnTypes.DISPENSE);
event.setCancelled(true);
return;
}
if (entity instanceof Monster || (entity instanceof SkeletonHorse)) {
event.setCancelled(true);
return;
}
}
}
Aggregations