Search in sources :

Example 16 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class PatientXInstance method freezeBlocks.

public void freezeBlocks(int percentage, boolean throwExplosives) {
    ice.forAll((pt) -> {
        BlockType aboveType = getRegion().getExtent().getBlockType(pt.add(0, 1, 0));
        BlockType belowType = getRegion().getExtent().getBlockType(pt.add(0, -1, 0));
        if (aboveType == BlockTypes.AIR && belowType == BlockTypes.WATER || belowType == BlockTypes.FLOWING_WATER) {
            if (percentage >= 100) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.ICE, Cause.source(SkreePlugin.container()).build());
                return;
            }
            BlockType curType = getRegion().getExtent().getBlockType(pt);
            if (curType == BlockTypes.PACKED_ICE || curType == BlockTypes.ICE) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.WATER, Cause.source(SkreePlugin.container()).build());
                if (!Probability.getChance(config.snowBallChance) || !throwExplosives) {
                    return;
                }
                Location target = new Location<>(getRegion().getExtent(), pt.add(0, 1, 0));
                for (int i = Probability.getRandom(3); i > 0; i--) {
                    Snowball melvin = (Snowball) getRegion().getExtent().createEntity(EntityTypes.SNOWBALL, target.getPosition());
                    melvin.setVelocity(new Vector3d(0, Probability.getRangedRandom(.25, 1), 0));
                    getRegion().getExtent().spawnEntity(melvin, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                }
            } else if (Probability.getChance(percentage, 100)) {
                getRegion().getExtent().setBlockType(pt, BlockTypes.PACKED_ICE, Cause.source(SkreePlugin.container()).build());
            }
        }
    });
}
Also used : Snowball(org.spongepowered.api.entity.projectile.Snowball) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location)

Example 17 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class PatientXInstance method freezeEntities.

private void freezeEntities() {
    Zombie boss = getBoss().get();
    double total = 0;
    for (Living entity : getContained(Living.class)) {
        if (entity.equals(boss)) {
            continue;
        }
        BlockType curType = entity.getLocation().getBlockType();
        if (curType != BlockTypes.WATER && curType != BlockTypes.FLOWING_WATER) {
            continue;
        }
        if (entity instanceof Zombie) {
            entity.offer(Keys.HEALTH, 0D);
            EntityHealthUtil.heal(boss, 1);
            total += .02;
        } else if (!Probability.getChance(5)) {
            entity.damage(Probability.getRandom(25), EntityDamageSource.builder().entity(boss).type(DamageTypes.MAGIC).build());
        }
    }
    modifyDifficulty(-total);
}
Also used : EntityZombie(net.minecraft.entity.monster.EntityZombie) Zombie(org.spongepowered.api.entity.living.monster.Zombie) BlockType(org.spongepowered.api.block.BlockType) Living(org.spongepowered.api.entity.living.Living)

Example 18 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class FreakyFourInstance method prepareFrimus.

private void prepareFrimus() {
    ZoneBoundingBox frimusRG = regions.get(FreakyFourBoss.FRIMUS);
    frimusRG.forAll(pt -> {
        BlockType originalType = getRegion().getExtent().getBlockType(pt);
        if (originalType == BlockTypes.FIRE || originalType == BlockTypes.FLOWING_LAVA || originalType == BlockTypes.LAVA) {
            getRegion().getExtent().setBlockType(pt, BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
        }
    });
}
Also used : BlockType(org.spongepowered.api.block.BlockType) ZoneBoundingBox(com.skelril.skree.service.internal.zone.ZoneBoundingBox)

Example 19 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class FreakyFourInstance method createWall.

private void createWall(ZoneBoundingBox region, Predicate<BlockType> oldExpr, Predicate<BlockType> newExpr, BlockType oldType, BlockType newType, int density, int floodFloor) {
    final Vector3i min = region.getMinimumPoint();
    final Vector3i max = region.getMaximumPoint();
    int minX = min.getX();
    int minY = min.getY();
    int minZ = min.getZ();
    int maxX = max.getX();
    int maxY = max.getY();
    int maxZ = max.getZ();
    int initialTimes = maxZ - minZ + 1;
    IntegratedRunnable integratedRunnable = new IntegratedRunnable() {

        @Override
        public boolean run(int times) {
            int startZ = minZ + (initialTimes - times) - 1;
            for (int x = minX; x <= maxX; ++x) {
                for (int z = startZ; z < Math.min(maxZ, startZ + 4); ++z) {
                    boolean flood = Probability.getChance(density);
                    for (int y = minY; y <= maxY; ++y) {
                        BlockType block = getRegion().getExtent().getBlockType(x, y, z);
                        if (z == startZ && newExpr.test(block)) {
                            getRegion().getExtent().setBlockType(x, y, z, oldType, Cause.source(SkreePlugin.container()).build());
                        } else if (flood && oldExpr.test(block)) {
                            getRegion().getExtent().setBlockType(x, y, z, newType, Cause.source(SkreePlugin.container()).build());
                        }
                    }
                }
            }
            return true;
        }

        @Override
        public void end() {
            if (floodFloor != -1) {
                for (int x = minX; x <= maxX; ++x) {
                    for (int z = minZ; z <= maxZ; ++z) {
                        if (!Probability.getChance(floodFloor)) {
                            continue;
                        }
                        BlockType block = getRegion().getExtent().getBlockType(x, minY, z);
                        if (oldExpr.test(block)) {
                            getRegion().getExtent().setBlockType(x, minY, z, newType, Cause.source(SkreePlugin.container()).build());
                        }
                    }
                }
            }
        }
    };
    TimedRunnable<IntegratedRunnable> timedRunnable = new TimedRunnable<>(integratedRunnable, initialTimes);
    Task task = Task.builder().execute(timedRunnable).interval(500, MILLISECONDS).submit(SkreePlugin.inst());
    timedRunnable.setTask(task);
}
Also used : Task(org.spongepowered.api.scheduler.Task) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) BlockType(org.spongepowered.api.block.BlockType) Vector3i(com.flowpowered.math.vector.Vector3i) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Example 20 with BlockType

use of org.spongepowered.api.block.BlockType in project Skree by Skelril.

the class CursedMineListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    CursedMineInstance inst = optInst.get();
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        event.setCancelled(true);
        return;
    }
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        BlockType originalType = block.getOriginal().getState().getType();
        if (cursedOres.contains(originalType)) {
            // we were having some multi-firing problems
            if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
                /*if (Probability.getChance(3000)) {
            ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
            player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
          }*/
                ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
                xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
                inst.eatFood(player);
                inst.poison(player, 6);
                inst.ghost(player, originalType);
            }
        } else if (stealableFluids.contains(originalType)) {
            inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
        } else {
            block.setCustom(block.getOriginal());
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockRecord(com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)91 World (org.spongepowered.api.world.World)34 BlockState (org.spongepowered.api.block.BlockState)23 Listener (org.spongepowered.api.event.Listener)21 Location (org.spongepowered.api.world.Location)17 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)16 ItemStack (org.spongepowered.api.item.inventory.ItemStack)14 Vector3i (com.flowpowered.math.vector.Vector3i)12 Optional (java.util.Optional)12 Player (org.spongepowered.api.entity.living.player.Player)12 List (java.util.List)10 Set (java.util.Set)10 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 ArrayList (java.util.ArrayList)9 Keys (org.spongepowered.api.data.key.Keys)9 Sponge (org.spongepowered.api.Sponge)8 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6