Search in sources :

Example 46 with IInventory

use of net.minecraft.inventory.IInventory 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 47 with IInventory

use of net.minecraft.inventory.IInventory in project Skree by Skelril.

the class GoldRushInstance method populateChest.

private void populateChest() {
    for (Location<World> chest : chestBlocks) {
        // TODO Sponge port
        Optional<TileEntity> optTileEnt = chest.getTileEntity();
        if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
            IInventory inventory = ((IInventory) optTileEnt.get());
            int iterationTimes = Probability.getRandom(27);
            for (int i = iterationTimes; i > 0; --i) {
                ItemStack targetStack;
                int goldRand = Probability.getRandom(Probability.getRandom(Probability.getRandom(64)));
                if (Probability.getChance(1000)) {
                    targetStack = makePrizeBox(newItemStack(BlockTypes.GOLD_BLOCK, goldRand));
                } else {
                    targetStack = makePrizeBox(newItemStack(ItemTypes.GOLD_INGOT, goldRand));
                }
                inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(targetStack));
            }
            if (Probability.getChance(10000 / iterationTimes)) {
                inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(makePrizeBox(newItemStack(CustomItemTypes.PHANTOM_HYMN))));
            }
        }
    }
    for (int i = 0; i < 2; i++) {
        Optional<TileEntity> optTileEnt = Probability.pickOneOf(chestBlocks).getTileEntity();
        if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
            IInventory inventory = ((IInventory) optTileEnt.get());
            inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, new net.minecraft.item.ItemStack(CustomItemTypes.GOLD_RUSH_KEY, 1, i));
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 48 with IInventory

use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.

the class EntityLocomotive method processTicket.

private void processTicket() {
    IInventory invTicket = getTicketInventory();
    ItemStack stack = invTicket.getStackInSlot(0);
    if (stack != null)
        if (stack.getItem() instanceof ItemTicket) {
            if (setDestination(stack))
                invTicket.setInventorySlotContents(0, InvTools.depleteItem(stack));
        } else
            invTicket.setInventorySlotContents(0, null);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemTicket(mods.railcraft.common.items.ItemTicket) ItemStack(net.minecraft.item.ItemStack)

Example 49 with IInventory

use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.

the class InvTools method calcRedstoneFromInventory.

/**
     * @see Container#calcRedstoneFromInventory(IInventory)
     */
public static int calcRedstoneFromInventory(@Nullable InventoryComposite inv) {
    if (inv == null)
        return 0;
    int numStacks = 0;
    float average = 0.0F;
    for (IInventoryObject inventoryObject : inv) {
        int stackLimit = inventoryObject.getBackingObject() instanceof IInventory ? ((IInventory) inventoryObject.getBackingObject()).getInventoryStackLimit() : 64;
        for (ItemStack stack : InventoryIterator.getRailcraft(inventoryObject).getStacks()) {
            average += (float) stack.stackSize / (float) Math.min(stackLimit, stack.getMaxStackSize());
            numStacks++;
        }
    }
    average = average / (float) inv.slotCount();
    return MathHelper.floor_float(average * 14.0F) + (numStacks > 0 ? 1 : 0);
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) ItemStack(net.minecraft.item.ItemStack)

Example 50 with IInventory

use of net.minecraft.inventory.IInventory in project Railcraft by Railcraft.

the class SchematicTile method storeRequirements.

@Override
public void storeRequirements(IBuilderContext context, BlockPos pos) {
    super.storeRequirements(context, pos);
    if (state.getBlock().hasTileEntity(state)) {
        TileEntity tile = context.world().getTileEntity(pos);
        if (tile instanceof IInventory) {
            IInventory inv = (IInventory) tile;
            ArrayList<ItemStack> rqs = new ArrayList<ItemStack>();
            for (int i = 0; i < inv.getSizeInventory(); ++i) {
                if (inv.getStackInSlot(i) != null) {
                    rqs.add(inv.getStackInSlot(i));
                }
            }
            storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()]));
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IInventory (net.minecraft.inventory.IInventory)129 ItemStack (net.minecraft.item.ItemStack)80 TileEntity (net.minecraft.tileentity.TileEntity)59 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7