Search in sources :

Example 11 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class RouterBlock 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);
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    Set<NetworkId> networks = worldBlob.getNetworksAt(data.getPos());
    for (NetworkId networkId : networks) {
        probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId());
        if (mode != ProbeMode.EXTENDED) {
            break;
        }
    }
    TileEntity te = world.getTileEntity(data.getPos());
    if (te instanceof TileEntityRouter) {
        TileEntityRouter router = (TileEntityRouter) te;
        if (router.inError()) {
            probeInfo.text(TextStyleClass.ERROR + "Too many channels on router!");
        } else {
            probeInfo.text(TextStyleClass.LABEL + "Channels: " + TextStyleClass.INFO + router.getChannelCount());
        }
    }
    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());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) BlobId(mcjty.xnet.multiblock.BlobId) ColorId(mcjty.xnet.multiblock.ColorId)

Example 12 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class RouterBlock method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    super.onBlockPlacedBy(world, pos, state, placer, stack);
    if (!world.isRemote) {
        XNetBlobData blobData = XNetBlobData.getBlobData(world);
        WorldBlob worldBlob = blobData.getWorldBlob(world);
        NetworkId networkId = worldBlob.newNetwork();
        worldBlob.createNetworkProvider(pos, new ColorId(CableColor.ROUTING.ordinal() + 1), networkId);
        blobData.save(world);
    }
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) ColorId(mcjty.xnet.multiblock.ColorId)

Example 13 with NetworkId

use of mcjty.xnet.api.keys.NetworkId 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();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 14 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class TileEntityRouter method countPublishedChannelsOnNet.

public int countPublishedChannelsOnNet() {
    Set<String> channels = new HashSet<>();
    NetworkId networkId = findRoutingNetwork();
    if (networkId != null) {
        LogicTools.routers(getWorld(), networkId).forEach(router -> router.addPublishedChannels(channels));
    }
    return channels.size();
}
Also used : NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 15 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class TileEntityRouter method findRemoteChannelInfo.

@Nonnull
private List<ControllerChannelClientInfo> findRemoteChannelInfo() {
    List<ControllerChannelClientInfo> list = new ArrayList<>();
    NetworkId networkId = findRoutingNetwork();
    if (networkId != null) {
        LogicTools.consumers(getWorld(), networkId).forEach(consumerPos -> LogicTools.routers(getWorld(), consumerPos).filter(r -> r != this).forEach(router -> list.addAll(router.findLocalChannelInfo(true))));
    }
    return list;
}
Also used : ControllerChannelClientInfo(mcjty.xnet.clientinfo.ControllerChannelClientInfo) GeneralConfiguration(mcjty.xnet.config.GeneralConfiguration) java.util(java.util) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) IConnectorSettings(mcjty.xnet.api.channels.IConnectorSettings) Constants(net.minecraftforge.common.util.Constants) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ChannelInfo(mcjty.xnet.logic.ChannelInfo) NetworkManager(net.minecraft.network.NetworkManager) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPosTools(mcjty.lib.varia.BlockPosTools) NBTTagList(net.minecraft.nbt.NBTTagList) Type(mcjty.typed.Type) ControllerChannelClientInfo(mcjty.xnet.clientinfo.ControllerChannelClientInfo) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LogicTools(mcjty.xnet.logic.LogicTools) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Argument(mcjty.lib.network.Argument) MAX_CHANNELS(mcjty.xnet.logic.ChannelInfo.MAX_CHANNELS) IChannelType(mcjty.xnet.api.channels.IChannelType) NetworkId(mcjty.xnet.api.keys.NetworkId) NetworkId(mcjty.xnet.api.keys.NetworkId) Nonnull(javax.annotation.Nonnull)

Aggregations

NetworkId (mcjty.xnet.api.keys.NetworkId)21 WorldBlob (mcjty.xnet.multiblock.WorldBlob)10 ConsumerId (mcjty.xnet.api.keys.ConsumerId)7 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)6 EnumFacing (net.minecraft.util.EnumFacing)6 ColorId (mcjty.xnet.multiblock.ColorId)5 Nonnull (javax.annotation.Nonnull)4 Nullable (javax.annotation.Nullable)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 java.util (java.util)3 Argument (mcjty.lib.network.Argument)3 BlockPosTools (mcjty.lib.varia.BlockPosTools)3 Type (mcjty.typed.Type)3 IChannelType (mcjty.xnet.api.channels.IChannelType)3 IConnectorSettings (mcjty.xnet.api.channels.IConnectorSettings)3 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)3 GeneralConfiguration (mcjty.xnet.config.GeneralConfiguration)3 ChannelInfo (mcjty.xnet.logic.ChannelInfo)3