use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ChunkBlob method writeToNBT.
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setInteger("lastBlob", lastBlobId);
List<Integer> m = new ArrayList<>();
for (Map.Entry<BlobId, Set<NetworkId>> entry : networkMappings.entrySet()) {
m.add(entry.getKey().getId());
for (NetworkId v : entry.getValue()) {
m.add(v.getId());
}
m.add(-1);
}
NBTTagIntArray mappings = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
compound.setTag("mappings", mappings);
m.clear();
for (Map.Entry<IntPos, BlobId> entry : blobAllocations.entrySet()) {
m.add(entry.getKey().getPos());
m.add(entry.getValue().getId());
}
NBTTagIntArray allocations = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
compound.setTag("allocations", allocations);
m.clear();
for (Map.Entry<IntPos, NetworkId> entry : networkProviders.entrySet()) {
m.add(entry.getKey().getPos());
m.add(entry.getValue().getId());
}
NBTTagIntArray providers = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
compound.setTag("providers", providers);
m.clear();
for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
m.add(entry.getKey().getPos());
m.add(entry.getValue().getId());
}
NBTTagIntArray consumers = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
compound.setTag("consumers", consumers);
m.clear();
for (Map.Entry<BlobId, ColorId> entry : blobColors.entrySet()) {
m.add(entry.getKey().getId());
m.add(entry.getValue().getId());
}
NBTTagIntArray colors = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
compound.setTag("colors", colors);
return compound;
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class WorldBlob method removeCableSegment.
public void removeCableSegment(BlockPos pos) {
ConsumerId consumerId = getConsumerAt(pos);
if (consumerId != null) {
consumerPositions.remove(consumerId);
}
NetworkId providerId = getNetworkAt(pos);
if (providerId != null) {
providerPositions.remove(providerId);
}
ChunkBlob blob = getOrCreateBlob(pos);
blob.removeCableSegment(pos);
recalculateNetwork();
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class GenericCableBlock method addProbeInfo.
@Override
@Optional.Method(modid = "theoneprobe")
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
if (mode == ProbeMode.DEBUG) {
BlobId blobId = worldBlob.getBlobAt(data.getPos());
if (blobId != null) {
probeInfo.text(TextStyleClass.LABEL + "Blob: " + TextStyleClass.INFO + blobId.getId());
}
ColorId colorId = worldBlob.getColorAt(data.getPos());
if (colorId != null) {
probeInfo.text(TextStyleClass.LABEL + "Color: " + TextStyleClass.INFO + colorId.getId());
}
}
Set<NetworkId> networks = worldBlob.getNetworksAt(data.getPos());
for (NetworkId network : networks) {
if (mode == ProbeMode.DEBUG) {
probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + network.getId() + ", V: " + worldBlob.getNetworkVersion(network));
} else {
probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + network.getId());
}
}
ConsumerId consumerId = worldBlob.getConsumerAt(data.getPos());
if (consumerId != null) {
probeInfo.text(TextStyleClass.LABEL + "Consumer: " + TextStyleClass.INFO + consumerId.getId());
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ConnectorBlock method createCableSegment.
@Override
public void createCableSegment(World world, BlockPos pos, ItemStack stack) {
ConsumerId consumer;
if (!stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().hasKey("consumerId")) {
consumer = new ConsumerId(stack.getTagCompound().getInteger("consumerId"));
} else {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
consumer = worldBlob.newConsumer();
}
createCableSegment(world, pos, consumer);
}
use of mcjty.xnet.api.keys.ConsumerId 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);
}
}
Aggregations