use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class ConnectorTileEntity method possiblyMarkNetworkDirty.
// Optimization to only increase the network if there is an actual block change
public void possiblyMarkNetworkDirty(@Nonnull BlockPos neighbor) {
for (EnumFacing facing : EnumFacing.VALUES) {
if (getPos().offset(facing).equals(neighbor)) {
Block newblock = getWorld().getBlockState(neighbor).getBlock();
if (newblock != cachedNeighbours[facing.ordinal()]) {
cachedNeighbours[facing.ordinal()] = newblock;
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
worldBlob.incNetworkVersion(worldBlob.getNetworkAt(getPos()));
}
return;
}
}
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityRouter method updatePublishName.
private void updatePublishName(@Nonnull BlockPos controllerPos, int channel, String name) {
LocalChannelId id = new LocalChannelId(controllerPos, channel);
if (name == null || name.isEmpty()) {
publishedChannels.remove(id);
} else {
publishedChannels.put(id, name);
}
int number = countPublishedChannelsOnNet();
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
NetworkId networkId = findRoutingNetwork();
if (networkId != null) {
if (number != channelCount) {
LogicTools.routers(getWorld(), networkId).forEach(router -> router.setChannelCount(number));
}
// Force a recalc of affected networks
worldBlob.incNetworkVersion(networkId);
}
for (NetworkId net : worldBlob.getNetworksAt(pos)) {
worldBlob.incNetworkVersion(net);
}
for (EnumFacing facing : EnumFacing.VALUES) {
for (NetworkId net : worldBlob.getNetworksAt(pos.offset(facing))) {
worldBlob.incNetworkVersion(net);
}
}
markDirtyQuick();
}
use of mcjty.xnet.multiblock.WorldBlob 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.multiblock.WorldBlob in project XNet by McJty.
the class ControllerBlock method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (!world.isRemote) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
worldBlob.removeCableSegment(pos);
blobData.save(world);
}
super.breakBlock(world, pos, state);
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method getConnectedBlockPositions.
@Override
public List<SidedPos> getConnectedBlockPositions() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
List<SidedPos> result = new ArrayList<>();
Set<ConnectedBlockClientInfo> set = new HashSet<>();
for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
String name = "";
TileEntity te = getWorld().getTileEntity(consumerPos);
if (te instanceof ConnectorTileEntity) {
// Should always be the case. @todo error?
name = ((ConnectorTileEntity) te).getConnectorName();
} else {
XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
BlockPos pos = consumerPos.offset(facing);
SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
result.add(sidedPos);
}
}
}
return result;
}
Aggregations