aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/interfaces/metatileentity/IMetaTileEntityItemPipe.java
blob: 1b1ce36871de6ef7b36cc214bfe178936d305be3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package gregtech.api.interfaces.metatileentity;

import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
import gregtech.api.util.GT_Utility;
import java.util.Map;

public interface IMetaTileEntityItemPipe extends IMetaTileEntity {
    /**
     * @return if this Pipe can still be used.
     */
    boolean pipeCapacityCheck();

    /**
     * @return if this Pipe can still be used.
     */
    boolean incrementTransferCounter(int aIncrement);

    /**
     * Sends an ItemStack from aSender to the adjacent Blocks.
     *
     * @param aSender the BaseMetaTileEntity sending the Stack.
     * @return if it was able to send something
     */
    boolean sendItemStack(Object aSender);

    /**
     * Executes the Sending Code for inserting Stacks into the TileEntities.
     *
     * @param aSender the BaseMetaTileEntity sending the Stack.
     * @param aSide   the Side of the PIPE facing the TileEntity.
     * @return if this Side was allowed to Output into the Block.
     */
    boolean insertItemStackIntoTileEntity(Object aSender, byte aSide);

    /**
     * Can be used to make flow control Pipes, like Redpowers Restriction Tubes.
     * Every normal Pipe returns a Value of 32768, so you can easily insert lower Numbers to set Routing priorities.
     * Negative Numbers to "suck" Items into a certain direction are also possible.
     */
    int getStepSize();

    /**
     * Utility for the Item Network
     */
    class Util {
        /**
         * @return a List of connected Item Pipes
         */
        public static Map<IMetaTileEntityItemPipe, Long> scanPipes(
                IMetaTileEntityItemPipe aMetaTileEntity,
                Map<IMetaTileEntityItemPipe, Long> aMap,
                long aStep,
                boolean aSuckItems,
                boolean aIgnoreCapacity) {
            aStep += aMetaTileEntity.getStepSize();
            if (aIgnoreCapacity || aMetaTileEntity.pipeCapacityCheck())
                if (aMap.get(aMetaTileEntity) == null || aMap.get(aMetaTileEntity) > aStep) {
                    IGregTechTileEntity aBaseMetaTileEntity = aMetaTileEntity.getBaseMetaTileEntity();
                    aMap.put(aMetaTileEntity, aStep);
                    for (byte i = 0, j = 0; i < 6; i++) {
                        if (aMetaTileEntity instanceof IConnectable
                                && !((IConnectable) aMetaTileEntity).isConnectedAtSide(i)) continue;
                        j = GT_Utility.getOppositeSide(i);
                        if (aSuckItems) {
                            if (aBaseMetaTileEntity
                                    .getCoverBehaviorAtSideNew(i)
                                    .letsItemsIn(
                                            i,
                                            aBaseMetaTileEntity.getCoverIDAtSide(i),
                                            aBaseMetaTileEntity.getComplexCoverDataAtSide(i),
                                            -2,
                                            aBaseMetaTileEntity)) {
                                IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i);
                                if (aBaseMetaTileEntity.getColorization() >= 0) {
                                    byte tColor = tItemPipe.getColorization();
                                    if (tColor >= 0 && tColor != aBaseMetaTileEntity.getColorization()) {
                                        continue;
                                    }
                                }
                                if (tItemPipe instanceof BaseMetaPipeEntity) {
                                    IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity();
                                    if (tMetaTileEntity instanceof IMetaTileEntityItemPipe
                                            && tItemPipe
                                                    .getCoverBehaviorAtSideNew(j)
                                                    .letsItemsOut(
                                                            j,
                                                            tItemPipe.getCoverIDAtSide(j),
                                                            tItemPipe.getComplexCoverDataAtSide(j),
                                                            -2,
                                                            tItemPipe)) {
                                        scanPipes(
                                                (IMetaTileEntityItemPipe) tMetaTileEntity,
                                                aMap,
                                                aStep,
                                                aSuckItems,
                                                aIgnoreCapacity);
                                    }
                                }
                            }
                        } else {
                            if (aBaseMetaTileEntity
                                    .getCoverBehaviorAtSideNew(i)
                                    .letsItemsOut(
                                            i,
                                            aBaseMetaTileEntity.getCoverIDAtSide(i),
                                            aBaseMetaTileEntity.getComplexCoverDataAtSide(i),
                                            -2,
                                            aBaseMetaTileEntity)) {
                                IGregTechTileEntity tItemPipe = aBaseMetaTileEntity.getIGregTechTileEntityAtSide(i);
                                if (tItemPipe != null) {
                                    if (aBaseMetaTileEntity.getColorization() >= 0) {
                                        byte tColor = tItemPipe.getColorization();
                                        if (tColor >= 0 && tColor != aBaseMetaTileEntity.getColorization()) {
                                            continue;
                                        }
                                    }
                                    if (tItemPipe instanceof BaseMetaPipeEntity) {
                                        IMetaTileEntity tMetaTileEntity = tItemPipe.getMetaTileEntity();
                                        if (tMetaTileEntity instanceof IMetaTileEntityItemPipe
                                                && tItemPipe
                                                        .getCoverBehaviorAtSideNew(j)
                                                        .letsItemsIn(
                                                                j,
                                                                tItemPipe.getCoverIDAtSide(j),
                                                                tItemPipe.getComplexCoverDataAtSide(j),
                                                                -2,
                                                                tItemPipe)) {
                                            scanPipes(
                                                    (IMetaTileEntityItemPipe) tMetaTileEntity,
                                                    aMap,
                                                    aStep,
                                                    aSuckItems,
                                                    aIgnoreCapacity);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            return aMap;
        }
    }
}