Search in sources :

Example 16 with WorldBlob

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;
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 17 with WorldBlob

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

Example 18 with WorldBlob

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);
}
Also used : WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) Nullable(javax.annotation.Nullable)

Example 19 with WorldBlob

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);
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 20 with WorldBlob

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;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

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