Search in sources :

Example 1 with Dropper

use of org.spongepowered.api.block.tileentity.carrier.Dropper in project modules-extra by CubeEngine.

the class Network method activate.

public void activate(Inventory inventory, List<ItemStack> filters) {
    if (isStorage()) {
        pullFromStorage(inventory, filters);
        return;
    }
    for (Map.Entry<Location<World>, DuctData> entry : exitPoints.entrySet()) {
        Inventory pollFrom = inventory;
        Location<World> loc = entry.getKey();
        DuctData data = entry.getValue();
        Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite();
        Location<World> targetLoc = loc.getRelative(dir.getOpposite());
        TileEntity te = targetLoc.getTileEntity().get();
        Inventory target = ((Carrier) te).getInventory();
        if (te instanceof Dropper) {
            Network nw = manager.findNetwork(targetLoc);
            nw.transferToStorage(queryFiltered(filters, inventory), data.get(dir).get());
            continue;
        }
        if (te instanceof Chest) {
            target = ((Chest) te).getDoubleChestInventory().orElse(target);
        }
        Optional<List<ItemStack>> targetFilter = data.get(dir);
        if (targetFilter.isPresent()) {
            if (// Only allow to extract items in the filter
            !filters.isEmpty()) {
                // TODO more filters
                pollFrom = queryFiltered(filters, inventory);
            }
            Inventory pollFromTo = pollFrom;
            if (// Only allow to insert items in the filter
            !targetFilter.get().isEmpty()) {
                // TODO more filters
                pollFromTo = queryFiltered(targetFilter.get(), inventory);
            }
            // For all filtered slots
            doTransfer(pollFromTo, target);
        }
    }
}
Also used : Chest(org.spongepowered.api.block.tileentity.carrier.Chest) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Dropper(org.spongepowered.api.block.tileentity.carrier.Dropper) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) DuctData(org.cubeengine.module.itemduct.data.DuctData) List(java.util.List) Carrier(org.spongepowered.api.item.inventory.Carrier) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Inventory(org.spongepowered.api.item.inventory.Inventory) Location(org.spongepowered.api.world.Location)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 DuctData (org.cubeengine.module.itemduct.data.DuctData)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 Chest (org.spongepowered.api.block.tileentity.carrier.Chest)1 Dropper (org.spongepowered.api.block.tileentity.carrier.Dropper)1 Carrier (org.spongepowered.api.item.inventory.Carrier)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 Direction (org.spongepowered.api.util.Direction)1 Location (org.spongepowered.api.world.Location)1 World (org.spongepowered.api.world.World)1