Search in sources :

Example 1 with ItemCompactor

use of com.skelril.nitro.item.ItemCompactor in project Skree by Skelril.

the class ScrollOfSummation method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    NonNullList<net.minecraft.item.ItemStack> pInv = tf(player).inventory.mainInventory;
    // noinspection SuspiciousToArrayCall
    Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute(pInv.toArray(new ItemStack[pInv.size()]));
    if (optCompacted.isPresent()) {
        Task.builder().execute(() -> {
            ItemStack[] nInv = optCompacted.get();
            for (int i = 0; i < pInv.size(); ++i) {
                pInv.set(i, tf(nInv[i]));
            }
            tf(player).inventoryContainer.detectAndSendChanges();
            tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
            player.sendMessage(Text.of(TextColors.GOLD, "The scroll glows brightly before turning to dust..."));
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemCompactor(com.skelril.nitro.item.ItemCompactor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with ItemCompactor

use of com.skelril.nitro.item.ItemCompactor in project Skree by Skelril.

the class HymnOfSummation method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    NonNullList<net.minecraft.item.ItemStack> pInv = tf(player).inventory.mainInventory;
    // noinspection SuspiciousToArrayCall
    Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute(pInv.toArray(new ItemStack[pInv.size()]));
    if (optCompacted.isPresent()) {
        Task.builder().execute(() -> {
            ItemStack[] nInv = optCompacted.get();
            for (int i = 0; i < pInv.size(); ++i) {
                pInv.set(i, tf(nInv[i]));
            }
            tf(player).inventoryContainer.detectAndSendChanges();
            player.sendMessage(Text.of(TextColors.GOLD, "The hymn glows brightly..."));
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemCompactor(com.skelril.nitro.item.ItemCompactor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Aggregations

ItemCompactor (com.skelril.nitro.item.ItemCompactor)2 Listener (org.spongepowered.api.event.Listener)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2