Search in sources :

Example 1 with LockCode

use of net.minecraft.world.LockCode 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)

Aggregations

BigDecimal (java.math.BigDecimal)1 ContainerChest (net.minecraft.inventory.ContainerChest)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 ILockableContainer (net.minecraft.world.ILockableContainer)1 LockCode (net.minecraft.world.LockCode)1 Listener (org.spongepowered.api.event.Listener)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1