use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ChunkBlob method dump.
public void dump() {
System.out.println("################# Chunk (" + chunkPos.x + "," + chunkPos.z + ") #################");
System.out.println("Network providers:");
for (Map.Entry<IntPos, NetworkId> entry : networkProviders.entrySet()) {
System.out.println(" " + toString(entry.getKey()) + ", network = " + entry.getValue().getId());
}
System.out.println("Network consumers:");
for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
System.out.println(" " + toString(entry.getKey()) + ", consumer = " + entry.getValue().getId());
}
System.out.println("Network mappings:");
for (Map.Entry<BlobId, Set<NetworkId>> entry : networkMappings.entrySet()) {
String s = "";
for (NetworkId networkId : entry.getValue()) {
s += networkId.getId() + " ";
}
System.out.println(" Blob(" + entry.getKey().getId() + "): networks = " + s);
}
System.out.println("Blob colors:");
for (Map.Entry<BlobId, ColorId> entry : blobColors.entrySet()) {
System.out.println(" Blob(" + entry.getKey().getId() + "): color = " + entry.getValue().getId());
}
System.out.println("Allocations:");
for (Map.Entry<IntPos, BlobId> entry : blobAllocations.entrySet()) {
System.out.println(" " + toString(entry.getKey()) + ", Blob(" + entry.getValue().getId() + ")");
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ChunkBlob method getConsumersForNetwork.
@Nonnull
public Set<IntPos> getConsumersForNetwork(NetworkId network) {
if (cachedConsumers == null) {
cachedConsumers = new HashMap<>();
for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
IntPos pos = entry.getKey();
BlobId blobId = blobAllocations.get(pos);
Set<NetworkId> networkIds = networkMappings.get(blobId);
if (networkIds != null) {
for (NetworkId net : networkIds) {
if (!cachedConsumers.containsKey(net)) {
cachedConsumers.put(net, new HashSet<>());
}
cachedConsumers.get(net).add(pos);
}
}
}
}
if (cachedConsumers.containsKey(network)) {
return cachedConsumers.get(network);
} else {
return Collections.emptySet();
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ChunkBlob method readFromNBT.
public void readFromNBT(NBTTagCompound compound) {
networkMappings.clear();
blobAllocations.clear();
networkProviders.clear();
blobColors.clear();
cachedBorderPositions.clear();
cachedNetworks = null;
cachedConsumers = null;
cachedProviders = null;
lastBlobId = compound.getInteger("lastBlob");
// Keep track of blobs we found
Set<BlobId> foundBlobs = new HashSet<>();
if (compound.hasKey("allocations")) {
int[] allocations = compound.getIntArray("allocations");
int idx = 0;
while (idx < allocations.length - 1) {
IntPos pos = new IntPos(allocations[idx]);
BlobId blob = new BlobId(allocations[idx + 1]);
blobAllocations.put(pos, blob);
foundBlobs.add(blob);
if (pos.isBorder()) {
cachedBorderPositions.add(pos);
}
idx += 2;
}
}
if (compound.hasKey("mappings")) {
int[] mappings = compound.getIntArray("mappings");
int idx = 0;
while (idx < mappings.length - 1) {
int key = mappings[idx];
BlobId blob = new BlobId(key);
Set<NetworkId> ids = new HashSet<>();
idx++;
while (idx < mappings.length && mappings[idx] != -1) {
ids.add(new NetworkId(mappings[idx]));
idx++;
}
if (foundBlobs.contains(blob)) {
// Only add mappings if we still have allocations for the blob
networkMappings.put(blob, ids);
}
idx++;
}
}
if (compound.hasKey("providers")) {
int[] providers = compound.getIntArray("providers");
int idx = 0;
while (idx < providers.length - 1) {
networkProviders.put(new IntPos(providers[idx]), new NetworkId(providers[idx + 1]));
idx += 2;
}
}
if (compound.hasKey("consumers")) {
int[] consumers = compound.getIntArray("consumers");
int idx = 0;
while (idx < consumers.length - 1) {
IntPos intPos = new IntPos(consumers[idx]);
ConsumerId consumerId = new ConsumerId(consumers[idx + 1]);
networkConsumers.put(intPos, consumerId);
consumerPositions.put(consumerId, intPos);
idx += 2;
}
}
if (compound.hasKey("colors")) {
int[] colors = compound.getIntArray("colors");
int idx = 0;
while (idx < colors.length - 1) {
BlobId blob = new BlobId(colors[idx]);
ColorId color = new ColorId(colors[idx + 1]);
if (foundBlobs.contains(blob)) {
// Only add colors if we still have allocations for the blob
blobColors.put(blob, color);
}
idx += 2;
}
}
}
use of mcjty.xnet.api.keys.ConsumerId 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.ConsumerId 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