Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private DummyOC _dummyOC;
- private class DummyOC implements Environment, SidedEnvironment, ManagedPeripheral {
- public DummyOC(TileEntityReactorComputerPort te) {
- this._node = Network.newNode(this, Visibility.Network).withComponent("br_reactor", Visibility.Network).create();
- this._te = te;
- }
- private TileEntityReactorComputerPort _te;
- public void onAttachedToController() {
- if (null != this._node && this._node.network() == null) {
- BigReactors.getLogger().info("CONNECTING TO OC NET");
- API.network.joinOrCreateNetwork(this._te);
- this._te.markDirty();
- }
- }
- public void onDetachedFromController() {
- if (null != this._node) {
- BigReactors.getLogger().info("DISCONNECTING FROM OC NET");
- this._node.remove();
- }
- }
- public void syncDataFrom(NBTTagCompound data, ModTileEntity.SyncReason syncReason) {
- BigReactors.getLogger().info("DUMMY sync from");
- if (null != this.node() && data.hasKey(NODE_TAG)) {
- BigReactors.getLogger().info("DUMMY LOADING OC NODE DATA");
- this.node().load(data.getCompoundTag(NODE_TAG));
- }
- }
- public void syncDataTo(NBTTagCompound data, ModTileEntity.SyncReason syncReason) {
- BigReactors.getLogger().info("DUMMY sync to");
- // let's do this like OC' AbstractManagedEnvironment do ...
- if (this.node() != null) {
- // Force joining a network when saving and we're not in one yet, so that
- // the address is embedded in the saved data that gets sent to the client,
- // so that that address can be used to associate components on server and
- // client (for example keyboard and screen/text buffer).
- BigReactors.getLogger().info("DUMMY SAVING OC NODE DATA");
- if (this.node().address() == null) {
- li.cil.oc.api.Network.joinNewNetwork(this.node());
- final NBTTagCompound nodeTag = new NBTTagCompound();
- this.node().save(nodeTag);
- data.setTag(NODE_TAG, nodeTag);
- this.node().remove();
- } else {
- final NBTTagCompound nodeTag = new NBTTagCompound();
- this.node().save(nodeTag);
- data.setTag(NODE_TAG, nodeTag);
- }
- }
- }
- // Environment
- @Override
- public Node node() {
- return this._node;
- }
- @Override
- public void onConnect(Node node) {
- }
- @Override
- public void onDisconnect(Node node) {
- }
- @Override
- public void onMessage(Message message) {
- }
- // SidedEnvironment
- @Override
- public Node sidedNode(EnumFacing side) {
- return this.node();
- }
- @Override
- public boolean canConnect(EnumFacing side) {
- return true;
- }
- // ManagedPeripheral
- @Override
- public String[] methods() {
- return new String[] {"getConnected", "getEnergyStored"};
- }
- @Override
- public Object[] invoke(String method, Context context, Arguments args) throws Exception {
- switch (method) {
- case "getConnected":
- BigReactors.getLogger().info("DUMMY invoke called: getConnected");
- return new Object[] { true };
- case "getEnergyStored":
- BigReactors.getLogger().info("DUMMY invoke called: getEnergyStored");
- return new Object[] {42};
- }
- return null;
- }
- private final Node _node;
- private static final String NODE_TAG = "ocNode";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement