use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method getNetworkChecker.
@Nonnull
public NetworkChecker getNetworkChecker() {
if (networkChecker == null) {
networkChecker = new NetworkChecker();
networkChecker.add(networkId);
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
LogicTools.routers(getWorld(), networkId).forEach(router -> {
networkChecker.add(worldBlob.getNetworksAt(router.getPos()));
// We're only interested in one network. The other router networks are all same topology
NetworkId routerNetwork = worldBlob.getNetworkAt(router.getPos());
if (routerNetwork != null) {
LogicTools.routers(getWorld(), routerNetwork).filter(r -> router != r).forEach(r -> LogicTools.connectors(getWorld(), r.getPos()).forEach(connectorPos -> networkChecker.add(worldBlob.getNetworkAt(connectorPos))));
}
});
// networkChecker.dump();
}
return networkChecker;
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method getConnectors.
@Override
@Nonnull
public Map<SidedConsumer, IConnectorSettings> getConnectors(int channel) {
if (cachedConnectors[channel] == null) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
cachedConnectors[channel] = new HashMap<>();
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer sidedConsumer = entry.getKey();
BlockPos pos = findConsumerPosition(sidedConsumer.getConsumerId());
if (pos != null && worldBlob.getNetworksAt(pos).contains(getNetworkId())) {
cachedConnectors[channel].put(sidedConsumer, entry.getValue().getConnectorSettings());
}
}
}
return cachedConnectors[channel];
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method findChannelInfo.
@Nonnull
private List<ChannelClientInfo> findChannelInfo() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
List<ChannelClientInfo> chanList = new ArrayList<>();
for (ChannelInfo channel : channels) {
if (channel != null) {
ChannelClientInfo clientInfo = new ChannelClientInfo(channel.getChannelName(), channel.getType(), channel.getChannelSettings(), channel.isEnabled());
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channel.getConnectors().entrySet()) {
SidedConsumer sidedConsumer = entry.getKey();
ConnectorInfo info = entry.getValue();
if (info.getConnectorSettings() != null) {
BlockPos consumerPos = findConsumerPosition(worldBlob, sidedConsumer.getConsumerId());
if (consumerPos != null) {
SidedPos pos = new SidedPos(consumerPos.offset(sidedConsumer.getSide()), sidedConsumer.getSide().getOpposite());
boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
ConnectorClientInfo ci = new ConnectorClientInfo(pos, sidedConsumer.getConsumerId(), channel.getType(), info.getConnectorSettings());
clientInfo.getConnectors().put(sidedConsumer, ci);
} else {
// Consumer was possibly removed. We might want to remove the entry from our list here?
// @todo
}
}
}
chanList.add(clientInfo);
} else {
chanList.add(null);
}
}
return chanList;
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method createConnector.
private void createConnector(int channel, SidedPos pos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
BlockPos consumerPos = pos.getPos().offset(pos.getSide());
ConsumerId consumerId = worldBlob.getConsumerAt(consumerPos);
if (consumerId == null) {
throw new RuntimeException("What?");
}
SidedConsumer id = new SidedConsumer(consumerId, pos.getSide().getOpposite());
boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
channels[channel].createConnector(id, advanced);
networkDirty();
markDirtyQuick();
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method updateConnector.
private void updateConnector(int channel, SidedPos pos, Map<String, Argument> args) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer key = entry.getKey();
if (key.getConsumerId().equals(consumerId) && key.getSide().getOpposite().equals(pos.getSide())) {
Map<String, Object> data = new HashMap<>();
for (Map.Entry<String, Argument> e : args.entrySet()) {
data.put(e.getKey(), e.getValue().getValue());
}
channels[channel].getConnectors().get(key).getConnectorSettings().update(data);
networkDirty();
markDirtyQuick();
return;
}
}
}
Aggregations