Search in sources :

Example 21 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class TileEntityController method getNetworkChecker.

@Nonnull
public NetworkChecker getNetworkChecker() {
    if (networkChecker == null) {
        networkChecker = new NetworkChecker();
        networkChecker.add(networkId);
        WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
        LogicTools.routers(getWorld(), networkId).forEach(router -> {
            networkChecker.add(worldBlob.getNetworksAt(router.getPos()));
            // We're only interested in one network. The other router networks are all same topology
            NetworkId routerNetwork = worldBlob.getNetworkAt(router.getPos());
            if (routerNetwork != null) {
                LogicTools.routers(getWorld(), routerNetwork).filter(r -> router != r).forEach(r -> LogicTools.connectors(getWorld(), r.getPos()).forEach(connectorPos -> networkChecker.add(worldBlob.getNetworkAt(connectorPos))));
            }
        });
    // networkChecker.dump();
    }
    return networkChecker;
}
Also used : GeneralConfiguration(mcjty.xnet.config.GeneralConfiguration) java.util(java.util) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) IConnectorSettings(mcjty.xnet.api.channels.IConnectorSettings) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo) 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) ItemStack(net.minecraft.item.ItemStack) Type(mcjty.typed.Type) NetworkChecker(mcjty.xnet.multiblock.NetworkChecker) ITickable(net.minecraft.util.ITickable) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConsumerId(mcjty.xnet.api.keys.ConsumerId) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) IControllerContext(mcjty.xnet.api.channels.IControllerContext) World(net.minecraft.world.World) ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) GuiController(mcjty.xnet.blocks.controller.gui.GuiController) LogicTools(mcjty.xnet.logic.LogicTools) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) XNet(mcjty.xnet.XNet) IBlockState(net.minecraft.block.state.IBlockState) Argument(mcjty.lib.network.Argument) NetCableSetup(mcjty.xnet.blocks.cables.NetCableSetup) MAX_CHANNELS(mcjty.xnet.logic.ChannelInfo.MAX_CHANNELS) IChannelType(mcjty.xnet.api.channels.IChannelType) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) TileEntity(net.minecraft.tileentity.TileEntity) SidedPos(mcjty.xnet.api.keys.SidedPos) NetworkId(mcjty.xnet.api.keys.NetworkId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) NetworkChecker(mcjty.xnet.multiblock.NetworkChecker) Nonnull(javax.annotation.Nonnull)

Example 22 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class TileEntityController method getConnectors.

@Override
@Nonnull
public Map<SidedConsumer, IConnectorSettings> getConnectors(int channel) {
    if (cachedConnectors[channel] == null) {
        WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
        cachedConnectors[channel] = new HashMap<>();
        for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
            SidedConsumer sidedConsumer = entry.getKey();
            BlockPos pos = findConsumerPosition(sidedConsumer.getConsumerId());
            if (pos != null && worldBlob.getNetworksAt(pos).contains(getNetworkId())) {
                cachedConnectors[channel].put(sidedConsumer, entry.getValue().getConnectorSettings());
            }
        }
    }
    return cachedConnectors[channel];
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Example 23 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class TileEntityController method findChannelInfo.

@Nonnull
private List<ChannelClientInfo> findChannelInfo() {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    List<ChannelClientInfo> chanList = new ArrayList<>();
    for (ChannelInfo channel : channels) {
        if (channel != null) {
            ChannelClientInfo clientInfo = new ChannelClientInfo(channel.getChannelName(), channel.getType(), channel.getChannelSettings(), channel.isEnabled());
            for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channel.getConnectors().entrySet()) {
                SidedConsumer sidedConsumer = entry.getKey();
                ConnectorInfo info = entry.getValue();
                if (info.getConnectorSettings() != null) {
                    BlockPos consumerPos = findConsumerPosition(worldBlob, sidedConsumer.getConsumerId());
                    if (consumerPos != null) {
                        SidedPos pos = new SidedPos(consumerPos.offset(sidedConsumer.getSide()), sidedConsumer.getSide().getOpposite());
                        boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
                        ConnectorClientInfo ci = new ConnectorClientInfo(pos, sidedConsumer.getConsumerId(), channel.getType(), info.getConnectorSettings());
                        clientInfo.getConnectors().put(sidedConsumer, ci);
                    } else {
                    // Consumer was possibly removed. We might want to remove the entry from our list here?
                    // @todo
                    }
                }
            }
            chanList.add(clientInfo);
        } else {
            chanList.add(null);
        }
    }
    return chanList;
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ChannelInfo(mcjty.xnet.logic.ChannelInfo) ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo) Nonnull(javax.annotation.Nonnull)

Example 24 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class TileEntityController method createConnector.

private void createConnector(int channel, SidedPos pos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    BlockPos consumerPos = pos.getPos().offset(pos.getSide());
    ConsumerId consumerId = worldBlob.getConsumerAt(consumerPos);
    if (consumerId == null) {
        throw new RuntimeException("What?");
    }
    SidedConsumer id = new SidedConsumer(consumerId, pos.getSide().getOpposite());
    boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
    channels[channel].createConnector(id, advanced);
    networkDirty();
    markDirtyQuick();
}
Also used : SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

Example 25 with WorldBlob

use of mcjty.xnet.multiblock.WorldBlob in project XNet by McJty.

the class TileEntityController method updateConnector.

private void updateConnector(int channel, SidedPos pos, Map<String, Argument> args) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
        SidedConsumer key = entry.getKey();
        if (key.getConsumerId().equals(consumerId) && key.getSide().getOpposite().equals(pos.getSide())) {
            Map<String, Object> data = new HashMap<>();
            for (Map.Entry<String, Argument> e : args.entrySet()) {
                data.put(e.getKey(), e.getValue().getValue());
            }
            channels[channel].getConnectors().get(key).getConnectorSettings().update(data);
            networkDirty();
            markDirtyQuick();
            return;
        }
    }
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) Argument(mcjty.lib.network.Argument) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Aggregations

WorldBlob (mcjty.xnet.multiblock.WorldBlob)25 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)11 ConsumerId (mcjty.xnet.api.keys.ConsumerId)8 NetworkId (mcjty.xnet.api.keys.NetworkId)8 ColorId (mcjty.xnet.multiblock.ColorId)7 TileEntity (net.minecraft.tileentity.TileEntity)7 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)6 EnumFacing (net.minecraft.util.EnumFacing)6 BlockPos (net.minecraft.util.math.BlockPos)6 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)5 Nonnull (javax.annotation.Nonnull)4 SidedPos (mcjty.xnet.api.keys.SidedPos)4 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)4 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)3 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)3 ConnectedBlockClientInfo (mcjty.xnet.clientinfo.ConnectedBlockClientInfo)3 BlobId (mcjty.xnet.multiblock.BlobId)3 IBlockState (net.minecraft.block.state.IBlockState)3 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)3 Nullable (javax.annotation.Nullable)2