Search in sources :

Example 26 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.

the class SpongeBlockSnapshot method merge.

@Override
public BlockSnapshot merge(BlockSnapshot that, MergeFunction function) {
    BlockSnapshot merged = this;
    merged = merged.withState(function.merge(this.blockState, that.getState()));
    for (ImmutableDataManipulator<?, ?> manipulator : that.getContainers()) {
        Optional<BlockSnapshot> optional = merged.with(function.merge(this.get(manipulator.getClass()).orElse(null), manipulator));
        if (optional.isPresent()) {
            merged = optional.get();
        }
    }
    return merged;
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot)

Example 27 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.

the class SpongeBlockSnapshot method with.

@Override
public Optional<BlockSnapshot> with(Iterable<ImmutableDataManipulator<?, ?>> valueContainers) {
    BlockSnapshot snapshot = this;
    for (ImmutableDataManipulator<?, ?> manipulator : valueContainers) {
        final Optional<BlockSnapshot> optional = snapshot.with(manipulator);
        if (!optional.isPresent()) {
            return Optional.empty();
        }
        snapshot = optional.get();
    }
    return Optional.of(snapshot);
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot)

Example 28 with BlockSnapshot

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

the class AntiCactusFarmListener method onItemDrop.

@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
    if (event.getCause().containsType(Player.class)) {
        return;
    }
    BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
    Optional<Location<World>> optLocation = blockSnapshot.getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> location = optLocation.get();
    while (true) {
        location = location.add(0, -1, 0);
        if (location.getBlockType() != BlockTypes.CACTUS) {
            break;
        }
        location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 29 with BlockSnapshot

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

the class GoldRushListener method onPlayerInteractEvent.

@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    GoldRushInstance inst = optInst.get();
    BlockSnapshot snapshot = event.getTargetBlock();
    BlockState state = snapshot.getState();
    if (!snapshot.getLocation().isPresent()) {
        return;
    }
    Location<World> targetBlock = snapshot.getLocation().get();
    if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
        Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
        if (!optTileEnt.isPresent()) {
            return;
        }
        TileEntity tileEntity = optTileEnt.get();
        Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
        if (!optTexts.isPresent()) {
            return;
        }
        List<Text> texts = optTexts.get();
        boolean unlocked = false;
        String text = texts.get(1).toPlain().toLowerCase();
        NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
        for (int i = 0; i < itemStacks.size(); ++i) {
            ItemStack is = itemStacks.get(i);
            if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
                continue;
            }
            if (text.contains("blue")) {
                if (is.getItemDamage() != 1) {
                    continue;
                }
            } else if (text.contains("red")) {
                if (is.getItemDamage() != 0) {
                    continue;
                }
            } else {
                continue;
            }
            unlocked = true;
            itemStacks.set(i, ItemStack.EMPTY);
            break;
        }
        if (unlocked) {
            tf(player).inventoryContainer.detectAndSendChanges();
            texts.set(2, Text.of("Locked"));
            texts.set(3, Text.of("- Unlocked -"));
            tileEntity.offer(Keys.SIGN_LINES, texts);
        }
    } else if (state.getType() == BlockTypes.LEVER) {
        Task.builder().execute(() -> {
            if (inst.checkLevers()) {
                inst.completeGame();
            }
        }).delayTicks(1).submit(SkreePlugin.inst());
    } else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
        event.setUseItemResult(Tristate.FALSE);
        event.setUseBlockResult(Tristate.FALSE);
        player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
        inst.payPlayer(player);
    } else if (!inst.isLocked()) {
        if (state.getType() == BlockTypes.STONE_BUTTON) {
            inst.tryToStart();
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 30 with BlockSnapshot

use of org.spongepowered.api.block.BlockSnapshot 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

BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)144 World (org.spongepowered.api.world.World)64 Listener (org.spongepowered.api.event.Listener)61 Location (org.spongepowered.api.world.Location)27 BlockState (org.spongepowered.api.block.BlockState)21 BlockPos (net.minecraft.util.math.BlockPos)20 Entity (org.spongepowered.api.entity.Entity)20 CauseStackManager (org.spongepowered.api.event.CauseStackManager)19 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)18 IBlockState (net.minecraft.block.state.IBlockState)18 Transaction (org.spongepowered.api.data.Transaction)17 BlockType (org.spongepowered.api.block.BlockType)15 Direction (org.spongepowered.api.util.Direction)15 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)14 Vector3d (com.flowpowered.math.vector.Vector3d)13 ArrayList (java.util.ArrayList)13 ChangeBlockEvent (org.spongepowered.api.event.block.ChangeBlockEvent)13 Player (org.spongepowered.api.entity.living.player.Player)12 User (org.spongepowered.api.entity.living.player.User)11 LocatableBlock (org.spongepowered.api.world.LocatableBlock)11