Search in sources :

Example 1 with BlockSpawnCause

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

Example 2 with BlockSpawnCause

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);
}
Also used : WorldService(com.skelril.skree.service.WorldService) StormBringer(com.skelril.skree.content.world.wilderness.wanderer.StormBringer) Value(org.spongepowered.api.data.value.mutable.Value) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) ScoreTypes(com.skelril.skree.service.internal.highscore.ScoreTypes) ModifierService(com.skelril.skree.service.ModifierService) HighScoreService(com.skelril.skree.service.HighScoreService) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SkreePlugin(com.skelril.skree.SkreePlugin) TextColor(org.spongepowered.api.text.format.TextColor) org.spongepowered.api.entity(org.spongepowered.api.entity) Living(org.spongepowered.api.entity.living.Living) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) ItemDropper(com.skelril.nitro.item.ItemDropper) Location(org.spongepowered.api.world.Location) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Extent(org.spongepowered.api.world.extent.Extent) BlockTypes(org.spongepowered.api.block.BlockTypes) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) BlockState(org.spongepowered.api.block.BlockState) HealthData(org.spongepowered.api.data.manipulator.mutable.entity.HealthData) Egg(org.spongepowered.api.entity.projectile.Egg) Cancellable(org.spongepowered.api.event.Cancellable) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) World(org.spongepowered.api.world.World) HandTypes(org.spongepowered.api.data.type.HandTypes) NamedCause(org.spongepowered.api.event.cause.NamedCause) Player(org.spongepowered.api.entity.living.player.Player) RespawnPlayerEvent(org.spongepowered.api.event.entity.living.humanoid.player.RespawnPlayerEvent) EntityHealthPrinter(com.skelril.nitro.entity.EntityHealthPrinter) PrimedTNT(org.spongepowered.api.entity.explosive.PrimedTNT) java.util(java.util) DestructEntityEvent(org.spongepowered.api.event.entity.DestructEntityEvent) Vector3d(com.flowpowered.math.vector.Vector3d) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) Supplier(java.util.function.Supplier) GraveDigger(com.skelril.skree.content.world.wilderness.wanderer.GraveDigger) Lists(com.google.common.collect.Lists) MathExt(com.skelril.nitro.numeric.MathExt) Text(org.spongepowered.api.text.Text) DropTableEntryImpl(com.skelril.nitro.droptable.DropTableEntryImpl) TextColors(org.spongepowered.api.text.format.TextColors) DimensionTypes(org.spongepowered.api.world.DimensionTypes) Nullable(javax.annotation.Nullable) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Enchantments(org.spongepowered.api.item.Enchantments) DropTable(com.skelril.nitro.droptable.DropTable) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) Validate(org.apache.commons.lang3.Validate) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) QuantityBoundedItemStackConfig(com.skelril.nitro.registry.dynamic.QuantityBoundedItemStackConfig) CombinedText(com.skelril.nitro.text.CombinedText) Wither(org.spongepowered.api.entity.living.monster.Wither) SimpleDropResolver(com.skelril.nitro.droptable.resolver.SimpleDropResolver) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) EnchantmentUtil(com.skelril.nitro.data.util.EnchantmentUtil) TimedRunnable(com.skelril.nitro.time.TimedRunnable) PotionEffectTypes(org.spongepowered.api.effect.potion.PotionEffectTypes) Fangz(com.skelril.skree.content.world.wilderness.wanderer.Fangz) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Title(org.spongepowered.api.text.title.Title) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) CollideEntityEvent(org.spongepowered.api.event.entity.CollideEntityEvent) Transaction(org.spongepowered.api.data.Transaction) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) TextStyles(org.spongepowered.api.text.format.TextStyles) Sponge(org.spongepowered.api.Sponge) PvPService(com.skelril.skree.service.PvPService) Cause(org.spongepowered.api.event.cause.Cause) Explosion(org.spongepowered.api.world.explosion.Explosion) Named(org.spongepowered.api.event.filter.cause.Named) BlockType(org.spongepowered.api.block.BlockType) First(org.spongepowered.api.event.filter.cause.First) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) Keys(org.spongepowered.api.data.key.Keys) MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) WorldEffectWrapperImpl(com.skelril.skree.service.internal.world.WorldEffectWrapperImpl) GRAVE_STONE(com.skelril.skree.content.registry.block.CustomBlockTypes.GRAVE_STONE) CofferResolver(com.skelril.skree.content.droptable.CofferResolver) SlipperySingleHitDiceRoller(com.skelril.nitro.droptable.roller.SlipperySingleHitDiceRoller) Boss(org.spongepowered.api.entity.living.monster.Boss) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) Task(org.spongepowered.api.scheduler.Task) Probability(com.skelril.nitro.probability.Probability) Fireball(org.spongepowered.api.entity.projectile.explosive.fireball.Fireball) PlaceHolderText(com.skelril.nitro.text.PlaceHolderText) Creeper(org.spongepowered.api.entity.living.monster.Creeper) ItemStackConfig(com.skelril.nitro.registry.dynamic.ItemStackConfig) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) Modifiers(com.skelril.skree.content.modifier.Modifiers) Monster(org.spongepowered.api.entity.living.monster.Monster) TimeUnit(java.util.concurrent.TimeUnit) DamageFunction(org.spongepowered.api.event.cause.entity.damage.DamageFunction) DropTableImpl(com.skelril.nitro.droptable.DropTableImpl) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener) ItemType(org.spongepowered.api.item.ItemType) SECONDS(java.util.concurrent.TimeUnit.SECONDS) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 3 with BlockSpawnCause

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;
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Egg(org.spongepowered.api.entity.projectile.Egg) ItemDropper(com.skelril.nitro.item.ItemDropper) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) SkeletonHorse(org.spongepowered.api.entity.living.animal.SkeletonHorse) Listener(org.spongepowered.api.event.Listener)

Aggregations

Monster (org.spongepowered.api.entity.living.monster.Monster)3 Egg (org.spongepowered.api.entity.projectile.Egg)3 Listener (org.spongepowered.api.event.Listener)3 BlockSpawnCause (org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause)3 ItemDropper (com.skelril.nitro.item.ItemDropper)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 Lists (com.google.common.collect.Lists)1 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)1 EnchantmentUtil (com.skelril.nitro.data.util.EnchantmentUtil)1 DropTable (com.skelril.nitro.droptable.DropTable)1 DropTableEntryImpl (com.skelril.nitro.droptable.DropTableEntryImpl)1 DropTableImpl (com.skelril.nitro.droptable.DropTableImpl)1 MasterDropTable (com.skelril.nitro.droptable.MasterDropTable)1 SimpleDropResolver (com.skelril.nitro.droptable.resolver.SimpleDropResolver)1 SlipperySingleHitDiceRoller (com.skelril.nitro.droptable.roller.SlipperySingleHitDiceRoller)1 EntityHealthPrinter (com.skelril.nitro.entity.EntityHealthPrinter)1 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 MathExt (com.skelril.nitro.numeric.MathExt)1 Probability (com.skelril.nitro.probability.Probability)1 ItemStackConfig (com.skelril.nitro.registry.dynamic.ItemStackConfig)1