Search in sources :

Example 1 with GLASS

use of org.spongepowered.api.block.BlockTypes.GLASS in project modules-extra by CubeEngine.

the class ItemDuctManager method findNetwork.

private void findNetwork(LastDuct last, Network network, int depth) {
    if (depth > maxDepth) {
        network.errors.add(last.loc);
        return;
    }
    Map<Direction, Location<World>> map = new HashMap<>();
    Queue<Location<World>> next = new LinkedList<>();
    next.offer(last.loc);
    do {
        // TODO limit direction with glass panes
        Set<Direction> dirs = directions;
        for (Direction dir : dirs) {
            if (!dir.equals(last.from.getOpposite())) {
                Location<World> rel = last.loc.getRelative(dir);
                if (last.isCompatible(rel)) {
                    if (// No loops allowed
                    network.pipes.contains(rel)) {
                        network.errors.add(rel);
                        network.errors.add(last.loc);
                    } else {
                        network.pipes.add(rel);
                        map.put(dir, rel);
                    }
                }
                // ExitPiston?
                if (rel.getBlockType().equals(PISTON) && rel.get(Keys.DIRECTION).orElse(Direction.NONE).equals(dir)) {
                    if (rel.getRelative(dir).get(DuctData.class).map(d -> d.get(dir.getOpposite()).isPresent()).orElse(false)) {
                        network.exitPoints.put(rel, rel.getRelative(dir).get(DuctData.class).get());
                    }
                }
                // Storage Chest
                if (last.storage) {
                    rel.getTileEntity().ifPresent(te -> {
                        if (te instanceof Carrier) {
                            network.storage.add(rel);
                        }
                    });
                }
            }
        }
        if (map.size() > 1) {
            for (Map.Entry<Direction, Location<World>> entry : map.entrySet()) {
                findNetwork(new LastDuct(entry.getValue(), entry.getKey()), network, depth + 1);
            }
        } else if (map.size() == 1) {
            for (Map.Entry<Direction, Location<World>> entry : map.entrySet()) {
                last.update(entry.getValue(), entry.getKey());
            }
            next.offer(last.loc);
        }
        // else nothing found here
        next.poll();
        map.clear();
    } while (!next.isEmpty());
}
Also used : Arrays(java.util.Arrays) Keys(org.spongepowered.api.data.key.Keys) ParticleOptions(org.spongepowered.api.effect.particle.ParticleOptions) PISTON(org.spongepowered.api.block.BlockTypes.PISTON) DataRegistration(org.spongepowered.api.data.DataRegistration) ItemTypes(org.spongepowered.api.item.ItemTypes) QUARTZ_BLOCK(org.spongepowered.api.block.BlockTypes.QUARTZ_BLOCK) Vector3d(com.flowpowered.math.vector.Vector3d) HashMap(java.util.HashMap) STAINED_GLASS(org.spongepowered.api.block.BlockTypes.STAINED_GLASS) EnchantmentTypes(org.spongepowered.api.item.enchantment.EnchantmentTypes) Enchantment(org.spongepowered.api.item.enchantment.Enchantment) Collections.singletonList(java.util.Collections.singletonList) ImmutableDuctData(org.cubeengine.module.itemduct.data.ImmutableDuctData) HashSet(java.util.HashSet) ShapedCraftingRecipe(org.spongepowered.api.item.recipe.crafting.ShapedCraftingRecipe) ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) ItemStack(org.spongepowered.api.item.inventory.ItemStack) IDuctData(org.cubeengine.module.itemduct.data.IDuctData) Text(org.spongepowered.api.text.Text) ParticleTypes(org.spongepowered.api.effect.particle.ParticleTypes) Ingredient(org.spongepowered.api.item.recipe.crafting.Ingredient) SoundTypes(org.spongepowered.api.effect.sound.SoundTypes) Map(java.util.Map) DROPPER(org.spongepowered.api.block.BlockTypes.DROPPER) LinkedList(java.util.LinkedList) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) EnumSet(java.util.EnumSet) GLASS_PANE(org.spongepowered.api.block.BlockTypes.GLASS_PANE) Location(org.spongepowered.api.world.Location) DyeColor(org.spongepowered.api.data.type.DyeColor) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) DuctDataBuilder(org.cubeengine.module.itemduct.data.DuctDataBuilder) STAINED_GLASS_PANE(org.spongepowered.api.block.BlockTypes.STAINED_GLASS_PANE) Carrier(org.spongepowered.api.item.inventory.Carrier) Direction(org.spongepowered.api.util.Direction) GLASS(org.spongepowered.api.block.BlockTypes.GLASS) CraftingRecipe(org.spongepowered.api.item.recipe.crafting.CraftingRecipe) World(org.spongepowered.api.world.World) BlockType(org.spongepowered.api.block.BlockType) Color(org.spongepowered.api.util.Color) Queue(java.util.Queue) Collections(java.util.Collections) DuctData(org.cubeengine.module.itemduct.data.DuctData) HashMap(java.util.HashMap) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) LinkedList(java.util.LinkedList) Carrier(org.spongepowered.api.item.inventory.Carrier) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.spongepowered.api.world.Location)

Aggregations

Vector3d (com.flowpowered.math.vector.Vector3d)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 DuctData (org.cubeengine.module.itemduct.data.DuctData)1 DuctDataBuilder (org.cubeengine.module.itemduct.data.DuctDataBuilder)1 IDuctData (org.cubeengine.module.itemduct.data.IDuctData)1 ImmutableDuctData (org.cubeengine.module.itemduct.data.ImmutableDuctData)1 Sponge (org.spongepowered.api.Sponge)1 BlockType (org.spongepowered.api.block.BlockType)1 DROPPER (org.spongepowered.api.block.BlockTypes.DROPPER)1 GLASS (org.spongepowered.api.block.BlockTypes.GLASS)1 GLASS_PANE (org.spongepowered.api.block.BlockTypes.GLASS_PANE)1