use of mcjty.xnet.api.keys.SidedConsumer 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.api.keys.SidedConsumer 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.api.keys.SidedConsumer 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.api.keys.SidedConsumer 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;
}
}
}
use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.
the class GuiController method refreshConnectorEditor.
private void refreshConnectorEditor() {
if (!listsReady()) {
return;
}
if (editingConnector != null && !editingConnector.equals(showingConnector)) {
showingConnector = editingConnector;
connectorEditPanel.removeChildren();
ChannelClientInfo info = fromServer_channels.get(editingChannel);
if (info != null) {
ConnectorClientInfo clientInfo = findClientInfo(info, editingConnector);
if (clientInfo != null) {
EnumFacing side = clientInfo.getPos().getSide();
SidedConsumer sidedConsumer = new SidedConsumer(clientInfo.getConsumerId(), side.getOpposite());
ConnectorClientInfo connectorInfo = info.getConnectors().get(sidedConsumer);
Button remove = new Button(mc, this).setText("x").setTextOffset(0, -1).setTooltips("Remove this connector").setLayoutHint(new PositionalLayout.PositionalHint(151, 1, 9, 10)).addButtonEvent(parent -> removeConnector(editingConnector));
ConnectorEditorPanel editor = new ConnectorEditorPanel(connectorEditPanel, mc, this, editingChannel, editingConnector);
connectorInfo.getConnectorSettings().createGui(editor);
connectorEditPanel.addChild(remove);
editor.setState(connectorInfo.getConnectorSettings());
} else {
Button create = new Button(mc, this).setText("Create").setLayoutHint(new PositionalLayout.PositionalHint(85, 20, 60, 14)).addButtonEvent(parent -> createConnector(editingConnector));
connectorEditPanel.addChild(create);
}
}
} else if (showingConnector != null && editingConnector == null) {
showingConnector = null;
connectorEditPanel.removeChildren();
}
}
Aggregations