summaryrefslogtreecommitdiff
path: root/src/main/java/net/cshift/transit/basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/cshift/transit/basic')
-rw-r--r--src/main/java/net/cshift/transit/basic/AbstractAcceptorNode.java51
-rw-r--r--src/main/java/net/cshift/transit/basic/AbstractNode.java45
-rw-r--r--src/main/java/net/cshift/transit/basic/AbstractProviderNode.java47
-rw-r--r--src/main/java/net/cshift/transit/basic/AbstractTwoWayNode.java47
-rw-r--r--src/main/java/net/cshift/transit/basic/system/AbstractSystem.java13
-rw-r--r--src/main/java/net/cshift/transit/basic/system/AbstractSystemNode.java12
6 files changed, 215 insertions, 0 deletions
diff --git a/src/main/java/net/cshift/transit/basic/AbstractAcceptorNode.java b/src/main/java/net/cshift/transit/basic/AbstractAcceptorNode.java
new file mode 100644
index 0000000..e2e6711
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/AbstractAcceptorNode.java
@@ -0,0 +1,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;
+ }
+
+}
diff --git a/src/main/java/net/cshift/transit/basic/AbstractNode.java b/src/main/java/net/cshift/transit/basic/AbstractNode.java
new file mode 100644
index 0000000..a87fba4
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/AbstractNode.java
@@ -0,0 +1,45 @@
+package net.cshift.transit.basic;
+
+import java.util.*;
+
+import net.cshift.transit.network.system.*;
+import net.minecraft.block.entity.*;
+
+public abstract class AbstractNode extends BlockEntity implements INode {
+
+ public AbstractNode(BlockEntityType<?> type) {
+ super(type);
+ }
+
+ HashMap<String, Object> data = new HashMap<String, Object>();
+ ArrayList<Connection> connections = new ArrayList<Connection>(0);
+
+ @Override
+ public abstract boolean hasGroup(String groupID);
+
+ @Override
+ public ISystem getSystem() {
+ return null;
+ }
+
+ @Override
+ public Object getData(String groupID) {
+ return data.get(groupID);
+ }
+
+ @Override
+ public void setData(Object dat, String groupID) {
+ data.put(groupID, dat);
+ }
+
+ @Override
+ public Connection[] getConnections() {
+ return (Connection[]) connections.toArray();
+ }
+
+ @Override
+ public int connectionCount() {
+ return connections.size();
+ }
+
+}
diff --git a/src/main/java/net/cshift/transit/basic/AbstractProviderNode.java b/src/main/java/net/cshift/transit/basic/AbstractProviderNode.java
new file mode 100644
index 0000000..cc81544
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/AbstractProviderNode.java
@@ -0,0 +1,47 @@
+package net.cshift.transit.basic;
+
+import net.cshift.transit.network.system.*;
+import net.cshift.transit.network.system.swap.*;
+import net.minecraft.block.entity.*;
+
+public abstract class AbstractProviderNode extends AbstractNode implements IProviderNode {
+
+ public AbstractProviderNode(BlockEntityType<?> type) {
+ super(type);
+ }
+
+ @Override
+ public boolean linkAcceptor(IAcceptorNode requestor, String group) {
+ if(this.hasGroup(group))
+ {
+ for (Connection c : connections) {
+ if(c.getNode() == requestor)
+ return false;
+ }
+
+ connections.add(new Connection(requestor, (short) 1));
+
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean unlinkAcceptor(IAcceptorNode requestor) {
+ for (Connection c : connections) {
+ if(c.getNode() == requestor)
+ {
+ if(c.isProviding())
+ c.setAccepting(false);
+ else
+ connections.remove(c);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/net/cshift/transit/basic/AbstractTwoWayNode.java b/src/main/java/net/cshift/transit/basic/AbstractTwoWayNode.java
new file mode 100644
index 0000000..cc06eeb
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/AbstractTwoWayNode.java
@@ -0,0 +1,47 @@
+package net.cshift.transit.basic;
+
+import net.cshift.transit.network.system.*;
+import net.cshift.transit.network.system.swap.*;
+import net.minecraft.block.entity.*;
+
+public abstract class AbstractTwoWayNode extends AbstractAcceptorNode implements IProviderNode {
+
+ public AbstractTwoWayNode(BlockEntityType<?> type) {
+ super(type);
+ }
+
+ @Override
+ public boolean linkAcceptor(IAcceptorNode requestor, String group) {
+ if(this.hasGroup(group))
+ {
+ for (Connection c : connections) {
+ if(c.getNode() == requestor)
+ return false;
+ }
+
+ connections.add(new Connection(requestor, (short) 1));
+
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean unlinkAcceptor(IAcceptorNode requestor) {
+ for (Connection c : connections) {
+ if(c.getNode() == requestor)
+ {
+ if(c.isProviding())
+ c.setAccepting(false);
+ else
+ connections.remove(c);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
diff --git a/src/main/java/net/cshift/transit/basic/system/AbstractSystem.java b/src/main/java/net/cshift/transit/basic/system/AbstractSystem.java
new file mode 100644
index 0000000..ef6254c
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/system/AbstractSystem.java
@@ -0,0 +1,13 @@
+package net.cshift.transit.basic.system;
+
+import net.cshift.transit.network.system.*;
+
+public abstract class AbstractSystem implements ISystem {
+
+ @Override
+ public INode[] getNodes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/net/cshift/transit/basic/system/AbstractSystemNode.java b/src/main/java/net/cshift/transit/basic/system/AbstractSystemNode.java
new file mode 100644
index 0000000..a246588
--- /dev/null
+++ b/src/main/java/net/cshift/transit/basic/system/AbstractSystemNode.java
@@ -0,0 +1,12 @@
+package net.cshift.transit.basic.system;
+
+import net.cshift.transit.basic.*;
+import net.minecraft.block.entity.*;
+
+public abstract class AbstractSystemNode extends AbstractNode {
+
+ public AbstractSystemNode(BlockEntityType<?> type) {
+ super(type);
+ }
+
+}