use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.
the class TileEntityController method removeConnector.
private void removeConnector(int channel, SidedPos pos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
SidedConsumer toremove = null;
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer key = entry.getKey();
if (key.getSide().getOpposite().equals(pos.getSide())) {
if (key.getConsumerId().equals(consumerId)) {
toremove = key;
break;
}
}
}
if (toremove != null) {
channels[channel].getConnectors().remove(toremove);
networkDirty();
markDirtyQuick();
}
}
use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.
the class ChannelInfo method writeToNBT.
public void writeToNBT(NBTTagCompound tag) {
channelSettings.writeToNBT(tag);
tag.setBoolean("enabled", enabled);
if (channelName != null && !channelName.isEmpty()) {
tag.setString("name", channelName);
}
NBTTagList conlist = new NBTTagList();
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : connectors.entrySet()) {
NBTTagCompound tc = new NBTTagCompound();
ConnectorInfo connectorInfo = entry.getValue();
connectorInfo.writeToNBT(tc);
tc.setInteger("consumerId", entry.getKey().getConsumerId().getId());
tc.setInteger("side", entry.getKey().getSide().ordinal());
tc.setString("type", connectorInfo.getType().getID());
tc.setBoolean("advanced", connectorInfo.isAdvanced());
conlist.appendTag(tc);
}
tag.setTag("connectors", conlist);
}
use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.
the class ChannelInfo method createConnector.
public ConnectorInfo createConnector(SidedConsumer id, boolean advanced) {
ConnectorInfo info = new ConnectorInfo(type, id, advanced);
connectors.put(id, info);
return info;
}
use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.
the class ChannelInfo method readFromNBT.
public void readFromNBT(NBTTagCompound tag) {
channelSettings.readFromNBT(tag);
enabled = tag.getBoolean("enabled");
if (tag.hasKey("name")) {
channelName = tag.getString("name");
} else {
channelName = null;
}
NBTTagList conlist = tag.getTagList("connectors", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < conlist.tagCount(); i++) {
NBTTagCompound tc = conlist.getCompoundTagAt(i);
String id = tc.getString("type");
IChannelType type = XNet.xNetApi.findType(id);
if (type == null) {
XNet.logger.warn("Unsupported type " + id + "!");
continue;
}
if (!getType().equals(type)) {
XNet.logger.warn("Trying to load a connector with non-matching type " + type + "!");
continue;
}
ConsumerId consumerId = new ConsumerId(tc.getInteger("consumerId"));
EnumFacing side = EnumFacing.VALUES[tc.getInteger("side")];
SidedConsumer key = new SidedConsumer(consumerId, side);
boolean advanced = tc.getBoolean("advanced");
ConnectorInfo connectorInfo = new ConnectorInfo(type, key, advanced);
connectorInfo.readFromNBT(tc);
connectors.put(key, connectorInfo);
}
}
use of mcjty.xnet.clientinfo.ConnectorInfo 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];
}
Aggregations