Search in sources :

Example 71 with Location

use of org.spongepowered.api.world.Location 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 72 with Location

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

the class MainWorldWrapper method onBlockChange.

@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (optLoc.isPresent() && isApplicable(optLoc.get())) {
            boolean preventedFromBuilding = check(player, optLoc.get());
            // Block players that are allowed to build, otherwise send the no build message
            Text noEditMessage = Text.of(TextColors.RED, "You can't change blocks here!");
            if (!preventedFromBuilding) {
                if (player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.CREATIVE) {
                    preventedFromBuilding = true;
                    noEditMessage = Text.of(TextColors.RED, "You must be in creative mode to edit!");
                }
            }
            if (preventedFromBuilding) {
                if (event.getCause().root().equals(player)) {
                    player.sendMessage(noEditMessage);
                }
                event.setCancelled(true);
                return;
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 73 with Location

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

the class GoldRushInstance method randomizeLevers.

private void randomizeLevers() {
    if (System.currentTimeMillis() - lastLeverSwitch >= TimeUnit.SECONDS.toMillis(14)) {
        for (Location<World> entry : leverBlocks.keySet()) {
            BlockState state = entry.getBlock();
            entry.getExtent().setBlock(entry.getBlockPosition(), state.withTrait(BooleanTraits.LEVER_POWERED, false).orElse(state), Cause.source(SkreePlugin.container()).build());
            leverBlocks.put(entry, !Probability.getChance(3));
        }
        lastLeverSwitch = System.currentTimeMillis();
        randomizeLevers();
    } else if (System.currentTimeMillis() - lastLeverSwitch == 0) {
        for (Location<World> entry : leverBlocks.keySet()) {
            Location<World> targLoc = entry.add(0, -2, 0);
            targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
        }
        Task.builder().execute(() -> {
            for (Map.Entry<Location<World>, Boolean> entry : leverBlocks.entrySet()) {
                Location<World> targLoc = entry.getKey().add(0, -2, 0);
                targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), entry.getValue() ? BlockTypes.REDSTONE_BLOCK : BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
            }
            Task.builder().execute(this::randomizeLevers).delayTicks(15).submit(SkreePlugin.inst());
        }).delayTicks(15).submit(SkreePlugin.inst());
    } else {
        for (Location<World> entry : leverBlocks.keySet()) {
            Location<World> targLoc = entry.add(0, -2, 0);
            targLoc.getExtent().setBlockType(targLoc.getBlockPosition(), BlockTypes.STONEBRICK, Cause.source(SkreePlugin.container()).build());
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Example 74 with Location

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

the class GoldRushInstance method findChestAndKeys.

private void findChestAndKeys() {
    keyRoom.forAll((pt) -> {
        BlockState block = getRegion().getExtent().getBlock(pt);
        if (block.getType() == BlockTypes.CHEST) {
            // TODO Sponge port
            Optional<TileEntity> optTileEnt = getRegion().getExtent().getTileEntity(pt);
            if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
                ((IInventory) optTileEnt.get()).clear();
            }
            chestBlocks.add(new Location<>(getRegion().getExtent(), pt));
        } else if (block.getType() == BlockTypes.WALL_SIGN) {
            Optional<org.spongepowered.api.block.tileentity.TileEntity> optTileEnt = getRegion().getExtent().getTileEntity(pt);
            if (!optTileEnt.isPresent()) {
                return;
            }
            locks.add(new Location<>(getRegion().getExtent(), pt));
        }
    });
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) BlockState(org.spongepowered.api.block.BlockState) Location(org.spongepowered.api.world.Location)

Example 75 with Location

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

the class ShnugglesPrimeInstance method probeArea.

public void probeArea() {
    spawnPts.clear();
    Vector3i min = getRegion().getMinimumPoint();
    Vector3i max = getRegion().getMaximumPoint();
    int minX = min.getX();
    int minZ = min.getZ();
    int minY = min.getY();
    int maxX = max.getX();
    int maxZ = max.getZ();
    int maxY = max.getY();
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            for (int y = maxY; y >= minY; --y) {
                BlockType type = getRegion().getExtent().getBlockType(x, y, z);
                if (type == BlockTypes.GOLD_BLOCK) {
                    Location<World> target = new Location<>(getRegion().getExtent(), x, y + 2, z);
                    if (target.getBlockType() == BlockTypes.AIR) {
                        spawnPts.add(target);
                    }
                }
            }
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14