use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.
the class LogicTools method getControllerPosForConnector.
@Nullable
public static BlockPos getControllerPosForConnector(@Nonnull World world, @Nonnull BlockPos connectorPos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
NetworkId networkId = worldBlob.getNetworkAt(connectorPos);
if (networkId == null) {
return null;
}
return worldBlob.getProviderPosition(networkId);
}
use of mcjty.xnet.api.keys.NetworkId 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.NetworkId 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.NetworkId 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.NetworkId in project XNet by McJty.
the class NetworkChecker method hash.
private long hash(WorldBlob worldBlob) {
long h = 0;
for (NetworkId network : networks) {
h = Long.rotateLeft(h, 3);
h ^= worldBlob.getNetworkVersion(network);
}
return h;
}
Aggregations