use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class ControllerBlock method findNeighbourConnector.
// Check neighbour blocks for a connector and inherit the color from that
private void findNeighbourConnector(World world, BlockPos pos) {
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
ColorId oldColor = worldBlob.getColorAt(pos);
ColorId newColor = null;
for (EnumFacing facing : EnumFacing.VALUES) {
if (world.getBlockState(pos.offset(facing)).getBlock() instanceof ConnectorBlock) {
ColorId color = worldBlob.getColorAt(pos.offset(facing));
if (color != null) {
if (color == oldColor) {
// Nothing to do
return;
}
newColor = color;
}
}
}
if (newColor != null) {
if (worldBlob.getBlobAt(pos) != null) {
worldBlob.removeCableSegment(pos);
}
NetworkId networkId = worldBlob.newNetwork();
worldBlob.createNetworkProvider(pos, newColor, networkId);
blobData.save(world);
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityController) {
((TileEntityController) te).setNetworkId(networkId);
}
}
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class ControllerBlock method addProbeInfo.
@Override
@Optional.Method(modid = "theoneprobe")
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
TileEntity te = world.getTileEntity(data.getPos());
WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
if (te instanceof TileEntityController) {
TileEntityController controller = (TileEntityController) te;
NetworkId networkId = controller.getNetworkId();
if (networkId != null) {
if (mode == ProbeMode.DEBUG) {
probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId() + ", V: " + worldBlob.getNetworkVersion(networkId));
} else {
probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId());
}
}
if (mode == ProbeMode.DEBUG) {
String s = "";
for (NetworkId id : controller.getNetworkChecker().getAffectedNetworks()) {
s += id.getId() + " ";
if (s.length() > 15) {
probeInfo.text(TextStyleClass.LABEL + "InfNet: " + TextStyleClass.INFO + s);
s = "";
}
}
if (!s.isEmpty()) {
probeInfo.text(TextStyleClass.LABEL + "InfNet: " + TextStyleClass.INFO + s);
}
}
if (controller.inError()) {
probeInfo.text(TextStyleClass.ERROR + "Too many controllers on network!");
}
}
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());
}
}
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method removeConnector.
private void removeConnector(int channel, SidedPos pos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
SidedConsumer toremove = null;
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer key = entry.getKey();
if (key.getSide().getOpposite().equals(pos.getSide())) {
if (key.getConsumerId().equals(consumerId)) {
toremove = key;
break;
}
}
}
if (toremove != null) {
channels[channel].getConnectors().remove(toremove);
networkDirty();
markDirtyQuick();
}
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method findConnectedBlocks.
@Nonnull
private List<ConnectedBlockClientInfo> findConnectedBlocks() {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
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());
IBlockState state = getWorld().getBlockState(pos);
ItemStack item = state.getBlock().getItem(getWorld(), pos, state);
ConnectedBlockClientInfo info = new ConnectedBlockClientInfo(sidedPos, item, name);
set.add(info);
}
}
}
List<ConnectedBlockClientInfo> list = new ArrayList<>(set);
list.sort(Comparator.comparing(ConnectedBlockClientInfo::getBlockUnlocName).thenComparing(ConnectedBlockClientInfo::getPos));
return list;
}
use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.
the class TileEntityController method update.
@Override
public void update() {
if (!getWorld().isRemote) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
if (worldBlob.getNetworksAt(getPos()).size() > 1) {
// Error situation!
markDirtyClient();
return;
}
checkNetwork(worldBlob);
if (!checkAndConsumeRF(GeneralConfiguration.controllerRFT)) {
return;
}
boolean dirty = false;
int newcolors = 0;
for (int i = 0; i < MAX_CHANNELS; i++) {
if (channels[i] != null && channels[i].isEnabled()) {
if (checkAndConsumeRF(GeneralConfiguration.controllerChannelRFT)) {
channels[i].getChannelSettings().tick(i, this);
}
newcolors |= channels[i].getChannelSettings().getColors();
dirty = true;
}
}
if (newcolors != colors) {
dirty = true;
colors = newcolors;
}
if (dirty) {
markDirtyQuick();
}
}
}
Aggregations