public void readFromNBT(final NBTTagCompound nbt) { // The host check may be superfluous for you. It's just there to allow // some special cases, where getNode() returns some node managed by // some other instance (for example when you have multiple internal // nodes in this tile entity). if (node != null && node.host() == this) { // This restores the node's address, which is required for networks // to continue working without interruption across loads. If the // node is a power connector this is also required to restore the // internal energy buffer of the node. node.load(nbt.getCompoundTag("oc:node")); } }
public void onChunkUnload() { // Make sure to remove the node from its network when its environment, // meaning this tile entity, gets unloaded. if (e.getWorldObj().isRemote) return; if (node != null) node.remove(); }
Environment otherHost = other.host(); if (otherHost instanceof OCConduitNetwork && otherHost != network) { node(color).disconnect(other); return; Node other2 = null; if (te instanceof SidedEnvironment) { other2 = ((SidedEnvironment) te).sidedNode(direction.getOpposite()); } else if (te instanceof Environment) { other2 = ((Environment) te).node(); boolean checkThisSide = true; if (otherHost instanceof SidedEnvironment) { checkThisSide = ((SidedEnvironment) otherHost).sidedNode(direction) != null; TileEntity connToTe = world.getTileEntity(connTo); if (connToTe instanceof SidedEnvironment) { stayConnected = ((SidedEnvironment) connToTe).sidedNode(direction.getOpposite()) == node(color); } else if (connToTe instanceof Environment) { stayConnected = ((Environment) connToTe).node() == node(color); node(color).disconnect(other);
private static String prettyNode(Node o) { String at = ""; Environment host = o.host(); if (host instanceof TileEntity) { BlockPos bc = ((TileEntity) host).getPos(); at = " at " + bc.getX() + "/" + bc.getY() + "/" + bc.getZ(); } return host.getClass().getName().replaceFirst("^.*\\.", "") + at; }
Node other = null; if (te instanceof SidedEnvironment) { other = ((SidedEnvironment) te).sidedNode(direction.getOpposite()); } else if (te instanceof Environment) { other = ((Environment) te).node(); } else { if (!node(color).isNeighborOf(other)) { node(color).connect(other);
public void updateEntity() { // On the first update, try to add our node to nearby networks. We do // this in the update logic, not in validate() because we need to access // neighboring tile entities, which isn't possible in validate(). // We could alternatively check node != null && node.network() == null, // but this has somewhat better performance, and makes it clearer. if (e.getWorldObj().isRemote) return; if (!addedToNetwork) { addedToNetwork = true; Network.joinOrCreateNetwork(e); } else { if (node != null) { if (e.getNode() == null) return; Connector c = ((Connector) node); EnergyConverterElnToOtherNode node = (EnergyConverterElnToOtherNode) e.getNode(); double eMax = node.getOtherModEnergyBuffer(Other.getElnToOcConversionRatio()); eMax = Math.min(Math.min(eMax, c.globalBufferSize() - c.globalBuffer()), node.descriptor.oc.outMax); if (c.tryChangeBuffer(eMax)) { node.drawEnergy(eMax, Other.getElnToOcConversionRatio()); } } } }
private void disconnectNode(@Nonnull EnumFacing direction) { World world = getBundle().getBundleworld(); TileEntity te = world.getTileEntity(getBundle().getLocation().offset(direction)); Node other = null; if (te instanceof SidedEnvironment) { other = ((SidedEnvironment) te).sidedNode(direction.getOpposite()); } else if (te instanceof Environment) { other = ((Environment) te).node(); } if (other != null) { disconnectNode(other, getSignalColor(direction)); } }
@Override public boolean canConnectToExternal(@Nonnull EnumFacing direction, boolean ignoreConnectionMode) { TileEntity te = getBundle().getBundleworld().getTileEntity(getBundle().getLocation().offset(direction)); if (te instanceof SidedEnvironment) { if (getBundle().getBundleworld().isRemote) { return ((SidedEnvironment) te).canConnect(direction.getOpposite()); } else { return ((SidedEnvironment) te).sidedNode(direction.getOpposite()) != null; } } else if (te instanceof Environment) { return true; } return false; }
public void invalidate() { // Make sure to remove the node from its network when its environment, // meaning this tile entity, gets unloaded. if (e.getWorldObj().isRemote) return; if (node != null) node.remove(); }
entry = args.checkInteger(3); Node node = node().network().node(address); if (node == null) { throw new IllegalArgumentException("no such component"); throw new IllegalArgumentException("no such component"); Environment env = node.host(); if (!(env instanceof Database)) { throw new IllegalArgumentException("not a database");
@Override public void handleInvalidate(IOCTile tile) { if (((Node) tile.getOCNode()) != null) { ((Node) tile.getOCNode()).remove(); } }
@Override public void handleChunkUnload(IOCTile tile) { if (((Node) tile.getOCNode()) != null) { ((Node) tile.getOCNode()).remove(); } }
@Override public void destroyNetwork() { for (DyeColor dyeColor : DyeColor.values()) { node[dyeColor.ordinal()].remove(); } super.destroyNetwork(); }