Search in sources :

Example 1 with Inventory

use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.

the class CursedMineInstance method drain.

public void drain() {
    for (Entity e : getContained(Carrier.class)) {
        // TODO Inventory API not fully implemented
        if (!(e instanceof Player)) {
            continue;
        }
        Inventory eInventory = ((Carrier) e).getInventory();
        if (e instanceof Player) {
            Location<World> playerLoc = e.getLocation();
            // Emerald
            long diff = System.currentTimeMillis() - lastActivation;
            if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
                PositionRandomizer randomizer = new PositionRandomizer(5);
                for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
                    Vector3i targetPos;
                    do {
                        targetPos = randomizer.createPosition3i(playerLoc.getPosition());
                    } while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
                    Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
                    getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
                }
            }
        }
        for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
            if (e instanceof Player) {
                if (Probability.getChance(15) && checkInventory((Player) e)) {
                    ((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
                    continue;
                }
            }
            // Iron
            eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
            // Gold
            eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
            eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
            // Redstone
            eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
            // Lap
            eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
            eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
            // Diamond
            eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
            eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
            eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) PositionRandomizer(com.skelril.nitro.position.PositionRandomizer) Player(org.spongepowered.api.entity.living.player.Player) Vector3i(com.flowpowered.math.vector.Vector3i) Carrier(org.spongepowered.api.item.inventory.Carrier) World(org.spongepowered.api.world.World) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 2 with Inventory

use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.

the class GoldRushListener method onChestClose.

@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
    Inventory inventory = event.getTargetInventory();
    if (inventory instanceof ContainerChest) {
        IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
        if (chestInv instanceof ILockableContainer) {
            String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
            Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
            if (optPlayer.isPresent()) {
                Player player = optPlayer.get();
                ((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
                Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
                if (!optInst.isPresent())
                    return;
                // TODO Sponge port
                GoldRushInstance inst = optInst.get();
                List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
                ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
                for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
                    ItemStack stack = chestInv.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (stack.getItem() instanceof CofferItem) {
                        toEvaluate.add(tf(stack));
                    } else {
                        toReturn.add(tf(stack));
                    }
                    chestInv.setInventorySlotContents(i, null);
                }
                BigDecimal value = BigDecimal.ZERO;
                for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
                    value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
                }
                inst.cofferRisk.put(player.getUniqueId(), value);
                for (Inventory slot : player.getInventory().slots()) {
                    if (toReturn.isEmpty()) {
                        break;
                    }
                    if (slot.size() == 0) {
                        slot.set(toReturn.poll());
                    }
                }
                if (!toReturn.isEmpty()) {
                    new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
                }
                player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
                MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
                targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
            }
        }
    }
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ILockableContainer(net.minecraft.world.ILockableContainer) ContainerChest(net.minecraft.inventory.ContainerChest) IInventory(net.minecraft.inventory.IInventory) Player(org.spongepowered.api.entity.living.player.Player) BigDecimal(java.math.BigDecimal) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) CofferItem(com.skelril.skree.content.registry.item.currency.CofferItem) ItemStack(net.minecraft.item.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Listener(org.spongepowered.api.event.Listener)

Example 3 with Inventory

use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.

the class MarketImplUtil method giveItems.

public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
    List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
    List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
    itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
    PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
    List<Inventory> inventories = new ArrayList<>();
    inventories.add(playerInventory.getHotbar());
    inventories.add(playerInventory.getMain());
    // Loop through replacing empty space with the requested items
    for (Inventory inventory : inventories) {
        List<ItemStackSnapshot> newBuffer = new ArrayList<>();
        for (ItemStackSnapshot snapshot : itemBuffer) {
            ItemStack stack = snapshot.createStack();
            InventoryTransactionResult result = inventory.offer(stack);
            newBuffer.addAll(result.getRejectedItems());
            transactions.add(new Clause<>(stack, stack.getQuantity()));
        }
        itemBuffer = newBuffer;
    }
    // Drop remaining items
    new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);
    return new Clause<>(true, transactions);
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Clause(com.skelril.nitro.Clause) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) PlayerInventory(org.spongepowered.api.item.inventory.entity.PlayerInventory) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)

Example 4 with Inventory

use of org.spongepowered.api.item.inventory.Inventory in project HuskyCrates-Sponge by codeHusky.

the class NullCrateView method getInventory.

@Override
public Inventory getInventory() {
    Inventory woop = Inventory.builder().property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 1)).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(TextColors.DARK_RED, "INVALID CRATE TYPE!"))).listener(ClickInventoryEvent.class, evt -> evt.setCancelled(true)).build(plugin);
    woop.offer(ItemStack.of(ItemTypes.BARRIER, 256 * 2 + 64));
    for (Inventory e : woop.slots()) {
        ItemStack b = e.peek().get();
        b.setQuantity(1);
        e.set(b);
    }
    return woop;
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) HuskyCrates(pw.codehusky.huskycrates.HuskyCrates) ItemTypes(org.spongepowered.api.item.ItemTypes) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) Player(org.spongepowered.api.entity.living.player.Player) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) TextColors(org.spongepowered.api.text.format.TextColors) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 5 with Inventory

use of org.spongepowered.api.item.inventory.Inventory in project HuskyCrates-Sponge by codeHusky.

the class SpinnerCrateView method updateInv.

private void updateInv(int state) {
    ItemStack border = ItemStack.builder().itemType(ItemTypes.STAINED_GLASS_PANE).add(Keys.DYE_COLOR, DyeColors.BLACK).build();
    border.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET, "HuskyCrates"));
    //border.offer(Keys.ITEM_LORE,lore);
    ItemStack selector = ItemStack.of(ItemTypes.REDSTONE_TORCH, 1);
    selector.offer(Keys.DISPLAY_NAME, Text.of(TextStyles.RESET, "HuskyCrates"));
    //selector.offer(Keys.ITEM_LORE,lore);
    int slotnum = 0;
    for (Inventory e : disp.slots()) {
        if (state == 0 && (slotnum == 4 || slotnum == 22)) {
            e.set(selector);
        } else if (slotnum > 9 && slotnum < 17 && state != 2) {
            //int itemNum = items.size() - 1 - Math.abs(((slotnum - 10) + (clicks)) % items.size());
            int itemNum = Math.abs((clicks + (slotnum - 9) - 3) % items.size());
            //System.out.println(itemNum);
            e.set(((CrateRewardHolder) items.get(itemNum)[1]).getDisplayItem());
            if (slotnum == 13) {
                giveToPlayer = (CrateRewardHolder) items.get(itemNum)[1];
            }
        } else if (slotnum != 13) {
            if (state == 2) {
                e.set(confettiBorder());
            } else if (state == 0) {
                e.set(border);
            }
        } else if (slotnum == 13 && state == 2) {
            e.set(giveToPlayer.getDisplayItem());
        }
        slotnum++;
    }
    if (!ourplr.isViewingInventory()) {
        ourplr.openInventory(disp, plugin.genericCause);
    }
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) CrateRewardHolder(pw.codehusky.huskycrates.crate.config.CrateRewardHolder) Inventory(org.spongepowered.api.item.inventory.Inventory)

Aggregations

Inventory (org.spongepowered.api.item.inventory.Inventory)9 ItemStack (org.spongepowered.api.item.inventory.ItemStack)5 Player (org.spongepowered.api.entity.living.player.Player)4 ItemStack (net.minecraft.item.ItemStack)3 Listener (org.spongepowered.api.event.Listener)3 ItemDropper (com.skelril.nitro.item.ItemDropper)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)2 BigDecimal (java.math.BigDecimal)2 ContainerChest (net.minecraft.inventory.ContainerChest)2 IInventory (net.minecraft.inventory.IInventory)2 ILockableContainer (net.minecraft.world.ILockableContainer)2 ClickInventoryEvent (org.spongepowered.api.event.item.inventory.ClickInventoryEvent)2 ItemTypes (org.spongepowered.api.item.ItemTypes)2 InventoryDimension (org.spongepowered.api.item.inventory.property.InventoryDimension)2 InventoryTitle (org.spongepowered.api.item.inventory.property.InventoryTitle)2 Text (org.spongepowered.api.text.Text)2 TextColors (org.spongepowered.api.text.format.TextColors)2 HuskyCrates (pw.codehusky.huskycrates.HuskyCrates)2 VirtualCrate (pw.codehusky.huskycrates.crate.VirtualCrate)2 Vector3i (com.flowpowered.math.vector.Vector3i)1