summaryrefslogtreecommitdiff
path: root/src/main/java/net/cshift/transit/basic/AbstractAcceptorNode.java
blob: e2e6711ad5fcd7a537f64e17219f08ec2fbee5f4 (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
package net.cshift.transit.basic;

import net.cshift.transit.network.packet.*;
import net.cshift.transit.network.system.*;
import net.cshift.transit.network.system.swap.*;
import net.minecraft.block.entity.*;

public abstract class AbstractAcceptorNode extends AbstractNode implements IAcceptorNode {

    public AbstractAcceptorNode(BlockEntityType<?> type) {
        super(type);
	}
	
	@Override
	public abstract <T> boolean accept(IStaticPacket<T> packet, String group);

    @Override
    public boolean linkProvider(IProviderNode requestor, String group) {
		if(this.hasGroup(group))
		{
			for (Connection c : connections) {
				if(c.getNode() == requestor)
					return false;
			}

			connections.add(new Connection(requestor, (short) 2));

			return true;
		}
		
        return false;
    }

    @Override
    public boolean unlinkProvider(IProviderNode requestor) {
        for (Connection c : connections) {
			if(c.getNode() == requestor)
			{
				if(c.isAccepting())
					c.setProviding(false);
				else
					connections.remove(c);
				
				return true;
			}
		}
		
        return false;
    }
    
}