private ItemStack doPipeIteration(Location<World> location, ItemStack itemStack, Direction fromDirection, Set<Location<World>> traversed) { if(traversed.contains(location)) return itemStack; traversed.add(location); if(itemStack.getQuantity() == 0) return itemStack; PipePart pipePart = getPipePart(location); if(pipePart == null) return itemStack; for (Location<World> location1 : pipePart.findPotentialOutputs(location, itemStack, fromDirection)) { if (pipePart.validateOutput(location, location1, itemStack)) { if (pipePart instanceof OutputPipePart) { Optional<Inventory> inventory = LocationUtil.getInventoryForLocation(location1); if (inventory.isPresent()) { InventoryTransactionResult result = inventory.get().offer(itemStack); if (!result.getRejectedItems().isEmpty()) { for (ItemStackSnapshot snapshot : result.getRejectedItems()) { itemStack = snapshot.createStack(); } } else { itemStack.setQuantity(0); } } } else itemStack = doPipeIteration(location1, itemStack, BlockUtil.getFacing(location1, location), traversed); } } return itemStack; }
@Test public void getFacingTest() { for (Direction direction : BlockUtil.getDirectFaces()) { Location loc = new Location<>(mock(World.class), 0, 0, 0); assertTrue(BlockUtil.getFacing(loc, loc.getRelative(direction)) == direction); } } }