Search in sources :

Example 6 with Inventory

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

the class TemplateCrateView 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) HuskyCrates(pw.codehusky.huskycrates.HuskyCrates) ItemTypes(org.spongepowered.api.item.ItemTypes) Random(java.util.Random) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) ArrayList(java.util.ArrayList) VirtualCrate(pw.codehusky.huskycrates.crate.VirtualCrate) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) Player(org.spongepowered.api.entity.living.player.Player) 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 7 with Inventory

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

the class FocusTeleporter method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<org.spongepowered.api.item.inventory.ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    org.spongepowered.api.item.inventory.ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    Optional<Location<World>> optDestination = getDestination(held);
    if (!optDestination.isPresent()) {
        return;
    }
    Inventory result = player.getInventory().query((ItemType) Sponge.getRegistry().getType(ItemType.class, "skree:ender_focus").get());
    if (result.size() > 0) {
        Task.builder().execute(() -> {
            result.poll(1);
            player.setLocation(optDestination.get());
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) ItemStack(net.minecraft.item.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 8 with Inventory

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

the class GoldRushListener method onChestOpen.

@Listener
public void onChestOpen(InteractInventoryEvent.Open event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent())
        return;
    GoldRushInstance inst = optInst.get();
    Inventory inventory = event.getTargetInventory();
    if (!inst.isLocked() && inventory instanceof ContainerChest) {
        IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
        if (chestInv instanceof ILockableContainer) {
            LockCode newLockCode = new LockCode(UUID.randomUUID().toString());
            tileEntityClaimMap.put(newLockCode.getLock(), player);
            ((ILockableContainer) chestInv).setLockCode(newLockCode);
            BigDecimal risk = Optional.ofNullable(inst.cofferRisk.get(player.getUniqueId())).orElse(BigDecimal.ZERO);
            Collection<org.spongepowered.api.item.inventory.ItemStack> queue = CofferValueMap.inst().satisfy(risk.toBigInteger());
            Iterator<org.spongepowered.api.item.inventory.ItemStack> it = queue.iterator();
            for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
                if (it.hasNext()) {
                    chestInv.setInventorySlotContents(i, tf(it.next()));
                    continue;
                }
                chestInv.setInventorySlotContents(i, null);
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) BigDecimal(java.math.BigDecimal) ILockableContainer(net.minecraft.world.ILockableContainer) ContainerChest(net.minecraft.inventory.ContainerChest) LockCode(net.minecraft.world.LockCode) ItemStack(net.minecraft.item.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Listener(org.spongepowered.api.event.Listener)

Example 9 with Inventory

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

the class PlayerStateServiceImpl method load.

@Override
public void load(Player player, String saveName) {
    Iterator<Inventory> slots = player.getInventory().slots().iterator();
    List<JsonElement> persistedInventoryContents = getInventoryContents(player, saveName);
    for (int i = 0; slots.hasNext(); ++i) {
        Inventory slot = slots.next();
        if (i < persistedInventoryContents.size()) {
            try {
                ItemStack stack = deserializeItemStack(persistedInventoryContents.get(i));
                slot.set(stack);
                continue;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        slot.set(newItemStack(ItemTypes.NONE));
    }
}
Also used : JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) ItemSerializer.serializeItemStack(com.skelril.nitro.item.ItemSerializer.serializeItemStack) ItemSerializer.deserializeItemStack(com.skelril.nitro.item.ItemSerializer.deserializeItemStack) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) 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