static @Nullable BlockEntity getBlockEntityForState(Level level, BlockPos pos, BlockState state) {

        if (!state.hasBlockEntity()) return null;

        BlockEntity tile = level.getBlockEntity(pos);
        if (tile == null || tile.isRemoved()) return null;

        // Special handling for recently emptied multipart tiles, as done in BlockMultipart.getTile().
        // This case would be hit if this lookup is a result of a neighbor update caused by a part removal.
        if (tile instanceof TileMultipart tmp && tmp.getPartList().isEmpty()) {
            return null;
        }

        return tile;
    }
Conditionally retrieves a tile if block state allows it and if existing tile is still valid
core/src/main/java/mrtjp/projectred/core/FaceLookup.java