use of org.cubeengine.module.itemduct.Network in project modules-extra by CubeEngine.
the class ItemDuctTransferListener method activate.
private void activate() {
List<Network> networks = new ArrayList<>();
for (Iterator<Location<World>> it = this.promptedActivations.keySet().iterator(); it.hasNext(); ) {
Location<World> loc = it.next();
if (this.promptedActivations.get(loc) - 1000 > System.currentTimeMillis()) {
promptedActivations.clear();
continue;
}
it.remove();
// Check if data is still present
Optional<DuctData> data = loc.get(DuctData.class);
if (data.isPresent()) {
for (Direction dir : Direction.values()) {
if (dir.isCardinal() || dir.isUpright()) {
BlockType type = loc.getRelative(dir).getBlockType();
if (STICKY_PISTON.equals(type) || OBSERVER.equals(type)) {
Optional<List<ItemStack>> filters = data.get().get(dir);
if (filters.isPresent()) {
Network network = manager.findNetwork(loc.getRelative(dir));
TileEntity te = loc.getTileEntity().get();
Inventory inventory = ((Carrier) te).getInventory();
if (te instanceof Chest) {
inventory = ((Chest) te).getDoubleChestInventory().orElse(inventory);
}
network.activate(inventory, filters.get());
networks.add(network);
}
}
}
}
}
}
for (Network network : networks) {
for (Location<World> exitLoc : network.exitPoints.keySet()) {
Direction exitDir = exitLoc.get(Keys.DIRECTION).orElse(Direction.NONE).getOpposite();
exitLoc = exitLoc.getRelative(exitDir.getOpposite());
promptActivation(exitLoc.getTileEntity().filter(t -> t instanceof Carrier).map(Carrier.class::cast).orElse(null), true, null);
}
}
if (promptedActivations.isEmpty()) {
task.cancel();
}
}
Aggregations