Search in sources :

Example 51 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class CustomTerragu method destroyLine.

protected int destroyLine(Player player, Direction dir, int maxDist, BlockSnapshot state) {
    Location<World> starting = state.getLocation().get();
    int i;
    for (i = 0; i < maxDist; ++i) {
        starting = starting.add(dir.toVector3d());
        if (starting.getBlockType() != state.getState().getType()) {
            break;
        }
        /*if (!starting.getExtent().digBlock(starting.getBlockPosition(), Cause.of(NamedCause.simulated(player)))) {
                break;
            }*/
        ((net.minecraft.world.World) starting.getExtent()).destroyBlock(new BlockPos(starting.getX(), starting.getY(), starting.getZ()), true);
    }
    return i;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(org.spongepowered.api.world.World)

Example 52 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class MagicWand method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    if (optHeldItem.get().getItem() != this) {
        return;
    }
    event.setUseBlockResult(Tristate.FALSE);
    Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
    if (!optLoc.isPresent()) {
        return;
    }
    Location<World> loc = optLoc.get();
    BlockType targetType = loc.getBlockType();
    if (targetType == CustomBlockTypes.MAGIC_LADDER) {
        MagicBlockStateHelper.startLadder(loc);
    } else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
        MagicBlockStateHelper.startPlatform(loc);
    } else {
        return;
    }
    if (!survival) {
        MagicBlockStateHelper.resetCounts();
        return;
    }
    MagicBlockStateHelper.dropItems(loc, event.getCause());
}
Also used : BlockType(org.spongepowered.api.block.BlockType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 53 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class WildernessWorldWrapper method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> block : transactions) {
        BlockSnapshot original = block.getOriginal();
        Optional<Location<World>> optLoc = original.getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Integer> optLevel = getLevel(optLoc.get());
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        Location<World> loc = optLoc.get();
        BlockState state = original.getState();
        BlockType type = state.getType();
        // Prevent item dupe glitch by removing the position before subsequent breaks
        markedOrePoints.remove(loc);
        if (config.getDropAmplificationConfig().amplifies(state)) {
            markedOrePoints.add(loc);
        }
        if (srcEnt instanceof Player && type.equals(BlockTypes.STONE) && Probability.getChance(Math.max(12, 250 - level))) {
            Vector3d max = loc.getPosition().add(1, 1, 1);
            Vector3d min = loc.getPosition().sub(1, 1, 1);
            Extent world = loc.getExtent();
            if (Probability.getChance(3)) {
                Entity entity = world.createEntity(EntityTypes.SILVERFISH, loc.getPosition().add(.5, 0, .5));
                world.spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
            }
            // Do this one tick later to guarantee no collision with transaction data
            Task.builder().delayTicks(1).execute(() -> {
                for (int x = min.getFloorX(); x <= max.getFloorX(); ++x) {
                    for (int z = min.getFloorZ(); z <= max.getFloorZ(); ++z) {
                        for (int y = min.getFloorY(); y <= max.getFloorY(); ++y) {
                            if (!world.containsBlock(x, y, z)) {
                                continue;
                            }
                            if (world.getBlockType(x, y, z) == BlockTypes.STONE) {
                                world.setBlockType(x, y, z, BlockTypes.MONSTER_EGG, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                            }
                        }
                    }
                }
            }).submit(SkreePlugin.inst());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Extent(org.spongepowered.api.world.extent.Extent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 54 with World

use of org.spongepowered.api.world.World 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) ModifierService(com.skelril.skree.service.ModifierService) 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) TypeCollections.ore(com.skelril.skree.content.registry.TypeCollections.ore) 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) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Fangz(com.skelril.skree.content.world.wilderness.wanderer.Fangz) ParticleTypes(org.spongepowered.api.effect.particle.ParticleTypes) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Title(org.spongepowered.api.text.title.Title) 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) Tuple(org.spongepowered.api.util.Tuple) 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) Function(java.util.function.Function) 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) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) 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 55 with World

use of org.spongepowered.api.world.World in project Skree by Skelril.

the class StormBringer method setupStormBringer.

private void setupStormBringer() {
    Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
    List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
    bindProcessor.add((condition, boss) -> {
        Optional<Skeleton> optBossEnt = boss.getTargetEntity();
        if (optBossEnt.isPresent()) {
            Skeleton bossEnt = optBossEnt.get();
            bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Storm Bringer"));
            double bossHealth = 20 * 30 * boss.getDetail().getLevel();
            setMaxHealth(bossEnt, bossHealth, true);
        }
        return Optional.empty();
    });
    List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
    damageProcessor.add((condition, boss) -> {
        Entity eToHit = condition.getAttacked();
        if (!(eToHit instanceof Living)) {
            return Optional.empty();
        }
        Living toHit = (Living) eToHit;
        Location<World> targetLocation = toHit.getLocation();
        for (int i = boss.getDetail().getLevel() * Probability.getRangedRandom(1, 10); i >= 0; --i) {
            Task.builder().execute(() -> {
                Entity lightning = targetLocation.getExtent().createEntity(EntityTypes.LIGHTNING, targetLocation.getPosition());
                targetLocation.getExtent().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
            }).delayTicks(5 * (6 + i)).submit(SkreePlugin.inst());
        }
        return Optional.empty();
    });
}
Also used : Entity(org.spongepowered.api.entity.Entity) WildernessBossDetail(com.skelril.skree.content.world.wilderness.WildernessBossDetail) Living(org.spongepowered.api.entity.living.Living) Instruction(com.skelril.openboss.Instruction) World(org.spongepowered.api.world.World) Skeleton(org.spongepowered.api.entity.living.monster.Skeleton)

Aggregations

World (org.spongepowered.api.world.World)81 Listener (org.spongepowered.api.event.Listener)24 Location (org.spongepowered.api.world.Location)23 Entity (org.spongepowered.api.entity.Entity)18 Player (org.spongepowered.api.entity.living.player.Player)18 Vector3i (com.flowpowered.math.vector.Vector3i)11 WorldService (com.skelril.skree.service.WorldService)11 BlockType (org.spongepowered.api.block.BlockType)10 ItemStack (org.spongepowered.api.item.inventory.ItemStack)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 ArrayList (java.util.ArrayList)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)7 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)6 Living (org.spongepowered.api.entity.living.Living)5 Monster (org.spongepowered.api.entity.living.monster.Monster)5 ItemDropper (com.skelril.nitro.item.ItemDropper)4 ModifierService (com.skelril.skree.service.ModifierService)4 IOException (java.io.IOException)4