use of mcjty.xnet.api.keys.NetworkId 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.NetworkId in project XNet by McJty.
the class WorldBlob method recalculateNetwork.
private void recalculateNetwork(@Nonnull Set<ChunkBlob> todo, @Nullable Set<ChunkBlob> recalculated) {
while (!todo.isEmpty()) {
ChunkBlob blob = todo.iterator().next();
todo.remove(blob);
if (recalculated != null) {
if (!recalculated.contains(blob)) {
blob.fixNetworkAllocations();
recalculated.add(blob);
}
}
blob.clearNetworkCache();
removeCachedNetworksForBlob(blob);
Set<IntPos> borderPositions = blob.getBorderPositions();
ChunkPos chunkPos = blob.getChunkPos();
for (IntPos pos : borderPositions) {
Set<NetworkId> networks = blob.getOrCreateNetworksForPosition(pos);
ColorId color = blob.getColorIdForPosition(pos);
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
if (pos.isBorder(facing)) {
Vec3i vec = facing.getDirectionVec();
ChunkBlob adjacent = chunkBlobMap.get(ChunkPos.asLong(chunkPos.x + vec.getX(), chunkPos.z + vec.getZ()));
if (adjacent != null) {
IntPos connectedPos = pos.otherSide(facing);
if (adjacent.getBorderPositions().contains(connectedPos) && adjacent.getColorIdForPosition(connectedPos).equals(color)) {
// We have a connection!
Set<NetworkId> adjacentNetworks = adjacent.getOrCreateNetworksForPosition(connectedPos);
if (networks.addAll(adjacentNetworks)) {
// We changed this blob so need to push back on todo
todo.add(blob);
}
if (adjacentNetworks.addAll(networks)) {
todo.add(adjacent);
}
}
}
}
}
}
}
}
use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.
the class WorldBlobTest method main.
public static void main(String[] args) {
ColorId color1 = new ColorId(111);
ColorId color2 = new ColorId(222);
ColorId color3 = new ColorId(333);
WorldBlob world = new WorldBlob(0);
BlockPos p1 = new BlockPos(10, 60, 10);
world.createNetworkProvider(p1, color1, new NetworkId(1000));
createCableLine(world, p1.east(), EnumFacing.EAST, 20, color1);
BlockPos p2 = new BlockPos(50, 61, 10);
world.createNetworkProvider(p2, color2, new NetworkId(2000));
createCableLine(world, p2.west(), EnumFacing.WEST, 50, color2);
BlockPos p3 = new BlockPos(50, 30, 1000);
createCableLine(world, p3, EnumFacing.UP, 5, color3);
createCableLine(world, p3.east().east(), EnumFacing.UP, 5, color3);
world.createNetworkProvider(p3.north(), color3, new NetworkId(3000));
world.createCableSegment(p3.east(), color3);
world.dump();
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
world.removeCableSegment(new BlockPos(30, 61, 10));
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
world.dump();
NBTTagCompound compound = new NBTTagCompound();
world.writeToNBT(compound);
world = new WorldBlob(0);
world.readFromNBT(compound);
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
System.out.println("------------------------------------------------------------");
world.dump();
}
use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.
the class TileEntityRouter method addRoutedConnectors.
public void addRoutedConnectors(Map<SidedConsumer, IConnectorSettings> connectors, @Nonnull BlockPos controllerPos, int channel, IChannelType type) {
if (inError()) {
// We are in error. Don't do anything
return;
}
LocalChannelId id = new LocalChannelId(controllerPos, channel);
String publishedName = publishedChannels.get(id);
if (publishedName != null && !publishedName.isEmpty()) {
NetworkId networkId = findRoutingNetwork();
if (networkId != null) {
LogicTools.consumers(getWorld(), networkId).forEach(consumerPos -> LogicTools.routers(getWorld(), consumerPos).forEach(router -> router.addConnectorsFromConnectedNetworks(connectors, publishedName, type)));
} else {
// If there is no routing network that means we have a local network only
addConnectorsFromConnectedNetworks(connectors, publishedName, type);
}
}
}
use of mcjty.xnet.api.keys.NetworkId 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());
}
}
Aggregations