Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1.  
  2.     private DummyOC _dummyOC;
  3.  
  4.     private class DummyOC implements Environment, SidedEnvironment, ManagedPeripheral {
  5.  
  6.         public DummyOC(TileEntityReactorComputerPort te) {
  7.  
  8.             this._node = Network.newNode(this, Visibility.Network).withComponent("br_reactor", Visibility.Network).create();
  9.             this._te = te;
  10.         }
  11.  
  12.         private TileEntityReactorComputerPort _te;
  13.  
  14.         public void onAttachedToController() {
  15.  
  16.             if (null != this._node && this._node.network() == null) {
  17.  
  18.                 BigReactors.getLogger().info("CONNECTING TO OC NET");
  19.  
  20.                 API.network.joinOrCreateNetwork(this._te);
  21.                 this._te.markDirty();
  22.             }
  23.         }
  24.  
  25.         public void onDetachedFromController() {
  26.  
  27.             if (null != this._node) {
  28.                 BigReactors.getLogger().info("DISCONNECTING FROM OC NET");
  29.                 this._node.remove();
  30.             }
  31.         }
  32.  
  33.         public void syncDataFrom(NBTTagCompound data, ModTileEntity.SyncReason syncReason) {
  34.  
  35.             BigReactors.getLogger().info("DUMMY sync from");
  36.  
  37.  
  38.             if (null != this.node() && data.hasKey(NODE_TAG)) {
  39.  
  40.                 BigReactors.getLogger().info("DUMMY LOADING OC NODE DATA");
  41.  
  42.                 this.node().load(data.getCompoundTag(NODE_TAG));
  43.             }
  44.         }
  45.  
  46.         public void syncDataTo(NBTTagCompound data, ModTileEntity.SyncReason syncReason) {
  47.  
  48.             BigReactors.getLogger().info("DUMMY sync to");
  49.  
  50.             // let's do this like OC' AbstractManagedEnvironment do ...
  51.  
  52.             if (this.node() != null) {
  53.  
  54.                 // Force joining a network when saving and we're not in one yet, so that
  55.                 // the address is embedded in the saved data that gets sent to the client,
  56.                 // so that that address can be used to associate components on server and
  57.                 // client (for example keyboard and screen/text buffer).
  58.  
  59.                 BigReactors.getLogger().info("DUMMY SAVING OC NODE DATA");
  60.  
  61.                 if (this.node().address() == null) {
  62.  
  63.                     li.cil.oc.api.Network.joinNewNetwork(this.node());
  64.  
  65.                     final NBTTagCompound nodeTag = new NBTTagCompound();
  66.  
  67.                     this.node().save(nodeTag);
  68.                     data.setTag(NODE_TAG, nodeTag);
  69.  
  70.                     this.node().remove();
  71.  
  72.                 } else {
  73.  
  74.                     final NBTTagCompound nodeTag = new NBTTagCompound();
  75.  
  76.                     this.node().save(nodeTag);
  77.                     data.setTag(NODE_TAG, nodeTag);
  78.                 }
  79.             }
  80.         }
  81.  
  82.  
  83.         // Environment
  84.  
  85.         @Override
  86.         public Node node() {
  87.             return this._node;
  88.         }
  89.  
  90.         @Override
  91.         public void onConnect(Node node) {
  92.         }
  93.  
  94.         @Override
  95.         public void onDisconnect(Node node) {
  96.         }
  97.  
  98.         @Override
  99.         public void onMessage(Message message) {
  100.         }
  101.  
  102.         // SidedEnvironment
  103.  
  104.         @Override
  105.         public Node sidedNode(EnumFacing side) {
  106.             return this.node();
  107.         }
  108.  
  109.         @Override
  110.         public boolean canConnect(EnumFacing side) {
  111.             return true;
  112.         }
  113.  
  114.         // ManagedPeripheral
  115.  
  116.         @Override
  117.         public String[] methods() {
  118.             return new String[] {"getConnected", "getEnergyStored"};
  119.         }
  120.  
  121.         @Override
  122.         public Object[] invoke(String method, Context context, Arguments args) throws Exception {
  123.  
  124.             switch (method) {
  125.                 case "getConnected":
  126.                     BigReactors.getLogger().info("DUMMY invoke called: getConnected");
  127.                     return new Object[] { true };
  128.  
  129.                 case "getEnergyStored":
  130.                     BigReactors.getLogger().info("DUMMY invoke called: getEnergyStored");
  131.                     return new Object[] {42};
  132.             }
  133.  
  134.             return null;
  135.         }
  136.  
  137.         private final Node _node;
  138.         private static final String NODE_TAG = "ocNode";
  139.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement