Search in sources :

Example 1 with PipeEventPriority

use of buildcraft.transport.pipes.events.PipeEventPriority in project BuildCraft by BuildCraft.

the class PipeItemsClay method eventHandler.

@PipeEventPriority(priority = -200)
public void eventHandler(PipeEventItem.FindDest event) {
    List<EnumSet<EnumFacing>> newDestinations = new ArrayList<>(event.destinations.size() * 2);
    for (EnumSet<EnumFacing> faces : event.destinations) {
        EnumSet<EnumFacing> nonPipesList = EnumSet.noneOf(EnumFacing.class);
        EnumSet<EnumFacing> pipesList = EnumSet.noneOf(EnumFacing.class);
        for (EnumFacing o : faces) {
            if (!event.item.blacklist.contains(o) && container.pipe.outputOpen(o)) {
                if (container.isPipeConnected(o)) {
                    TileEntity entity = container.getTile(o);
                    if (entity instanceof IPipeTile) {
                        pipesList.add(o);
                    } else {
                        nonPipesList.add(o);
                    }
                }
            }
        }
        if (!nonPipesList.isEmpty()) {
            newDestinations.add(nonPipesList);
        }
        if (!pipesList.isEmpty()) {
            newDestinations.add(pipesList);
        }
    }
    event.destinations.clear();
    event.destinations.addAll(newDestinations);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPipeTile(buildcraft.api.transport.IPipeTile) EnumSet(java.util.EnumSet) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) PipeEventPriority(buildcraft.transport.pipes.events.PipeEventPriority)

Example 2 with PipeEventPriority

use of buildcraft.transport.pipes.events.PipeEventPriority in project BuildCraft by BuildCraft.

the class LensFilterHandler method eventHandler.

@PipeEventPriority(priority = -100)
public void eventHandler(PipeEventItem.FindDest event) {
    IPipeTile container = event.pipe.getTile();
    List<EnumSet<EnumFacing>> newDestinations = new ArrayList<>(event.destinations.size() * 2);
    for (EnumSet<EnumFacing> dirs : event.destinations) {
        EnumSet<EnumFacing> correctColored = EnumSet.noneOf(EnumFacing.class);
        EnumSet<EnumFacing> notColored = EnumSet.noneOf(EnumFacing.class);
        EnumDyeColor myColor = event.item.color;
        for (EnumFacing dir : dirs) {
            boolean hasFilter = false;
            boolean hasLens = false;
            EnumDyeColor sideColor = null;
            EnumDyeColor sideLensColor = null;
            // Get the side's color
            // (1/2) From this pipe's outpost
            PipePluggable pluggable = container.getPipePluggable(dir);
            if (pluggable != null && pluggable instanceof LensPluggable) {
                if (((LensPluggable) pluggable).isFilter) {
                    hasFilter = true;
                    sideColor = ((LensPluggable) pluggable).dyeColor;
                } else {
                    hasLens = true;
                    sideLensColor = ((LensPluggable) pluggable).dyeColor;
                }
            }
            // (2/2) From the other pipe's outpost
            IPipe otherPipe = container.getNeighborPipe(dir);
            if (otherPipe != null && otherPipe.getTile() != null) {
                IPipeTile otherContainer = otherPipe.getTile();
                pluggable = otherContainer.getPipePluggable(dir.getOpposite());
                if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
                    EnumDyeColor otherColor = ((LensPluggable) pluggable).dyeColor;
                    if (hasFilter && otherColor != sideColor) {
                        // Filter colors conflict - the side is unpassable
                        continue;
                    } else if (hasLens) {
                        // treated as colorless
                        if (sideLensColor == otherColor) {
                            hasFilter = false;
                            sideColor = null;
                        } else {
                            continue;
                        }
                    } else {
                        hasFilter = true;
                        sideColor = otherColor;
                    }
                }
            }
            if (hasFilter) {
                if (myColor == sideColor) {
                    correctColored.add(dir);
                }
            } else {
                notColored.add(dir);
            }
        }
        if (!correctColored.isEmpty()) {
            newDestinations.add(correctColored);
        }
        if (!notColored.isEmpty()) {
            newDestinations.add(notColored);
        }
    }
    event.destinations.clear();
    event.destinations.addAll(newDestinations);
}
Also used : IPipeTile(buildcraft.api.transport.IPipeTile) LensPluggable(buildcraft.transport.pluggable.LensPluggable) EnumSet(java.util.EnumSet) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) EnumDyeColor(net.minecraft.item.EnumDyeColor) IPipe(buildcraft.api.transport.IPipe) PipeEventPriority(buildcraft.transport.pipes.events.PipeEventPriority)

Aggregations

IPipeTile (buildcraft.api.transport.IPipeTile)2 PipeEventPriority (buildcraft.transport.pipes.events.PipeEventPriority)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 EnumFacing (net.minecraft.util.EnumFacing)2 IPipe (buildcraft.api.transport.IPipe)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 LensPluggable (buildcraft.transport.pluggable.LensPluggable)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 TileEntity (net.minecraft.tileentity.TileEntity)1